Skip to content

Commit c270cf3

Browse files
Abel Wutorvalds
authored andcommitted
mm/slub.c: branch optimization in free slowpath
The two conditions are mutually exclusive and gcc compiler will optimise this into if-else-like pattern. Given that the majority of free_slowpath is free_frozen, let's provide some hint to the compilers. Tests (perf bench sched messaging -g 20 -l 400000, executed 10x after reboot) are done and the summarized result: un-patched patched max. 192.316 189.851 min. 187.267 186.252 avg. 189.154 188.086 stdev. 1.37 0.99 Signed-off-by: Abel Wu <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: David Rientjes <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Hewenliang <[email protected]> Cc: Hu Shiyuan <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent d7cff4d commit c270cf3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

mm/slub.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,20 +3019,21 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
30193019

30203020
if (likely(!n)) {
30213021

3022-
/*
3023-
* If we just froze the page then put it onto the
3024-
* per cpu partial list.
3025-
*/
3026-
if (new.frozen && !was_frozen) {
3022+
if (likely(was_frozen)) {
3023+
/*
3024+
* The list lock was not taken therefore no list
3025+
* activity can be necessary.
3026+
*/
3027+
stat(s, FREE_FROZEN);
3028+
} else if (new.frozen) {
3029+
/*
3030+
* If we just froze the page then put it onto the
3031+
* per cpu partial list.
3032+
*/
30273033
put_cpu_partial(s, page, 1);
30283034
stat(s, CPU_PARTIAL_FREE);
30293035
}
3030-
/*
3031-
* The list lock was not taken therefore no list
3032-
* activity can be necessary.
3033-
*/
3034-
if (was_frozen)
3035-
stat(s, FREE_FROZEN);
3036+
30363037
return;
30373038
}
30383039

0 commit comments

Comments
 (0)