Skip to content

Commit 90b1e56

Browse files
Chengming Zhoutehcaster
authored andcommitted
mm/slub: directly load freelist from cpu partial slab in the likely case
The likely case is that we get a usable slab from the cpu partial list, we can directly load freelist from it and return back, instead of going the other way that need more work, like reenable interrupt and recheck. But we need to remove the "VM_BUG_ON(!new.frozen)" in get_freelist() for reusing it, since cpu partial slab is not frozen. It seems acceptable since it's only for debug purpose. And get_freelist() also assumes it can return NULL if the freelist is empty, which is not possible for the cpu partial slab case, so we add "VM_BUG_ON(!freelist)" after get_freelist() to make it explicit. There is some small performance improvement too, which shows by: perf bench sched messaging -g 5 -t -l 100000 mm-stable slub-optimize Total time 7.473 7.209 Signed-off-by: Chengming Zhou <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 6613476 commit 90b1e56

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

mm/slub.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,6 @@ static inline void *get_freelist(struct kmem_cache *s, struct slab *slab)
33263326
counters = slab->counters;
33273327

33283328
new.counters = counters;
3329-
VM_BUG_ON(!new.frozen);
33303329

33313330
new.inuse = slab->objects;
33323331
new.frozen = freelist != NULL;
@@ -3498,18 +3497,20 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
34983497

34993498
slab = slub_percpu_partial(c);
35003499
slub_set_percpu_partial(c, slab);
3501-
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
3502-
stat(s, CPU_PARTIAL_ALLOC);
35033500

3504-
if (unlikely(!node_match(slab, node) ||
3505-
!pfmemalloc_match(slab, gfpflags))) {
3506-
slab->next = NULL;
3507-
__put_partials(s, slab);
3508-
continue;
3501+
if (likely(node_match(slab, node) &&
3502+
pfmemalloc_match(slab, gfpflags))) {
3503+
c->slab = slab;
3504+
freelist = get_freelist(s, slab);
3505+
VM_BUG_ON(!freelist);
3506+
stat(s, CPU_PARTIAL_ALLOC);
3507+
goto load_freelist;
35093508
}
35103509

3511-
freelist = freeze_slab(s, slab);
3512-
goto retry_load_slab;
3510+
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
3511+
3512+
slab->next = NULL;
3513+
__put_partials(s, slab);
35133514
}
35143515
#endif
35153516

0 commit comments

Comments
 (0)