From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Prateek <kprateek283@gmail.com>
Cc: io-uring@vger.kernel.org, kprateek283@gmail.com
Subject: Re: [PATCH] setup: dynamically detect default huge page size
Date: Tue, 23 Jun 2026 11:11:27 -0400 [thread overview]
Message-ID: <87jyrpuw9s.fsf@mailhost.krisman.be> (raw)
In-Reply-To: <20260623110930.910263-1-kprateek283@gmail.com>
Prateek <kprateek283@gmail.com> writes:
> Hi Gabriel,
>
> Thanks for the review.
>
> On Mon, Jun 22, 2026 at 16:49 Gabriel Krisman Bertazi wrote:
>> > +static size_t get_huge_page_size(void)
>> > +{
>> > + static size_t hps;
>>
>> Please, initialize your static variables to makes it readable. I.e,
>> should be initialized it to 2MB.
>
> hps is left at 0 on purpose as a "not computed yet" flag -- same thing
> get_page_size() does in arch/aarch64/lib.h with cache_val. If I set
> hps = 2MB upfront, the first call just returns 2MB without ever
> reading /proc/meminfo, which defeats the point.
Ah, of course. Back to the original point, please initialize hps
explicitly (to 0). Yeah, I know the compiler should do that for you in
C99. Still, make it explicit.
>
>> > + size_t ret = 2 * 1024 * 1024; /* fallback: 2MB */
>>
>> ret redundant with hps, could go away.
>
> The local ret is there so I only write to hps once at the end. If two
> threads race into this function, neither one sees a half-baked
> fallback value in hps. The race itself is harmless since both threads
> would compute the same result anyway.
No, it is redundant. You don't need to have "half-baked" values in hps
either. as you already use val to build your hugepage size. ret is just an
extra step that will vanish in compilation.
There are many ways around it. For instance:
unsigned long val = 0;
...
out:
hps = (val)?: 2*1024*1024; /* fallback to 2 MB pages */
return hps;
--
Gabriel Krisman Bertazi
prev parent reply other threads:[~2026-06-23 15:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-20 11:36 [PATCH] setup: dynamically detect default huge page size Prateek
2026-06-22 16:49 ` Gabriel Krisman Bertazi
2026-06-23 11:09 ` Prateek
2026-06-23 15:11 ` Gabriel Krisman Bertazi [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=87jyrpuw9s.fsf@mailhost.krisman.be \
--to=krisman@suse.de \
--cc=io-uring@vger.kernel.org \
--cc=kprateek283@gmail.com \
/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