From: "André Draszik" <andre.draszik@linaro.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org
Cc: "André Almeida" <andrealmeid@igalia.com>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Valentin Schneider" <vschneid@redhat.com>,
"Waiman Long" <longman@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@redhat.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Michal Hocko" <mhocko@suse.com>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
linux-mm@kvack.org
Subject: Re: [PATCH v2 2/6] futex: Use RCU-based per-CPU reference counting instead of rcuref_t
Date: Wed, 30 Jul 2025 13:20:18 +0100 [thread overview]
Message-ID: <0c8cc83bb73abf080faf584f319008b67d0931db.camel@linaro.org> (raw)
In-Reply-To: <20250710110011.384614-3-bigeasy@linutronix.de>
On Thu, 2025-07-10 at 13:00 +0200, Sebastian Andrzej Siewior wrote:
> From: Peter Zijlstra <peterz@infradead.org>
>
> The use of rcuref_t for reference counting introduces a performance bottleneck
> when accessed concurrently by multiple threads during futex operations.
>
> Replace rcuref_t with special crafted per-CPU reference counters. The
> lifetime logic remains the same.
>
> The newly allocate private hash starts in FR_PERCPU state. In this state, each
> futex operation that requires the private hash uses a per-CPU counter (an
> unsigned int) for incrementing or decrementing the reference count.
>
> When the private hash is about to be replaced, the per-CPU counters are
> migrated to a atomic_t counter mm_struct::futex_atomic.
> The migration process:
> - Waiting for one RCU grace period to ensure all users observe the
> current private hash. This can be skipped if a grace period elapsed
> since the private hash was assigned.
>
> - futex_private_hash::state is set to FR_ATOMIC, forcing all users to
> use mm_struct::futex_atomic for reference counting.
>
> - After a RCU grace period, all users are guaranteed to be using the
> atomic counter. The per-CPU counters can now be summed up and added to
> the atomic_t counter. If the resulting count is zero, the hash can be
> safely replaced. Otherwise, active users still hold a valid reference.
>
> - Once the atomic reference count drops to zero, the next futex
> operation will switch to the new private hash.
>
> call_rcu_hurry() is used to speed up transition which otherwise might be
> delay with RCU_LAZY. There is nothing wrong with using call_rcu(). The
> side effects would be that on auto scaling the new hash is used later
> and the SET_SLOTS prctl() will block longer.
>
> [bigeasy: commit description + mm get/ put_async]
kmemleak complains about a new memleak with this commit:
[ 680.179004][ T101] kmemleak: 1 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
$ cat /sys/kernel/debug/kmemleak
unreferenced object (percpu) 0xc22ec0eface8 (size 4):
comm "swapper/0", pid 1, jiffies 4294893115
hex dump (first 4 bytes on cpu 7):
01 00 00 00 ....
backtrace (crc b8bc6765):
kmemleak_alloc_percpu+0x48/0xb8
pcpu_alloc_noprof+0x6ac/0xb68
futex_mm_init+0x60/0xe0
mm_init+0x1e8/0x3c0
mm_alloc+0x5c/0x78
init_args+0x74/0x4b0
debug_vm_pgtable+0x60/0x2d8
do_one_initcall+0x128/0x3e0
do_initcall_level+0xb4/0xe8
do_initcalls+0x60/0xb0
do_basic_setup+0x28/0x40
kernel_init_freeable+0x158/0x1f8
kernel_init+0x2c/0x1e0
ret_from_fork+0x10/0x20
And futex_mm_init+0x60/0xe0 resolves to
mm->futex_ref = alloc_percpu(unsigned int);
in futex_mm_init().
Reverting this commit (and patches 3 and 4 in this series due to context),
makes kmemleak happy again.
Cheers,
Andre'
next prev parent reply other threads:[~2025-07-30 12:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250710110011.384614-1-bigeasy@linutronix.de>
2025-07-10 11:00 ` [PATCH v2 2/6] futex: Use RCU-based per-CPU reference counting instead of rcuref_t Sebastian Andrzej Siewior
2025-07-30 12:20 ` André Draszik [this message]
2025-07-30 19:44 ` Thomas Gleixner
2025-08-01 14:59 ` André Draszik
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=0c8cc83bb73abf080faf584f319008b67d0931db.camel@linaro.org \
--to=andre.draszik@linaro.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=david@redhat.com \
--cc=dvhart@infradead.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
--cc=vschneid@redhat.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).