Re: [PATCH] setup: dynamically detect default huge page size
Gabriel Krisman Bertazi <[email protected]>
| Newsgroups | org.kernel.vger.io-uring |
|---|---|
| Organization | SUSE |
| Message-ID | <[email protected]> |
Prateek <[email protected]> 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