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 3942B3C060F for ; Mon, 11 May 2026 09:02: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=1778490138; cv=none; b=FOIAM1VeP9whOy4gmqq8vqXYvZ/TKMYo/eVG181mWaZySIEtRtXktnjCUeK0F+p4B+T+Ebi05rFKe18WTNm3NFxQq9QFbDTNJ2aXAAg4DL0v0tSK233PvJueRmwfWDtvszVNK0Hvdc2VbMSzncWMm0BRLlgeKRMP/Da1cVgxfpw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490138; 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=qSXLaOvO5NIoWm+bw0cRnN7YyIgprjWoxUptMIr8HNSdSnQIu9pOWdsg9GPBZp390wqfB7RECQgCVeAAqK6AbPdEk7YArqe9imZgVehHRFv8FkOBN41PNnPXHCAG5ah/p/DtoE3+jDdSg5o1xl4/ppI0WIArjAZGNk4igUN2fk4= 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=ggzYbS77; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=On01t3NH; 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="ggzYbS77"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="On01t3NH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490136; 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=ggzYbS77R7NMdRsdBQcTxVQZ5nG0Sxdz1bOjiAfjM7jh9K3YALZA53i6gUcwSlk7XAOG57 LY9TKJ55RMhSh4zRBqMEBMb9RBfrKfUOsmG6BDWzqOpaxalEIPOf+082VQzi395dmuwKD0 Vjv/7stxV1qe09r70FSphdudrqVmewM= 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-556-Px4nlpIUNnqhfp4-eqIw5g-1; Mon, 11 May 2026 05:02:15 -0400 X-MC-Unique: Px4nlpIUNnqhfp4-eqIw5g-1 X-Mimecast-MFC-AGG-ID: Px4nlpIUNnqhfp4-eqIw5g_1778490134 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43ff19e54beso2869338f8f.2 for ; Mon, 11 May 2026 02:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490134; x=1779094934; 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=On01t3NHEdwNkT+rv5qtZY/QYXZhTk9hqMDoYa79V9TAES/qCtZ0lWu+y1SaJjH4e1 gZBnGUVBYa5Zla1vj/hPFTR4Iiz05y2DlZHHM6ZvRIqPJpvmS7+2i+Vi2wAIXQJjYi3m Hy8LSDD26oBWyT2nOA4ZH5MtFSdXGyj5X3IdOAVvJ1EfXejXT3cN9oBqadW7TPITwbGP h7OQcASwM/5iC2awI1JZpHGpIq3mwLBW59Z/ynqI1QA7CzwNUK1el99UlAf6wxca1ZA4 N1ScfwOPFG0hprd7nm6228KRy0M2WyL/EHGdaNqGDDe8+uFtAPONfmO16FbvTEc3VpXk 69Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490134; x=1779094934; 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=UPSKwdLlAQWJv/9022T9IQ3XgOPtT6AugN5GmFQ6HmggkQI+TrOFt1MM7Cs6DwOSPY 2fLQi8zkHOypP1FbqhTRLRrHr5ohvSpfCMZ4dT4OCXzQSfFwRfxXJmJqE+g8z6HgVa7E pw0EdmAzx8ZcLQzTLbOziKiEyzsasdJlaz6J8Hu7OkySjCNuTg7AC8sREb0QR2cG/I6q d694zfV7h1aAXeXlx++v4YGt22sTEc4UaD8G6mUtzaNAeXma+1hk4q1oFaXuvJqE5vfg h000iIEtCsGu5RcquvLQxHtQGOskcOnuB9CGd8g92kQAjO5CZY4RlYj97S4hIlGdombD A/NA== X-Gm-Message-State: AOJu0YySH6ekBQEETGm14PrahxKP2NazP+gttLhqYBpMOX4OmK1cgp4q Ko1BvW81YsQfCbWGQNcpj7YD9SIykRg16IbhKhQuZ8tR7AE87k/FNkxbVLcsiXLn8Xi3fLVz9W6 KGQ1jHBzvn4HEiqoM4owTATb9wMcWqqHXZnqTaG6wSDVFo+CXeMSeLgyqOPSFRpWsPJqUyGWdL0 1xLXgHRgdEOD+5HAPlu/1PTHoUf0QacDQU6BrW9H72TQ/nig== X-Gm-Gg: Acq92OFlwL6yXs/zs83yMN13LoCmB0rikHIxnSZAcvD/4YhGwqm8hSKIFPsmKFEV/N8 bLimOWQcNEqdpKavY9uL/ioaHiL0M2odzr76bn9eEigqYTkc5DE27ylu+NcLr/SYLZDKk+mA5bP NYv9zRmYuC40h6996pwGMVVLjTmjFB7Kq2ENtw9Hvf+sKz4GK1B1p/yFLBsXySX5c4mtpViU60j 2L9EKkCcjMbnd3h1WU1K96CpzsSMxy/bVUpZ6YJZquJGPdnfTXtTbY4enfNGBvy52HLPFE+Nb9f 3iXvO4ImaP4E0XYl9Dcca/1iRpP+F1C+pZflxF82wtXbYWABa70XF3ZOFFSSTjEw4nipxtAdXVp wdylH1/q/kxad+jH/2YHvZvGK3s2pT+VDMb/zO4ED X-Received: by 2002:a05:6000:2502:b0:43f:dd40:bbc8 with SMTP id ffacd0b85a97d-45462c341d9mr21397121f8f.24.1778490133582; Mon, 11 May 2026 02:02:13 -0700 (PDT) X-Received: by 2002:a05:6000:2502:b0:43f:dd40:bbc8 with SMTP id ffacd0b85a97d-45462c341d9mr21396993f8f.24.1778490132555; Mon, 11 May 2026 02:02:12 -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 ffacd0b85a97d-4548e6a6a64sm25368230f8f.6.2026.05.11.02.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:02:12 -0700 (PDT) Date: Mon, 11 May 2026 05:02:06 -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 resend v6 05/30] mm: page_alloc: move prep_compound_page before post_alloc_hook Message-ID: <6345727fdfa76157ba0518e2148d1848e0bdbc16.1778489843.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