[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <jewtporls43r5y3eybqzm4bcku5sf3wzw6ewfjbyykeb3mxp27@ydjcrck6ldkd>
Date: Tue, 27 May 2025 21:28:35 +0200
From: "Pankaj Raghav (Samsung)" <kernel@...kajraghav.com>
To: Dave Hansen <dave.hansen@...el.com>
Cc: Pankaj Raghav <p.raghav@...sung.com>,
Suren Baghdasaryan <surenb@...gle.com>, Ryan Roberts <ryan.roberts@....com>,
Vlastimil Babka <vbabka@...e.cz>, Baolin Wang <baolin.wang@...ux.alibaba.com>,
Borislav Petkov <bp@...en8.de>, Ingo Molnar <mingo@...hat.com>,
"H . Peter Anvin" <hpa@...or.com>, Zi Yan <ziy@...dia.com>, Mike Rapoport <rppt@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>, Michal Hocko <mhocko@...e.com>,
David Hildenbrand <david@...hat.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>, Thomas Gleixner <tglx@...utronix.de>,
Nico Pache <npache@...hat.com>, Dev Jain <dev.jain@....com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>, Jens Axboe <axboe@...nel.dk>, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, linux-block@...r.kernel.org, willy@...radead.org, x86@...nel.org,
linux-fsdevel@...r.kernel.org, "Darrick J . Wong" <djwong@...nel.org>, mcgrof@...nel.org,
gost.dev@...sung.com, hch@....de
Subject: Re: [RFC 2/3] mm: add STATIC_PMD_ZERO_PAGE config option
> > You are right that if this config is disabled, the callers with NULL mm
> > struct are guaranteed to fail, but we are not generating extra code
> > because there are still users who want dynamic allocation.
>
> I'm pretty sure you're making the compiler generate unnecessary code.
> Think of this:
>
> if (mm_get_huge_zero_folio(mm)
> foo();
> else
> bar();
>
> With the static zero page, foo() is always called. But bar() is dead
> code. The compiler doesn't know that, so it will generate both sides of
> the if().
>
Ahh, yeah you are right. I was thinking about the callee and not the
caller.
> If you can get the CONFIG_... option checks into the header, the
> compiler can figure it out and not even generate the call to bar().
Got it. I will keep this in mind before sending the next version.
> > Do you think it is better to have the code with inside an #ifdef instead
> > of using the IS_ENABLED primitive?
> It has nothing to do with an #ifdef versus IS_ENABLED(). It has to do
> with the compiler having visibility into how mm_get_huge_zero_folio()
> works enough to optimize its callers.
I think something like this should give some visibility to the compiler:
struct folio *huge_zero_folio __read_mostly;
...
#if CONFIG_STATIC_PMD_ZERO_PAGE
struct folio* mm_get_huge_zero_folio(...)
{
return READ_ONCE(huge_zero_folio);
}
#else
struct folio* mm_get_huge_zero_folio(...)
{
<old-code>
}
#endif
But I am not sure here if the compiler can assume here the static
huge_zero_folio variable will be non-NULL. It will be interesting to
check that in the output.
--
Pankaj
Powered by blists - more mailing lists