]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm, slub: cheaper locking for percpu sheaves
authorVlastimil Babka <vbabka@suse.cz>
Wed, 28 Aug 2024 09:28:19 +0000 (11:28 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Fri, 17 Jan 2025 15:57:36 +0000 (16:57 +0100)
commitcba930ce7af3e2f47f615f00a41aa4f1708f4845
tree67304c2333dc30c72a5ba0fdd23fb5045c682795
parentc50f6797af39c7b60c65b061a6a56c8eeb3c54b6
mm, slub: cheaper locking for percpu sheaves

Instead of local_lock_irqsave(), use just get_cpu_ptr() (which only
disables preemption) and then set an active flag. If potential callers
include irq handler, the operation must use a trylock variant that bails
out if the flag is already set to active because we interrupted another
operation in progress.

Changing the flag doesn't need to be atomic as the irq is one the same
cpu. This should make using percpu sheaves cheaper, with the downside of
some unlucky operations in irq handlers have to fallback to non-sheave
variants. That should be rare so there should be a net benefit.

On PREEMPT_RT we can use simply local_lock() as that does the right
thing without the need to disable irqs.

Thanks to Mateusz Guzik and Jann Horn for suggesting this kind of
locking scheme in online conversations. Initially attempted to fully
copy the page allocator's pcplist locking, but its reliance on
spin_trylock() made it much more costly.

Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c