> > 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