From patchwork Sat Aug 24 19:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13776498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E121BC52D6F for ; Sat, 24 Aug 2024 19:10:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0E20800F1; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96CA3800EE; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 797F8800F1; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5111E800F0 for ; Sat, 24 Aug 2024 15:10:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E689DA802D for ; Sat, 24 Aug 2024 19:10:38 +0000 (UTC) X-FDA: 82488080556.26.21DDD3B Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf29.hostedemail.com (Postfix) with ESMTP id 2EE3212000A for ; Sat, 24 Aug 2024 19:10:35 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="il4cNM1/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724526525; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dHJr4su3KzsflXo6gchJ2B6JfeJstKzSoEoijiSdexY=; b=jDtCvlJpFLrix6AdZIIi81Yo4avix4J7t5mAdWEYseMeBthxqBlPAjIUcV32FGUa5sN7I1 k3zCbd+8wnL5iQkxQ1tz49pirjtwKLduI/J/nRJlUjigcNmjO5qxJI3d3u0PVMyWb++ePz lZYpoAWY4HKCQYaH9L2rXFtZFJPZidg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="il4cNM1/"; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724526525; a=rsa-sha256; cv=none; b=nrhBVY/5Va36B0hTdnoRXCVeFrHJpZMWn9nh300iAOfKf6IuuyzYJirSh6VHIUnhernKRA HB26XGHVdZjnnaTrroam1NFk/KytcAyYl7tZsRgBeL7mqSte+gJ25EMDCnP4MKjsQgwOQ+ rt/+b4PE5CInet/557lnLKKTOyIAodE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724526634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dHJr4su3KzsflXo6gchJ2B6JfeJstKzSoEoijiSdexY=; b=il4cNM1/7oj7XYsuHh1W1JNzs4Oq8+fDTy6JvD4Z511p+2xPkkP9wOvvzwe4YnQoziTFYw r0FkAsv8qjNLoGwPvEttI9Y6Q+RRSVD1WBAfURE9dCu6369wU2dC//Sp+tP23BA3CWrQfj Uxn9vImAHZ/0ZmIV1TedThnII+RIVw8= From: Kent Overstreet To: david@fromorbit.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Kent Overstreet , Alexander Viro , linux-fsdevel@vger.krenel.org, Tejun Heo Subject: [PATCH 07/10] percpu: per_cpu_sum() Date: Sat, 24 Aug 2024 15:10:14 -0400 Message-ID: <20240824191020.3170516-8-kent.overstreet@linux.dev> In-Reply-To: <20240824191020.3170516-1-kent.overstreet@linux.dev> References: <20240824191020.3170516-1-kent.overstreet@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2EE3212000A X-Stat-Signature: mn68m4yqwocx1r49bqscdxeh4qytu8n7 X-Rspam-User: X-HE-Tag: 1724526635-483382 X-HE-Meta: U2FsdGVkX1+Mjt3XOWBGBoqyKTNvwNmtRCIy9mC0ojooEgtaLhLiHwY3k40e/cMuWPIKBQ2Vk4YSmEljRHteUIbHjnFNsmLBx0f8quxZ/dAPKIvHZwpeWE4UShtdAE20iquDPh26mvRpBOWlMir5G/vzuDR12uVBFdoFe+gqhym2HwS17BpMWtlIS3Y0jakSqtMnKiDqnfExKmbLOltr5yp4HZVObplqU/F1BKI+2fC2trz/W447iXGC/pic4fC39yadsKvBp736og4jAl+y0HHdLzI17bLhwTle2CS4sICoLu4Nif2Y/UkakwPxaHeSXESB5m1Z+OAGVT/pp58Lt7rV3P5ipZZScBHF0EfprxxbCiOOsEEXCFs5JYZxaTg9AikUrH2ZecSQd89/u963IieESYMXaI8XSkcLgE52UM3rJe6Knh7T3GWEsj2Ejai7aMqfNMutVM6TKjXvgWCfzvn8zpP0vy7o9Yj6ID9OmnFaO5Z9MFRVyaPhJ78CnThByX8m2SJTrcoQGXdMxQPXeUIEvDdDAH6HBQB+BeNegjr9KNCBU30fk1W9QF6RxhUGXw2vj4UhRc8Dh0dm9ntJYeyhWdaRVGpK5sPnyCcvlMYHgxv5PdL+mpzlOQ+atimiRNxDltDJqJKfuuwK3rA1/AtZgCBmkNCbHVBJXrbeH8F7AQ8JBG5ljfrjkRlZOG9ZlFNJtGjTAhKIhXEXtVNnAgMb2SvSEbOFiglMYV102J0OitMG9iHNwqsSn2BjO6/3O77QBChLCjIOm+maWJ3eXIRCwbcTJ+54C5BKO8dWWHuKalT7PwacGDvdXVZ0ajfKwTL7SIm0wQbiJiOfUXF/CT/7qhCNnvRc6SP4XbUdli/O2NuNn4OMd6vLAP17RQzL26husR2N8bG9DD4v9+Fn1xaA1rImaIhWevFsgHVxjBFTlSYJ8ZCgNeMEIvNjx4vyEXCpPW1/duf0xhwKUTx 6pzJIrXh Kq0GszI3uhD+/NkylwrmUPD6iD9LbfOZeaJQMtsIlOMn7SgMLn6yqicL2WVBVe335GAhyHnEF1h+5fb/c9GzwP60ssF++uKSWnPqy/ZV7vAdOCgSGTVxVl7bC/Jx2EYYJcC1N0bY+1sLf9xoT9MCBjJM2zwAa+CmzLcxo3jp1sfPW/SY+VDRFz2bwSmhzXn6XY1hTur8/pJpS22JJpsZIwqgTMxU+5bCyGMIza6vxQF4OqQgeR33FEtLs+/SLmKhyaxU3zS+q+d+K1UQb6VHH1c3+tYZDy/pUor/2w8yYTukoHoT7LYbq5QoWXkwdr7jYP/UGJSMV8kMUW6mdI5kk4lORjw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a little helper to replace open coded versions. Signed-off-by: Kent Overstreet Cc: Alexander Viro Cc: linux-fsdevel@vger.krenel.org Cc: Tejun Heo Signed-off-by: Kent Overstreet --- fs/bcachefs/util.h | 10 ---------- fs/dcache.c | 16 +++------------- include/linux/percpu.h | 10 ++++++++++ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index fb02c1c36004..e90c2f546007 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -584,16 +584,6 @@ do { \ } \ } while (0) -#define per_cpu_sum(_p) \ -({ \ - typeof(*_p) _ret = 0; \ - \ - int cpu; \ - for_each_possible_cpu(cpu) \ - _ret += *per_cpu_ptr(_p, cpu); \ - _ret; \ -}) - static inline u64 percpu_u64_get(u64 __percpu *src) { return per_cpu_sum(src); diff --git a/fs/dcache.c b/fs/dcache.c index 3d8daaecb6d1..64108cbd52f6 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -151,29 +151,19 @@ static struct dentry_stat_t dentry_stat = { */ static long get_nr_dentry(void) { - int i; - long sum = 0; - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry, i); + long sum = per_cpu_sum(&nr_dentry); return sum < 0 ? 0 : sum; } static long get_nr_dentry_unused(void) { - int i; - long sum = 0; - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry_unused, i); + long sum = per_cpu_sum(&nr_dentry_unused); return sum < 0 ? 0 : sum; } static long get_nr_dentry_negative(void) { - int i; - long sum = 0; - - for_each_possible_cpu(i) - sum += per_cpu(nr_dentry_negative, i); + long sum = per_cpu_sum(&nr_dentry_negative); return sum < 0 ? 0 : sum; } diff --git a/include/linux/percpu.h b/include/linux/percpu.h index 4b2047b78b67..0df28ff54f66 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -162,4 +162,14 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr); extern unsigned long pcpu_nr_pages(void); +#define per_cpu_sum(_p) \ +({ \ + typeof(*(_p)) sum = 0; \ + int cpu; \ + \ + for_each_possible_cpu(cpu) \ + sum += *per_cpu_ptr(_p, cpu); \ + sum; \ +}) + #endif /* __LINUX_PERCPU_H */