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 04D523C4547 for ; Mon, 11 May 2026 08:53:17 +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=1778489599; cv=none; b=uk9d7RuRI2FcAoHZ4dSm2Pt9puawGgPbOO+ctKAUHjQeLeSeWXQmxzfMBMLP697knPdfmfPQaG5akZvBOMFB+ZGP+QFvFzzPbgxh5OBMva9wGQLH0zbmkQ2IilDBKDXmOcrsKg02JsaZt6zFob4z9KGgsY4zydBVCZvDAYbXvj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778489599; c=relaxed/simple; bh=XgkToM0l5fC6A+WA27EumzbdOVH3Y/tvtIPE5N6fvlI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HkVV5DPxoR67eIz1UTyQcbkOg3Gm96nrlTY8n+WjgKleFvd6u5oRgM5ELRHkDLNwrIBUhPP9eLNTwhZwMtQ/cCvh2X1eAsWHoAP1uAfHG06/cKuviZ1LKMJsAq9HjKOJpKGo/gdga/Vdj4KKg5uWkWuoT1bXOtuoNRICakyNjtg= 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=XnQbMg9b; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QXMmam0s; 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="XnQbMg9b"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QXMmam0s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778489597; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=XnQbMg9bqrtvxS3i2W0eLzkSttvoFNLjVnG0fgxt0xNSDKwFb6byU5NUgfavxkgBgcmDwP I7pWgHBxgVw9WSvdAzFdjX4xEyzZzVQ3/uHvKJCkIucdUt939mdrUI6ML659Vz5j7FdcST 1xTzMlz2XaYfcIFeLAdmsQBRkrdJD6s= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-irk-tqVVMVWj-vI7rgc9vA-1; Mon, 11 May 2026 04:53:15 -0400 X-MC-Unique: irk-tqVVMVWj-vI7rgc9vA-1 X-Mimecast-MFC-AGG-ID: irk-tqVVMVWj-vI7rgc9vA_1778489594 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488d2cd2674so31591555e9.0 for ; Mon, 11 May 2026 01:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778489594; x=1779094394; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=QXMmam0svrC1/GYujtrm0cUVbWKrmgaEPntxySZQmdqxDmq/U63p/bBo3n+OIJEJ9z soFVgA0v8KeMBfQeDYLIChkJPBY0cWNiMTUP6ZSHqMbWVMY+ptQ4mjVE+pMmUssGFAl6 CrFrrnFNqiLeklk9eMf4jb8l2r+qzeKnHifHA6Z7P4QVSGF+c4TaMM8UBEX0haMVQZwl 7pfZh/Bf7jqavlI3Cax6yk7zR03OFycDgBw1o837/vDL1hvPTT5NixQflXfAPan1xP/Y ROb2O5YT9gj5pmM0/sWI25u/FDEQnqzwZV6JRsrgRGpg9K5Qph65Q4b0sV/NxmGbhnKl 0sLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778489594; x=1779094394; 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=Mz2Z32/qoGa6ei05M/PHSG1PfYksVkCsfkbIzcH2BdQ=; b=nK/GUV13zaBN6PoynU4fQNpEwfAAzxJN9/hKqEgfg3hG6uovI1J/S6KOgIhuBtQxM/ HpD2cgG6aUVyJzsJvhKOjVt0QOFqHLRzknM2RFkZc+7PQvY0DdYRm6c+A9avJyeRDIT9 y3Ln17Rh3Sb5RC30Af0dnPzzcDYjL23wCCUyR9x4qoCFZ6ZcISz+NXZ0v7iy48zSZaUr rB1RVoQ1QjgfzGUnl84NS4SZivmXhww/RnLP9VBQzz9Axs0BbovIX/XYwxAxsD7RbrVA En3hkgr+feI3+kUmPONsy8jvmFar80GjB7JMe4EwaX0yNsTV2mNlZRueVPrKvrqCvUno BcYQ== X-Gm-Message-State: AOJu0Yw/hb/XZpLBcJ7qwugljWQ4gL8PXGdnUk8/rD1brTiJisQz3QYN XTUqH5BXuC6yHVYSyneqJHf3reopaYxZ4EcjulOGvjxEsSTJ7YPNauYoLB2quyakkLSOVF8Jhnm osEaj29Vjch4VzzRgTIg0wlo5CVGyxRZc/m3A550rLq9lluLWYyrBF0HIKRO6nn2Q4MmQ+a1a6V 1U+OgVdoKEZXgNh1iMw81yvWid52X8Z2XGZ4gEYnY3okIsAQ== X-Gm-Gg: Acq92OFIDr86idYc7sF0fDlBHFOH+Yf6xtbuJREI8VSIJpHEuF4PQqTSoI7H7pAJjKJ n31PE4rNBF0HCxXL1nhk+cM3faH1yXZH0h26yyHqif8QnF8tc+7yk3kXsLeUnna8OxMDlZUB7FR u6mpecURbQufbhfPczJDK/LAeQ6lopApMpatfX9Sv2QWeveJnfaKEjBXzavUwEZK41fL+GnIKSA 7eX+5BzogrMEmZTvWYzXb4NfTnfxtgRirT7syPIAGs4m3xFgWSggKCEGqqW9zb2Wsi0JKZ0MwXA hyhKjZRuGz7RUJzpk6sC0pBLH8wbZTe+KY9iy6Xiq4YoBn1gx+CXZGvZyRAyTAYbgC85xSqKPUZ Va/E8emujfOtGWvbAUWohJeaLEd4mMBM3CsXXA1/T X-Received: by 2002:a05:600c:c094:b0:488:b14f:b8ed with SMTP id 5b1f17b1804b1-48e51dd89ffmr269713135e9.0.1778489594040; Mon, 11 May 2026 01:53:14 -0700 (PDT) X-Received: by 2002:a05:600c:c094:b0:488:b14f:b8ed with SMTP id 5b1f17b1804b1-48e51dd89ffmr269711995e9.0.1778489593191; Mon, 11 May 2026 01:53:13 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6fffba5fsm164913515e9.2.2026.05.11.01.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 01:53:12 -0700 (PDT) Date: Mon, 11 May 2026 04:53:08 -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 v6 05/30] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <6345727fdfa76157ba0518e2148d1848e0bdbc16.1778488966.git.mst@redhat.com> 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. 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(). Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c3c0f4e2baa7..f76d5271b5c6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1864,11 +1864,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