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 DA2983976BB for ; Thu, 7 May 2026 22:22:44 +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=1778192567; cv=none; b=ky8DYyuFft2NZj9fxmMCSsCBpJRGwF2PulBr9qfyXc4fQj/hp4V9RvBYMP3dVkn1TMZmxarjrQRtvajNqHHi8Ds+f9Ov06GFk3kBxIH6SZDudMN4banKCaQn/hIXKGqZuAu7G9F94scqxa+BuHD1O9F2SPpmGAxQZ2CZCkLFX+Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778192567; c=relaxed/simple; bh=cYnvOSKzt3Z5LKY0YwQVyrVs2NSaHnVvr9KHUQESnbE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A91d+YFqYvKuDev4Iqkw4l8eG7rORftJFWyqYsfiEuPrfTQpYcORX1k97a+vH1hoanO6ue7MEz2MHlaWv7D+3eSZZ8W1Ll5V5wpE2Xih0uh7Pc4YS/5oFexUh7Sp1lM7KUmX4R3+p71iWvEmtfft9IlrXpSH/wUJPuc4Gn7gKRs= 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=AG+h8oWr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=b8A0HZal; 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="AG+h8oWr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="b8A0HZal" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778192563; 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=NawwnsjUX7qccisIUGIt5emibxZpAoP7nEpyB49cuUs=; b=AG+h8oWrwCGTaIb4/8rJjTbit3fAMyMwI6jd1OVlkRudVvcq7QYGJ0E/D8hZTAcSal+hGM fvK9yrmdhZdGPELH7pIPMOexTblgUJ19C304HMbfluAMpo0Q189pI985aKf4UBKFAipwcf fnzK+J0f+glexS9gY0xuyLWx2EquGCE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-oJPb8afqO6eSEGGsinJj6A-1; Thu, 07 May 2026 18:22:42 -0400 X-MC-Unique: oJPb8afqO6eSEGGsinJj6A-1 X-Mimecast-MFC-AGG-ID: oJPb8afqO6eSEGGsinJj6A_1778192561 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43d103e46c3so840143f8f.3 for ; Thu, 07 May 2026 15:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778192561; x=1778797361; 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=NawwnsjUX7qccisIUGIt5emibxZpAoP7nEpyB49cuUs=; b=b8A0HZalxYPlVNf0XFV/DAt4Of+MR3ADeYTHcH5iwaJ5TgvA9RXv7qBqzcl0U/WOf9 BX2qVWLRdPaxKTUUcJRHpe+2gFuSX2nbM4oGP8vdMDYTkTbMQDYOjL53ViiCdAEoL73q bkiGR4aV4bZyZBmhIxazyl77Rd6QM8VZZ2hXincKRmxX0mSpOUS18wsGNHP4VcYB/5W9 UKa28to386wVmiedeGrRo2dUHEpEcMzfUGhC8VU3gGwPEBmkUeoa4FNbdQC9WvXcCDmg t01ev9FgXnljrvqx/ko9E2tnLzUarXqskenMCwH4zTP9Ij7Uzhm9P2AN1lVR5gUiv1af s8VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778192561; x=1778797361; 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=NawwnsjUX7qccisIUGIt5emibxZpAoP7nEpyB49cuUs=; b=ES+WBmT8vueaYGbs+pi+AmjrbAJ1591u4vGJB9HEpJ1H9IjyIuyoGuOnDsS/3aNi1T +bLvETvhEPBwZyUZnFOIm6M1QOLWes9JpAPZy7FpUxGWln4fWzCJyvXh6V0Zrvx8hsxN tWO3mE1r12pT84sxqisPSgu7HpTOLZ0+dgA7siIHSRpzPhThAOaMmiSl6CKJAtRtKlhk WDqIxFNETpQ0tKI4rR4kIdq/0LpMasR19+OS/+jAwnS5Wmk55YFE6xWy4pxkQicHj6wG 0yutV1C38EIEYRusR2h3+rR5lQY0gpbQJoPJDN9P4eOIDRJSlhm/lBb5puwo5ycvWLqn 60OQ== X-Gm-Message-State: AOJu0YwSSqXb7xqsqWanV+k9Kc4m3hzCCFuWniwqdrGIb5rg+hr4cqnA h70SFsLwouODhGz8JlXf9Yla0vi7ZmECEatQH57Lo8uyHMAHwJKksADTZFSKdykEASKuj6WMPG4 F9EFkY6mPdo7+vRipYIsMEP3kH6zNrlvNDGMEoY//U8e9MvRv0+UfrfJv34/hMv13eRBqAot4VW Hi9ql7wKpEFStlvoJVn1PwosGzrfGTIRLGmaHyA/gigR8= X-Gm-Gg: AeBDieswAxNOU9HgViTm/vXGh+Q5gu7T/Ix7+CcvbKqBb3iqLKGDfY3AbRf7DaCM+2A Mp5IoYQkMcGm4ILV7qBnZGfxuqhC2X5DZ/0g6O97WjxG2AVpZYQ3u6Lkkb8I74rPSBqX7ZDa02T 6vv1yxDERgMv5loQ1q7iXa1yxM0J1uTw48uGU8pbWUdm7PmmxQ9nmvpEV2euwpeasnP0cMx+wgo R572U6aa6C7be7oXGTdhqesVuoL5kY86r9Sz8DWKrWHKFKYVYeme7QseoZtoeKmb+GFjW0v/KB8 e5Zx+kkG8bt127+54cahfcj6NT0JdA+8Gun6iyySsHBFmYnlkNuVaoJcv73U3nJ+7Z9dg6gmI3z E/6LRIdAQHqarPFtP3eb99hbeODzSvOrlhssLH/2H X-Received: by 2002:a05:600c:45c5:b0:48e:526e:1040 with SMTP id 5b1f17b1804b1-48e676b45eamr1526155e9.23.1778192561029; Thu, 07 May 2026 15:22:41 -0700 (PDT) X-Received: by 2002:a05:600c:45c5:b0:48e:526e:1040 with SMTP id 5b1f17b1804b1-48e676b45eamr1525695e9.23.1778192560371; Thu, 07 May 2026 15:22:40 -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-48e65c01d7bsm4569775e9.8.2026.05.07.15.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 15:22:39 -0700 (PDT) Date: Thu, 7 May 2026 18:22:37 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org Subject: [PATCH v5 04/28] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <249b45850d1c864563ba4415d55eeca9ef12dab9.1778192416.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. 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 c9efc07741b9..92640ddb0b7b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1895,11 +1895,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