]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cleanup: Optimize guards
authorPeter Zijlstra <peterz@infradead.org>
Mon, 9 Mar 2026 16:40:42 +0000 (17:40 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 16 Mar 2026 12:16:49 +0000 (13:16 +0100)
commit2deccd5c862a0337a691bcfaa87919b4216e6103
tree159c143067bbb3d55cac77736cd8c2e629728793
parentacb38872d4cbec5b6825345d9d757e21d2d9d953
cleanup: Optimize guards

Andrew reported that a guard() conversion of zone_lock increased the
code size unnecessarily.

It turns out the unconditional __GUARD_IS_ERR() is to blame. As
explored earlier [1], __GUARD_IS_ERR(), similar to IS_ERR_OR_NULL(),
generates somewhat sub-optimal code.

However, looking at things again, it is possible to avoid doing the
__GUARD_IS_ERR() unconditionally. Revert the normal destructors to a
simple NULL test and only add the IS_ERR bit to COND guards.

This cures the reported overhead; as compiled by GCC-16:

page_alloc.o:

pre: Total: Before=45299, After=45371, chg +0.16%
post: Total: Before=45299, After=45026, chg -0.60%

[1] https://lkml.kernel.org/r/20250513085001.GC25891@noisy.programming.kicks-ass.net

Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20260309164516.GE606826@noisy.programming.kicks-ass.net
include/linux/cleanup.h