]> 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>
Tue, 12 Nov 2024 16:19:24 +0000 (17:19 +0100)
commitc9f40620a790e13720a1e4ba55a1a74925306338
treead17ae1075adabcf50420ce90716fcacdf0dda35
parentb38c6352b599efab37659ee725290b5417086cb7
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