Skip to content

Commit 2cdc011

Browse files
Chengming Zhouopsiff
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 <zhouchengming@bytedance.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> (cherry picked from commit 90b1e56)
1 parent c53792f commit 2cdc011

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

mm/slub.c

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

31383138
new.counters = counters;
3139-
VM_BUG_ON(!new.frozen);
31403139

31413140
new.inuse = slab->objects;
31423141
new.frozen = freelist != NULL;
@@ -3308,18 +3307,20 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
33083307

33093308
slab = slub_percpu_partial(c);
33103309
slub_set_percpu_partial(c, slab);
3311-
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
3312-
stat(s, CPU_PARTIAL_ALLOC);
33133310

3314-
if (unlikely(!node_match(slab, node) ||
3315-
!pfmemalloc_match(slab, gfpflags))) {
3316-
slab->next = NULL;
3317-
__put_partials(s, slab);
3318-
continue;
3311+
if (likely(node_match(slab, node) &&
3312+
pfmemalloc_match(slab, gfpflags))) {
3313+
c->slab = slab;
3314+
freelist = get_freelist(s, slab);
3315+
VM_BUG_ON(!freelist);
3316+
stat(s, CPU_PARTIAL_ALLOC);
3317+
goto load_freelist;
33193318
}
33203319

3321-
freelist = freeze_slab(s, slab);
3322-
goto retry_load_slab;
3320+
local_unlock_irqrestore(&s->cpu_slab->lock, flags);
3321+
3322+
slab->next = NULL;
3323+
__put_partials(s, slab);
33233324
}
33243325
#endif
33253326

0 commit comments

Comments
 (0)