From: Andrew Morton <akpm@linux-foundation.org>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Jeongjun Park <aha310510@gmail.com>,
dennis@kernel.org, tj@kernel.org, cl@linux.com, jack@suse.cz,
hughd@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/percpu_counter: fix data race in __percpu_counter_limited_add()
Date: Tue, 6 May 2025 17:10:51 -0700 [thread overview]
Message-ID: <20250506171051.7c9a4bed6ff799e8060ca0d7@linux-foundation.org> (raw)
In-Reply-To: <aiap53zqms4igpmdxorv45xsgzyx44xb57jupr2ndiibu3qugo@mg53s6mdbq3j>
On Tue, 6 May 2025 13:56:13 +0200 Mateusz Guzik <mjguzik@gmail.com> wrote:
> > unknown = batch * num_online_cpus();
> > count = __this_cpu_read(*fbc->counters);
> >
> > @@ -344,11 +345,10 @@ bool __percpu_counter_limited_add(struct percpu_counter *fbc,
> > ((amount > 0 && fbc->count + unknown <= limit) ||
> > (amount < 0 && fbc->count - unknown >= limit))) {
> > this_cpu_add(*fbc->counters, amount);
> > - local_irq_restore(flags);
> > - return true;
> > + good = true;
> > + goto out;
> > }
> >
> > - raw_spin_lock(&fbc->lock);
> > count = fbc->count + amount;
> >
> > /* Skip percpu_counter_sum() when safe */
> > --
> >
>
> As this always takes the centralized lock in the fast path this defeats
> the point of using a per-cpu counter in the first place.
Well. It partially "defeats the point" if the client code actually
uses percpu_counter_limited_add(). Only shmem.c does that.
> I noted this thing is buggy almost a year ago:
> https://lore.kernel.org/linux-mm/5eemkb4lo5eefp7ijgncgogwmadyzmvjfjmmmvfiki6cwdskfs@hi2z4drqeuz6/
>
> per the e-mail I don't believe existence of this routine is warranted.
>
> shmem is still the only consumer.
Totally. It would be better to remove percpu_counter_limited_add() and
to implement its intended effect within shmem.c
prev parent reply other threads:[~2025-05-07 0:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 10:24 Jeongjun Park
2025-05-06 11:56 ` Mateusz Guzik
2025-05-07 0:10 ` Andrew Morton [this message]
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=20250506171051.7c9a4bed6ff799e8060ca0d7@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aha310510@gmail.com \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mjguzik@gmail.com \
--cc=tj@kernel.org \
/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