]> git.ipfire.org Git - thirdparty/linux.git/commit
pid: only take pidmap_lock once on alloc
authorMateusz Guzik <mjguzik@gmail.com>
Wed, 3 Dec 2025 09:28:51 +0000 (10:28 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 15 Dec 2025 13:33:38 +0000 (14:33 +0100)
commit6d864a1b182532e7570383af8825fa4ddcd24243
treec4d5409a5c3f3f173c86cb990d78c55fbed5905d
parentc0aac5975bafc86f6817b14e9f71dcb5064a9183
pid: only take pidmap_lock once on alloc

When spawning and killing threads in separate processes in parallel the
primary bottleneck on the stock kernel is pidmap_lock, largely because
of a back-to-back acquire in the common case. This aspect is fixed with
the patch.

Performance improvement varies between reboots. When benchmarking with
20 processes creating and killing threads in a loop, the unpatched
baseline hovers around 465k ops/s, while patched is anything between
~510k ops/s and ~560k depending on false-sharing (which I only minimally
sanitized). So this is at least 10% if you are unlucky.

The change also facilitated some cosmetic fixes.

It has an unintentional side effect of no longer issuing spurious
idr_preload() around idr_replace().

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20251203092851.287617-3-mjguzik@gmail.com
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
kernel/pid.c