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.133.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 353DD3AFD0B for ; Mon, 8 Jun 2026 08:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907809; cv=none; b=P4IP60Aqdp1VmB5Xk6xywsLCoZ2dhNiPIJTC9UNq3JhU6D6iNoyGkaZppjl/vPrQE2mchCgqxJudegy0H3uGQq7iQN7opN6KOdL3dUJquhCBRUfg5yEsnb/kb+PtKzu0zEZC6d0isFtAXUW5+QRlF10TgPhcRuGdh7VVdvPd0fE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907809; c=relaxed/simple; bh=pjwppoBrYRW1HQas7rkHTtLdWmdFN3pMjiX+S9iYC1E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H5IkR0AJRT43bUmkzmGzAZw5PKROcHsunxWvly1YzE7Jst8MkUSXziNnsD+5JzW+8Zxjji1oW2Qdhja1K8wWrBoXQW/M2muehVZcgpOpgdV0xayZAvH9psKWVFVy85Cxo+GtPfb/2Pz25CXbYo17JxvjwKNOmkSIRDL8JpaPW+4= 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=BrPXVh5+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=HUG1KOYJ; arc=none smtp.client-ip=170.10.133.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="BrPXVh5+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="HUG1KOYJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780907801; 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=8KJh4wvwDWohkhm2jB8sA/e6an56FCy42Cqcxiv2qXU=; b=BrPXVh5++1SufKZI3QM6wBBC7NGV+qEC1gUNq5R8H0u+jrik8DLCrVirFTf5u8QZvarCL4 Aiu13G93ZS+q4439E+5IyC7oYcobfKTMwWK6FAgT7x7noMebgnnrjgzj1RE/9mOaiAzC5e 4OvdjGPRJDv2eS2FYweG94rNGOsLZ0Y= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-402-7umxmQt0MeWi2pGOXe9qSw-1; Mon, 08 Jun 2026 04:36:39 -0400 X-MC-Unique: 7umxmQt0MeWi2pGOXe9qSw-1 X-Mimecast-MFC-AGG-ID: 7umxmQt0MeWi2pGOXe9qSw_1780907799 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-46010392f89so3680385f8f.2 for ; Mon, 08 Jun 2026 01:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780907799; x=1781512599; 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=8KJh4wvwDWohkhm2jB8sA/e6an56FCy42Cqcxiv2qXU=; b=HUG1KOYJ8D4JjZWJ3SkiN3iUEivraz/eTHDDITvdsDfcoiy6GS1dH0u3uvLuaJvefm C6Ib7GGTwdAUxGchy3bpPm2capcm+vGFGMLbNTdl7o1fVwyRFm6khO40u41fslkx2eih LMN5wAPfqfA0BM8odizP6OvLRklmh2f9r9mJTQ4Ubcd80j1mtfY4IMRzgBhZvCQZwk8K yVG4UKnMirK1XXyubwdsF2lhzjQJTpmovfjDsUetDHYy0iOSq53hkRGDc/oCZih5Q3O4 ROhBcbDGhk1yWWeB3L7Jsu/sXkaYS+c5tfTsIAp1FOATcyRSszK0fFnvh/IDxIQMBRZW 4tUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780907799; x=1781512599; 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=8KJh4wvwDWohkhm2jB8sA/e6an56FCy42Cqcxiv2qXU=; b=Onv9KBZBQA2Q7jOFCWNhxmuJP0b5tVZpYKRw6daaPRIJUmIuzjCzeICAcLk9qRKDtc Eb4dE93qVxykw1TvpJl6nRv8ylR7BSCbulqQM8yA1lxM2Bhr/EzPy3/wqjHeU5L5iDNM /mA9FPQKKPNBoqf7s52m6rtdy8eP5bDsTcFn4E/RMjFhHHJMrIa8ZSU8xwHEtrk9S8U3 3w0YuGxZc6DSretQT2WcDEFi1D4egGdBAmapskhGskUM6oluqKqQZs90o9KXFK6pQ3Zt DK97p2jWVNDZSuIZlCX33bo1G0yqpMpECSYL4PXFFzJjTKJBLXZVAfiPv7UIaeUkcCkb hwZQ== X-Gm-Message-State: AOJu0Yyxet+z1fZBhMfbptEoO9YgoBvb3Pqry940DkjQrwN4gqOZlGDT 1lkyoXB3YaBIz+h0G2IvYf3UMlGtwrRlTM2Xpfqw72axAam9ctzHNo5+e8ypmBCZhJlB871dFgM shZ2bzsDupFAnOvqKW3YdqSpyxZFhcLacVlPV3cRoS8yYrcFrIohUy0c6LQFJl+E2FN8kGngS2g bX/RryCgzzX+fJlgvCWedqoMfLcM1G8ZU+R94lD0bbWJo= X-Gm-Gg: Acq92OGNQQvXhFSIY23sMYBItrUEHu1qIKivk0OObpVA1CNzpsfLh1j+HJMmGfCOfYZ Lf+Icf3w7eU7TmfnBF0YaApNCItctAJZZ2Vi7FFjzF7sS6YmrBHO9TV3OQ4EFWZ/pxmtSr/mAZi VAwFSolIHUhzYJRi2xyE8zDCU9mfUrBkObbxiMLQvdHu6e4SMJR80I14945HBMVoHvXmDBbwZxr VTyV33yG4RqfcJYXK5ozVnQMCrTSw0K4/Da6k0cfhUGKMv/y1F8b551KVzWajCH5S4so5cgs4vb fz29Pod1Jm/gaJjK6OUwOsyjQz06GvSdslNUeBcSu1E38f711o1ZvLIfIpfR680Kj1RSw0EAaxz dmjj0yH6Xa4VUJPUdakSOI1Y= X-Received: by 2002:a5d:658c:0:b0:45d:7bf0:c7d3 with SMTP id ffacd0b85a97d-46030643aa6mr15913854f8f.19.1780907798531; Mon, 08 Jun 2026 01:36:38 -0700 (PDT) X-Received: by 2002:a5d:658c:0:b0:45d:7bf0:c7d3 with SMTP id ffacd0b85a97d-46030643aa6mr15913766f8f.19.1780907797944; Mon, 08 Jun 2026 01:36:37 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f0a43e9sm50455796f8f.0.2026.06.08.01.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:36:37 -0700 (PDT) Date: Mon, 8 Jun 2026 04:36:20 -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 v10 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.51.2.2891.g4157995a80.dirty 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 0943ab724032..4676fd49819e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1874,11 +1874,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