From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AB713BF66C for ; Wed, 20 May 2026 22:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315693; cv=none; b=H3ePQJArqYKh/3ezd0RbG08oIsOVrdob4nyecgtp6woeKqBoWavCTqhVDztCEEZ8qvXrjIQmQ2PhbnEjR4JKDte29cYPlxkO2dWaESjTBuF0BiT+dPBRq5iia3O0Xmv957lyUL+LIqu6yvzaA3PjSZMWk9psiYBmneVVR/v94F4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315693; c=relaxed/simple; bh=W8/RgV8YlHoI/N38IUKKZXJPftBVftzLE1J25cjwbi0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XNkqnUkBDrkRKGXj8EgUskxEXFCmz2M01LcFAiUJA1DXBQyiarTmcRu3FbnkHaBOV8+EatPRzSyJpLNcM9ra8eoA5OAfhVemdWluYZefN9TSaVu6FBl9ZB13UaN2fgiO+6rRlntg26a0w0VH5iW9zE1YdwgeyuNulN0jXAok0P0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=W10NeEB9; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iM0sKAUU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W10NeEB9"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iM0sKAUU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kjfty6vgLrS4T7uumYbV6HhVn6mEWZk8nuiVgC9VboM=; b=W10NeEB9XVrAaYPTBmsFf2gNs4cFmHHxMlYP1aoRQ6vlGgzF6f9RLwh3LY9PzNn4M9nGEH FOOlHj1P7Livlb3wGR3DUIPAlp9hqVkjUYNpNuCBAiA3iaf6JUMvnFn3XfdamPhABN0ZQ2 ndmbUQVtQDsRYSgeANF+M++1YducH0U= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-235-D0NsMJBvO1m6L36Q2uf-5A-1; Wed, 20 May 2026 18:21:30 -0400 X-MC-Unique: D0NsMJBvO1m6L36Q2uf-5A-1 X-Mimecast-MFC-AGG-ID: D0NsMJBvO1m6L36Q2uf-5A_1779315689 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48fde68e420so47682295e9.0 for ; Wed, 20 May 2026 15:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315689; x=1779920489; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kjfty6vgLrS4T7uumYbV6HhVn6mEWZk8nuiVgC9VboM=; b=iM0sKAUUJ0bRjmel8lGjCyw9Iypua1eWbmrXVHCYCBTS9yPfn9Ep9GsY5TfdWo7sUl ThoDx0jIhG1vnM/HU4zRRWDbsw2zW87C4sT3QH4twLi8zfBe8uSgHv3ztPDKY3hqb1Wa R65eA/os8TMB84EnSHJJZYsa4vJeYkbko3CUUGwCmk9lYk4m1qc3Qar5YJ+0U2zxDsdP SnzGy1I7tsZ4VuNVgz4edzICO7qEUeAk2irdZ53ZZvDmCf6FSQGXLPjGfdeCtaqo5vm+ HWdDadOaYqDfLlpS+gc0uisK+Eps4XZkiKG6tzfSom0LlK4rAxoJyoH1en57zFL35P0W 1Y6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315689; x=1779920489; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kjfty6vgLrS4T7uumYbV6HhVn6mEWZk8nuiVgC9VboM=; b=I5VDP0WgTOI5ptfFq1TTtDIblE/Bt0/o0ULyHNjebAPnuLXkG9/piFek2ppswkGAqZ pH4DKQbb+zdpSMnQds+WkGZ29f75QA7VSl1cHzIgN1tUzZlY8h8WGBSic1g+kl32Y8iE aqOt/wDgsxqCEv8A/ufxtQmogDg1HiTzoSFi2rvz3sYZJR2xIJ+XMtF8V6noQ1Q1RQpH Yj+1znyCkBFyJG/0LJOD40DIxD8i5+n1fJ+Nd9+8tzwv5LEoMePaK39g2CVdAuz3nWaO 6gP1DTemtCKdE4CKyQ4xDxQ01U5GnKRO918nYjh0Leml0PLxYwKp+TR1BDSw9IPpJA9g dRTg== X-Gm-Message-State: AOJu0YyKWluypIcCygIIlCVMWqyksFLGmdfy0F+d/2kmJxRIUnfSx1QJ vMEbfO0VKizjRdwTwXa2szwU0Rl+BpNthm1m0O4zk8RbqrdQ1I2rVvuuS40tq3nRhrqLCs8hpdw h67crser0TYw2i+m6n9zfM1ODEZJaNHr1jW3HCKBs90IcaqvLSh5MkZIPpRZNpDkNDwjYBjeOxU lBV/da1Ya5NsHO4ljFJQYOil+AAu0ulBMX1R76MepV/tc= X-Gm-Gg: Acq92OEFyw/e85gOVD98/A58bDsmRamxmFh0uD+y0v0lhwvFo4FYJm0u+SQC4175eSD LnwzI07VcqHUuVjI3xDjBYhqyQmcDUeXLF+Pf/JnB6YQy+mK661Qj1/LMb3FyZGe72CSXge1bNR zyi7YkaduiSwcVLK7juHZvMCKWTkr9XMj0rB94aBTqd9HUv6n2/aKVPnmGZ9C8IOg00KujyOWPm wzCoTnROJfqW85k/7s+ZVVsiZSljVmSlGZrhNFGmfTZZIe/ko+2X6H4rK8hP/UO8aTcgcBIHx21 1oBoc95vIErTUPr77NoSupQ7mwC1nsZyiBGSQhaBeaVZQPLNGXA1+KZbngS2T6Xs8zGRoVzb/a4 bm7BpZCgUjfBYr8EBDTzLa8JZg7NQHvXM8299nMhUY+4= X-Received: by 2002:a05:600c:5c8:b0:488:f453:b976 with SMTP id 5b1f17b1804b1-490360a9e24mr1510095e9.27.1779315688748; Wed, 20 May 2026 15:21:28 -0700 (PDT) X-Received: by 2002:a05:600c:5c8:b0:488:f453:b976 with SMTP id 5b1f17b1804b1-490360a9e24mr1509455e9.27.1779315688284; Wed, 20 May 2026 15:21:28 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da0fe0f72sm61409614f8f.25.2026.05.20.15.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:21:27 -0700 (PDT) Date: Wed, 20 May 2026 18:21:23 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: [PATCH v8 11/37] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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. Also reorder compaction_alloc_noprof() for consistency. Compaction currently passes USER_ADDR_NONE so folio_zero_user() is not called there, but keeping the same ordering avoids a future tripping hazard. Reviewed-by: Gregory Price Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/compaction.c | 4 ++-- mm/page_alloc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 72684fe81e83..4336e433c99b 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1849,10 +1849,10 @@ static struct folio *compaction_alloc_noprof(struct folio *src, unsigned long da set_page_private(&freepage[size], start_order); } dst = (struct folio *)freepage; - post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); - set_page_refcounted(&dst->page); if (order) prep_compound_page(&dst->page, order); + post_alloc_hook(&dst->page, order, __GFP_MOVABLE, USER_ADDR_NONE); + set_page_refcounted(&dst->page); cc->nr_freepages -= 1 << order; cc->nr_migratepages -= 1 << order; return page_rmappable_folio(&dst->page); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b725a3b59835..3108ac9061ce 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1877,11 +1877,11 @@ static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags unsigned int alloc_flags, unsigned long user_addr) { - post_alloc_hook(page, order, gfp_flags, user_addr); - if (order && (gfp_flags & __GFP_COMP)) prep_compound_page(page, order); + post_alloc_hook(page, order, gfp_flags, user_addr); + /* * page is set pfmemalloc when ALLOC_NO_WATERMARKS was necessary to * allocate the page. The expectation is that the caller is taking -- MST