Re: [RFC PATCH] mm/page_alloc.c: Micro-optimisation Remove unnecessary branch

From: Matthew Wilcox
Date: Sun Mar 08 2020 - 07:50:30 EST


On Sat, Mar 07, 2020 at 03:15:42PM -0800, Andrew Morton wrote:
> On Sat, 7 Mar 2020 23:53:35 +0100 mateusznosek0@xxxxxxxxx wrote:
> > - if (unlikely(ac.nodemask != nodemask))
> > - ac.nodemask = nodemask;
> > + ac.nodemask = nodemask;
>
> This will now unconditionally dirty the ac.nodemask cacheline, which
> means that cacheline will need to be written back. If it is truly
> unlikely that the write was needed then the thinking goes that the
> test-and-branch is worthwhile, by saving on memory traffic.
>
> At least, I assume that's why the code is the way it is.

The line immediately before this hunk is:

ac.spread_dirty_pages = false;

ac is on-stack and is only 32 bytes. I don't see a reason not to do this.

Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>