linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>,
	oleg@redhat.com, brauner@kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v3 2/2] pid: only take pidmap_lock once on alloc
Date: Sun, 7 Dec 2025 10:37:55 +0000	[thread overview]
Message-ID: <20251207103755.70be2f89@pumpkin> (raw)
In-Reply-To: <CAGudoHFjrMsQaDzndo3sM1Jn_WROBrZ0PeQbU89-tDakLAOvew@mail.gmail.com>

On Sun, 7 Dec 2025 10:21:35 +0100
Mateusz Guzik <mjguzik@gmail.com> wrote:

> On Sun, Dec 7, 2025 at 8:21 AM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Sat, Dec 06, 2025 at 02:19:55PM +0100, Mateusz Guzik wrote:  
> > > -     if (!pid)
> > > +     if (unlikely(!pid))  
> >
> > Does this change anything?  I was under the impression that gcc already
> > treats !p as unlikely.  
> 
> I don't know if gcc is guaranteed to act like that, most of my
> experience is with clang which was rather inconsistent about it.
> 

If nothing else unlikely() are information for the human (and other) reader.

In my experience, a simple if () is always coded as a forwards jump around
the controlled code - regardless of any likely/unlikely annotation.
Similarly 'if () continue/break' is an immediate jump to the loop end code.
You need to add a non-empty 'else' branch, or something before the
continue/break for the un/likely to have an effect (an asm() comment will do).

While some instruction sets have explicit 'branch expected taken' markers
others (like x86 - except P6) don't.
Similarly some cpu predict backwards branches taken if their is nothing
in the branch predictor, others (including some x86) just use the relevant
branch predictor 'slot' without regard for the actual branch address.
Then there is the branch prediction done by the instruction fetch/decode
unit, that has a tendency to use markers on the cache line - so doesn't
necessarily even check it is a branch instruction!

Basically the coder doesn't have much control at all on many cpu.

Oh, and using un/likely() can make the code worse.

	David

 


      reply	other threads:[~2025-12-07 10:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-06 13:19 [PATCH v3 0/2] further damage-control lack of clone scalability Mateusz Guzik
2025-12-06 13:19 ` [PATCH v3 1/2] ns: pad refcount Mateusz Guzik
2025-12-06 13:19 ` [PATCH v3 2/2] pid: only take pidmap_lock once on alloc Mateusz Guzik
2025-12-07  7:21   ` Matthew Wilcox
2025-12-07  9:21     ` Mateusz Guzik
2025-12-07 10:37       ` David Laight [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=20251207103755.70be2f89@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mjguzik@gmail.com \
    --cc=oleg@redhat.com \
    --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