Re: [PATCH] mm: optimize once judgment with clang
From: Mike Rapoport
Date: Sun Mar 08 2026 - 14:03:22 EST
On Sat, Mar 07, 2026 at 10:41:35PM +0800, Xie Yuanbin wrote:
> On Sat, 7 Mar 2026 10:12:18 +0200, Mike Rapoport wrote:
> > On Sat, Mar 07, 2026 at 02:54:04PM +0800, Xie Yuanbin wrote:
> >> commit 242b872239f6a7deacbc ("include/linux/once_lite.h: fix judgment in
> >> WARN_ONCE with clang") helps optimize performance and size under the
> >> clang compiler, but the modification is not complete.
> >
> > How much does it actually optimize for size?
>
> Basing on commit a0ae2a256046c0c5d377 ("Add linux-next specific
> files for 20260306"), compiler "Debian clang version 21.1.8 (5)",
> arm64 default defconfig, and setting CONFIG_CC_OPTIMIZE_FOR_SIZE=y,
> the size result is:
> | | size |
> | -| -|
> | Image.gz | 14256146 |
> | size of ".text" section in vmlinex | 17035264 |
>
> Basing on above, revert the commit 242b872239f6a7deacbc
> ("include/linux/once_lite.h: fix judgment in WARN_ONCE with clang"),
> and build again:
> | | size |
> | -| -|
> | Image.gz | 14258152(+2006) |
> | size of ".text" section in vmlinex | 17039360(+4096) |
It would be nice to see where the difference is with scripts/bloat-o-meter.
And while commit 242b872239f6a7deacbc is a oneliner that essentially
updates most of the _ONCE constructs, I'm not convinced that the churn in
the patch that updates include/linux/mmdebug.h worth it.
Do you have the numbers for this patch as well?
> > Note that performance is really not critical here because we are already
> > dealing with slow path of debug code.
>
> It seems that WARN_ON_ONCE_GFP() is not affected by in CONFIG_DEBUG_VM,
> and it is used in __alloc_frozen_pages_noprof(), which seems to be a hot
> path.
What might be useful there is to change the order of conditions so that
__ret_warn_once will be evaluated first.
--
Sincerely yours,
Mike.