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 E16BA3C1978 for ; Tue, 12 May 2026 21:05:59 +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=1778619961; cv=none; b=MV9nlxxy5h2L2kerDTnJA2gtYsm/LF3R7+UvPP6mSmKvZ++p5zVxwlZ1hdGJpDO35eRMdSUwUvXLBw27t1cXiqvhGEPvTmLOUaGac2cDU9BCnd5sCC5nTL8RNrQVm9HiVd8HHTlcWdouPARoLPa6mYkRzTlVCbY4Tq/Xf8QJuSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778619961; c=relaxed/simple; bh=qfAiB4Mi7HiE1t/8STINyzikxWNwc1bX9dNw7SeomIA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XBOWDRuaGLxlAFcvj78FZ66aynoHY5rpbqpqCZm2Av25cF9RJC2ZFJZ1Hil6iavKA+y+jzMQcpplJjc+lOrQoqQ1mi03m8UVwKDKB7XNnnOFFtiirYO0dGo0/pfkPyA3t9/xcA844urSkGuqH/FPgnND3av/pp+KEMWI+GnuJZI= 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=fySg5UL6; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=eaihUH2X; 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="fySg5UL6"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="eaihUH2X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778619959; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=fySg5UL6vojOnk+aa1XzN6fvMTUSNkduRlkS/1bRklLSImVwCNS6oYxCyUa0dgEF6njuVd GLAQWuKLpLJoc5wNfVokyVL4bdUdV5mKzKKMfQIrNrziOEkGb6grrmB28fQQAsBkMfNZbY Vu2a+Udwb8T5TuJ/KLbAgRDB9IhQq3I= 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-465-FVJlKSlfN6GeStOwvfVOmQ-1; Tue, 12 May 2026 17:05:56 -0400 X-MC-Unique: FVJlKSlfN6GeStOwvfVOmQ-1 X-Mimecast-MFC-AGG-ID: FVJlKSlfN6GeStOwvfVOmQ_1778619955 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48e6af7a9cdso31232535e9.3 for ; Tue, 12 May 2026 14:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778619955; x=1779224755; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=eaihUH2X1LdQvQm8PAKa2mWJ4ip9vVULjmpaXjtZNsNzC9MPl+DIB7e3KaiQFyY1kd 5M1ptfWuaEihU/LoMHO/5iLkibxZx8YGWuFAilNdH4A0+DGu2Vi3GGHqAbHorAprLDxM Y8Ivly7Fmcr3iv7cZRZ5xJm9jJ5BJ1SimRbcc+Lhi/JqO+/aHdYCLJhHY29MIjFN36Aj S1JudS5WCtFGBFT9OctXcsiUoAp0bJbD0ycGKSyF0BxZtp6Jqi2EQUpAe8pGWzAcC/CL wH733cLjw96XLMEDn1hZPh+NNDLuAnaEXEpug6w179ZUGIpBKzGynAQgUrAVf3DEjIRp W3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778619955; x=1779224755; 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=ScNqY6XGVTvavY3RuaxUGlH8VyMDuF0XI3V7nGekON0=; b=iN8o6X8oPD0xi1CU165DqDvZWXwgmrWT5hJit56tbm49UVYTVV5QS2sSdpkX7DOtG/ xNFj9jscdAL3CHEZsW0Y1+p4pCfKyGFDOGwnBaFNPJ7TGFdFpAf7fDmYVE5s1muTvBt/ zUnsHw7j2T2fogxPC9OowUNubwmSVStG53D8aqGbU0DYn18dvmbGglFJ+wVyqHaYlfw/ Ab+naw/Le1zf5MA9Tv4C+fO3M7Y2VjM/7uZ1EkzE1AdMPQKQKqgr4cqdXh1c2aqrgaUY fRWgm+x3Fi//jda4O0txc0CBFRpmxhYInYN/e4pfN8MutYH0YNPsGhnZrTRLdk9qzBTu Apww== X-Gm-Message-State: AOJu0YwVMSk0rlK33tySPfsxEhXYSJxNAHZrkJbGqiBnjY12GZFmhNH4 E74tNg/v1p1sdd7piI3/ucNALnkcnlGWxwhT1uIO1QvY6ZzqcWrqZqttqtscSF7TF9Ow3pz5Yik 0+jnZOv5Km0W2G9bzhHPee7rpzeTwtwEhJnR96e3EiAxVV7Ri46g34EMTL/WBEIzCgDlCvHr+Zf GWgcXAJYaHK3FDncicDrZRgDI9urIinh89feeda/1wUyA= X-Gm-Gg: Acq92OE5Ebgv37NsNlOd9hB84hEdO9pfGAMlXUVkR1aE5vdeaLYHfF1All14wMk2zsI hdH63bGEW65Hd9vLuBzw1n7sWsEC4zZO2HbL9GEykx0gd0HpEynWL0ADxQvO3dARoMEWm0z5XR7 pe7lVnoXynfYzjZKhkQUe3s6rI/sqKANsu/fWbMfvD79z2K8C0MXomzQCgZjIRSF+ls+tWjf3BI Y9X6NTj3mU6+E6A7epCY5rtOi+EccCIQL71/BEtDIeVXSBiYRB6voKQbnz+1TK0smdB9vkHX5Uc 0iJ79sMHqsmj2PyCRFTHzOeo0IZ2oa7mv08pc2FgcmUpNOsr4W39H6xWpbwoi89/GhbVjcyNwVd 0fzxb4JhEBba/YwaluiDNdyxMgOo9RUeYk7ywlegP X-Received: by 2002:a05:600c:8b56:b0:48a:599a:3716 with SMTP id 5b1f17b1804b1-48fc9a45891mr5020095e9.23.1778619954969; Tue, 12 May 2026 14:05:54 -0700 (PDT) X-Received: by 2002:a05:600c:8b56:b0:48a:599a:3716 with SMTP id 5b1f17b1804b1-48fc9a45891mr5019335e9.23.1778619954287; Tue, 12 May 2026 14:05:54 -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-48e8f429fdfsm24854985e9.15.2026.05.12.14.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:05:53 -0700 (PDT) Date: Tue, 12 May 2026 17:05:49 -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 v7 08/31] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <71a446816276ef01ce6dde104c4a44993c07e6e5.1778616612.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. 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 8c673095c11f..db387dd6b813 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