From: Andrew Morton <akpm@linux-foundation.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
Xie Yuanbin <qq570070308@gmail.com>,
willy@infradead.org, Liam.Howlett@oracle.com, david@kernel.org,
justinstitt@google.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, ljs@kernel.org, llvm@lists.linux.dev,
mhocko@suse.com, morbo@google.com, nathan@kernel.org,
nick.desaulniers+lkml@gmail.com, rppt@kernel.org,
surenb@google.com
Subject: Re: [PATCH] mm: optimize the implementation of WARN_ON_ONCE_GFP()
Date: Thu, 26 Mar 2026 22:34:20 -0700 [thread overview]
Message-ID: <20260326223420.cf92ff1d55d078390cb10cb9@linux-foundation.org> (raw)
In-Reply-To: <20260310145231.1680db9b@pumpkin>
On Tue, 10 Mar 2026 14:52:31 +0000 David Laight <david.laight.linux@gmail.com> wrote:
> > > If a and b is both unlikely, then "unlikely(a) && unlikely(b)" will
> > > generate better code than "unlikely(a && b)". This is also true for gcc.
> >
> > What are the details of how it's better for gcc?
>
> I'm not sure about that specific case, but I've definitely seen gcc
> generate sub-optimal code for some un/likely() of compound expressions.
> The underlying cause is that the code is (probably) first transformed to:
> bool tmp = expression;
> if (unlikely(tmp)) ...
> this means that you lose some of the short-circuiting that happens
> early in the code generation of 'if (expression)'.
>
> It is also not at all clear what you want the compiler to generate.
> For 'unlikely(a || b)' you want 'if (a) goto x; if (b) goto x' so that
> the 'likely' path is the no-branch one.
> But for 'unlikely(a && b)' you still want 'if (a) goto x; y:' which means
> that the 'b' test is out-of-line and has to be 'x: if (!b) goto y' to
> avoid a branch when a is false - but that means you have a 'normally
> taken' branch after the test of b.
> That pretty much means the compiler has to decide which unlikely()
> to ignore.
> So it only makes sense to do 'if (unlikely(a) && b)'.
> Indeed even 'if (unlikely(a) && likely(b))' may be better!
fwiw, this change makes no change to `size mm/page_alloc.o' for x86_64
gcc defconfig.
Given the expressed objections and that WARN_ON_ONCE_GFP() is used only
twice in the whole kernel, I think I'll remove this patch.
Xie, if you disagree with this then please resubmit the patch with a
more convincing justification and hopefully people will reconsider it.
Thanks.
prev parent reply other threads:[~2026-03-27 5:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:38 Xie Yuanbin
2026-03-09 15:40 ` Matthew Wilcox
2026-03-09 15:59 ` Xie Yuanbin
2026-03-10 10:55 ` Vlastimil Babka (SUSE)
2026-03-10 14:52 ` David Laight
2026-03-27 5:34 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260326223420.cf92ff1d55d078390cb10cb9@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Liam.Howlett@oracle.com \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mhocko@suse.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=qq570070308@gmail.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox