On Mon, May 11, 2026 at 05:02:06AM -0400, Michael S. Tsirkin wrote:
> Move prep_compound_page() before post_alloc_hook() in prep_new_page().
> 
> The next patch adds a folio_zero_user() call to post_alloc_hook(),
> which uses folio_nr_pages() to determine how many pages to zero.
> Without compound metadata set up first, folio_nr_pages() returns 1
> for higher-order allocations, so only the first page would be zeroed.
> 
> All other operations in post_alloc_hook() (arch_alloc_page, KASAN,
> debug, page owner, etc.) use raw page pointers with explicit order
> counts and are unaffected by this reordering.
> 
> Note: compaction_alloc_noprof() has the opposite ordering
> (post_alloc_hook before prep_compound_page).  This is fine because
> compaction always passes USER_ADDR_NONE, so folio_zero_user() is
> never called there and folio_nr_pages() is never reached inside
> post_alloc_hook().
>

We can't really know that this will stay true forever, may as well
change the ordering there to prevent a tripping hazard.

Possibly you might want to just squash this change with the next patch
and add a comment that the ordering is now explicit and required that
way to be correct.

(possibly patches 4-5-6 should just be one patch, since it's all really
 the same change, but 4 seems fine by itself).

> Signed-off-by: Michael S. Tsirkin <[email protected]>
> Assisted-by: Claude:claude-opus-4-6
> Assisted-by: cursor-agent:GPT-5.4-xhigh

Reviewed-by: Gregory Price <[email protected]>

Reply via email to