[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <576136E0-440F-4727-969D-B558C862CD19@nvidia.com>
Date: Wed, 21 Jan 2026 13:21:45 -0500
From: Zi Yan <ziy@...dia.com>
To: Kiryl Shutsemau <kas@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Muchun Song <muchun.song@...ux.dev>, David Hildenbrand <david@...nel.org>,
Matthew Wilcox <willy@...radead.org>, Usama Arif <usamaarif642@...il.com>,
Frank van der Linden <fvdl@...gle.com>, Oscar Salvador <osalvador@...e.de>,
Mike Rapoport <rppt@...nel.org>, Vlastimil Babka <vbabka@...e.cz>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Baoquan He <bhe@...hat.com>,
Michal Hocko <mhocko@...e.com>, Johannes Weiner <hannes@...xchg.org>,
Jonathan Corbet <corbet@....net>, kernel-team@...a.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org
Subject: Re: [PATCHv4 13/14] mm: Remove the branch from compound_head()
On 21 Jan 2026, at 11:22, Kiryl Shutsemau wrote:
> The compound_head() function is a hot path. For example, the zap path
> calls it for every leaf page table entry.
>
> Rewrite the helper function in a branchless manner to eliminate the risk
> of CPU branch misprediction.
>
> Signed-off-by: Kiryl Shutsemau <kas@...nel.org>
> Reviewed-by: Muchun Song <muchun.song@...ux.dev>
> ---
> include/linux/page-flags.h | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
LGTM. And it fixed the issue in patch 10.
Reviewed-by: Zi Yan <ziy@...dia.com>
>
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index f89702e101e8..95ac963b78af 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -224,25 +224,32 @@ static __always_inline bool compound_info_has_mask(void)
> static __always_inline unsigned long _compound_head(const struct page *page)
> {
> unsigned long info = READ_ONCE(page->compound_info);
> + unsigned long mask;
> +
> + if (!compound_info_has_mask()) {
> + /* Bit 0 encodes PageTail() */
> + if (info & 1)
> + return info - 1;
>
> - /* Bit 0 encodes PageTail() */
> - if (!(info & 1))
> return (unsigned long)page;
Here, info & 1 check now is guarded by compound_info_has_mask(), so the
issue I mentioned in Patch 10 is gone.
> -
> - /*
> - * If compound_info_has_mask() is false, the rest of compound_info is
> - * the pointer to the head page.
> - */
> - if (!compound_info_has_mask())
> - return info - 1;
> + }
Best Regards,
Yan, Zi
Powered by blists - more mailing lists