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 3B2123FB07F for ; Fri, 29 May 2026 15:23:08 +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=1780068190; cv=none; b=qNgapuIa0xL+gk3djkZU9ZC0rwklv7q6DX0jsQDeUEqp3LyaN1Dy8ZWWa1fb+7d516s6pccTJn1NBGuPPc5OZsTEY9hWbGduw4j5VyerQa6FoFEJ2dlDYVmCFk3YrOpeOvQAUoFJe1VeacwLp3RCAYaRWctgsBk7ww73CoQxxqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068190; 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=H1RtvFcJTZ7ss7XE76bai9jLeQLC5CeGsqH1D0h8kSxu6Ce+D3pGEiDbkEPhCQdRvnzr6mg5lyst1FZnglkvn2iFxA76t7+qJW8oKV8zt8BeJ+7SJIMx//TTdiEW0wWus4M3HQrhKSQKTcoCDpyltMvQ9+nrNIg3HoC+dH2vJ88= 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=QltAKcxg; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=oE6+avOD; 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="QltAKcxg"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="oE6+avOD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068187; 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=QltAKcxgNt533q1q+Z51wHw2Ewwn/ACeC98pd2X3JaM5jIGf6GruON3A3QEiBq95maRkb5 DAG9hzluSO3vN4i+zo9i57WdOqIWS6vH1z/ce3DBEGnLpPbJWlm1XY2v7uQbbXRzR6fU3J Nn4eMq5j10XqaeB1MP2Mjf6WGXCs4jQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-NLgZVBzINNid8R3D81hWHQ-1; Fri, 29 May 2026 11:23:05 -0400 X-MC-Unique: NLgZVBzINNid8R3D81hWHQ-1 X-Mimecast-MFC-AGG-ID: NLgZVBzINNid8R3D81hWHQ_1780068185 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-45aeac88af4so11159252f8f.3 for ; Fri, 29 May 2026 08:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068184; x=1780672984; 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=oE6+avOD4zOmVrEnQoMvxllZv62Y+qqtLiTfCM9FznkaBnRcgzOgzGSUgpWAD/jdfb c5IavWvu2stzxSsOplIu9kYcjhphJJz+qO0X0GDDkwpwvTA0MlsEL5nu8E+oWAVw41Zj llTZdqFfr7jyck3yR8jyzQLXwY71/kDZIcI4PSgNGcZwhcauhMizL29Bi5/9XjCcxXmT wfnpXc5uHCw4Kez2lkYAYtzA1Lk4Vaf4hCmjRytSKmlDj461t85CgywHfLTolckMuauf Nd7sTcFFO94ePjE/2C9L0TAJZHiFGYW+JUk9Xx/CiafnttNR8e3Jxhd/qulI35Tlhu8F bYKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068184; x=1780672984; 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=kybjyjCJaa4NMUrxpsWeRhLJrT+qM9Ny1tiLmkKYNP292MC7dH2WIY62/luAunbHy+ CRhhbMTF8nlVhF6/7czWFPCg64Cm1gZJUBjA87YGgBUmvkdcEuN0fzkwVaBAwsikU/YH etB+I9/tiWr3PKwQu4NAPuRMY0aRc0PpHgFh1sHSuwZNnyEnH5iEX1y44x5ZQk0B1Eh2 3LaOl/fpRk/f1ljAzgPG90A0dBqeEWzp7O6DNz/xvJopHJPKAdWurhkJ41Gqs3izLLyA QIc/eb3uRRHQSHmVZUER62aBcowJBAU0E63DKOkrcMRtqxE9EngHh/bgpcXfA1o0vG5v pglQ== X-Gm-Message-State: AOJu0YxVqB4JDsuCtQ2/3o7Fdo3g644Qd9pkqwiz5fjHDmMThY49K/qD tzqBJxns5/8cGi3Vk1bPaGe4DgrKQZ3Y5j1TIYiDbSpS3ZCtQb2yOs1ZRWKR3TGrj+YRK6VPfWc VIW6tycpfTKs7oMACA/w7TLL41GLRRjMrHF1qheSnmbHW9RhhVrFM9FClJixYELrWSCv4BAjO7G tCFXAlB+znapa3taZWRGnOdpK+BZPsz3eiR8SmKtsva3g= X-Gm-Gg: Acq92OEu69/CfmAmnOTohbQJSURlYtXEI8XygCu3+fzmEC8vhPijp8pwFwWhi7qkkFF 6cqdmawnVuNNU6Vu8b//j3qGF/pWwoSEY8iV/RtyiGg3y62Aa/KEmTJYuHFNyFI9Cw4f/ukuKa9 tsOEedhD/TCjcyYn6hvg0/kSBSGyHelECySw1uwkGwPtxYLzYChvs7wfPDZyuZd18nhGWF6oByS mkDfbwmjb8sxQT7hpsiLTtJmKFcQgcEm0UTmVniBFvJjq8PFeSgPPsGZzl+h2G9hejifqWaoTZy Svy7Soy6woHHRDasRDEV2+OE/H0TfK9LiNAKONVSbuxWMxQy96pF5STjK8XN73wSJztRBTcdoz/ M3DUr5rDLhJjb8slNh10kQIVw0SxN/Fqn05u5uHw0hlv/i1lXpv9GaA== X-Received: by 2002:a05:6000:1603:b0:45e:82b7:c260 with SMTP id ffacd0b85a97d-45ef6af7a60mr366103f8f.2.1780068184378; Fri, 29 May 2026 08:23:04 -0700 (PDT) X-Received: by 2002:a05:6000:1603:b0:45e:82b7:c260 with SMTP id ffacd0b85a97d-45ef6af7a60mr365980f8f.2.1780068183483; Fri, 29 May 2026 08:23:03 -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-45ef354c682sm3952557f8f.23.2026.05.29.08.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:23:02 -0700 (PDT) Date: Fri, 29 May 2026 11:22:58 -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 v9 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