From: Dave Chinner <david@fromorbit.com>
To: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org
Cc: linux-mm@vger.kernel.org, linux-fsdevel@vger.kernel.org,
yebin10@huawei.com
Subject: [PATCH 4/4] pcpcntr: remove percpu_counter_sum_all()
Date: Wed, 15 Mar 2023 19:49:38 +1100 [thread overview]
Message-ID: <20230315084938.2544737-5-david@fromorbit.com> (raw)
In-Reply-To: <20230315084938.2544737-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
percpu_counter_sum_all() is now redundant as the race condition it
was invented to handle is now dealt with by percpu_counter_sum()
directly and all users of percpu_counter_sum_all() have been
removed.
Remove it.
This effectively reverts the changes made in f689054aace2
("percpu_counter: add percpu_counter_sum_all interface") except for
the cpumask iteration that fixes percpu_counter_sum() made earlier
in this series.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
include/linux/percpu_counter.h | 6 -----
lib/percpu_counter.c | 40 ++++++++++------------------------
2 files changed, 11 insertions(+), 35 deletions(-)
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h
index 521a733e21a9..75b73c83bc9d 100644
--- a/include/linux/percpu_counter.h
+++ b/include/linux/percpu_counter.h
@@ -45,7 +45,6 @@ void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
void percpu_counter_add_batch(struct percpu_counter *fbc, s64 amount,
s32 batch);
s64 __percpu_counter_sum(struct percpu_counter *fbc);
-s64 percpu_counter_sum_all(struct percpu_counter *fbc);
int __percpu_counter_compare(struct percpu_counter *fbc, s64 rhs, s32 batch);
void percpu_counter_sync(struct percpu_counter *fbc);
@@ -196,11 +195,6 @@ static inline s64 percpu_counter_sum(struct percpu_counter *fbc)
return percpu_counter_read(fbc);
}
-static inline s64 percpu_counter_sum_all(struct percpu_counter *fbc)
-{
- return percpu_counter_read(fbc);
-}
-
static inline bool percpu_counter_initialized(struct percpu_counter *fbc)
{
return true;
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 0e096311e0c0..5004463c4f9f 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -122,23 +122,6 @@ void percpu_counter_sync(struct percpu_counter *fbc)
}
EXPORT_SYMBOL(percpu_counter_sync);
-static s64 __percpu_counter_sum_mask(struct percpu_counter *fbc,
- const struct cpumask *cpu_mask)
-{
- s64 ret;
- int cpu;
- unsigned long flags;
-
- raw_spin_lock_irqsave(&fbc->lock, flags);
- ret = fbc->count;
- for_each_cpu_or(cpu, cpu_online_mask, cpu_mask) {
- s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
- ret += *pcount;
- }
- raw_spin_unlock_irqrestore(&fbc->lock, flags);
- return ret;
-}
-
/*
* Add up all the per-cpu counts, return the result. This is a more accurate
* but much slower version of percpu_counter_read_positive().
@@ -153,22 +136,21 @@ static s64 __percpu_counter_sum_mask(struct percpu_counter *fbc,
*/
s64 __percpu_counter_sum(struct percpu_counter *fbc)
{
+ s64 ret;
+ int cpu;
+ unsigned long flags;
- return __percpu_counter_sum_mask(fbc, cpu_dying_mask);
+ raw_spin_lock_irqsave(&fbc->lock, flags);
+ ret = fbc->count;
+ for_each_cpu_or(cpu, cpu_online_mask, cpu_dying_mask) {
+ s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
+ ret += *pcount;
+ }
+ raw_spin_unlock_irqrestore(&fbc->lock, flags);
+ return ret;
}
EXPORT_SYMBOL(__percpu_counter_sum);
-/*
- * This is slower version of percpu_counter_sum as it traverses all possible
- * cpus. Use this only in the cases where accurate data is needed in the
- * presense of CPUs getting offlined.
- */
-s64 percpu_counter_sum_all(struct percpu_counter *fbc)
-{
- return __percpu_counter_sum_mask(fbc, cpu_possible_mask);
-}
-EXPORT_SYMBOL(percpu_counter_sum_all);
-
int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, gfp_t gfp,
struct lock_class_key *key)
{
--
2.39.2
next prev parent reply other threads:[~2023-03-15 8:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-15 8:49 [PATCH 0/4] pcpctr: fix percpu_counter_sum vs cpu offline race Dave Chinner
2023-03-15 8:49 ` [PATCH 1/4] cpumask: introduce for_each_cpu_or Dave Chinner
2023-03-15 8:49 ` [PATCH 2/4] pcpcntrs: fix dying cpu summation race Dave Chinner
2023-03-15 8:49 ` [PATCH 3/4] fork: remove use of percpu_counter_sum_all Dave Chinner
2023-03-15 8:49 ` Dave Chinner [this message]
2023-03-15 19:22 ` [PATCH 4/4] pcpcntr: remove percpu_counter_sum_all() kernel test robot
2023-03-15 20:55 ` Dave Chinner
2023-03-17 2:22 ` Yujie Liu
2023-03-15 20:14 ` kernel test robot
2023-03-15 21:21 ` Darrick J. Wong
[not found] ` <20230315233618.2168-1-hdanton@sina.com>
2023-03-18 0:37 ` [PATCH 2/4] pcpcntrs: fix dying cpu summation race Dave Chinner
2023-03-18 0:41 ` [PATCH 0/4] pcpctr: fix percpu_counter_sum vs cpu offline race Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230315084938.2544737-5-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=yebin10@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).