From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6252B3FFF94 for ; Mon, 3 Aug 2026 13:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785764285; cv=none; b=A/88FJyDJr6UA28tl81DR9jRMOGyDSSQunsWb9g4koml0cbnCPUwBDleE2jepcGcHbA6+ANgYdAaxRo7ZZ0AChCtAnYwL1+b6VUzov9aUdUPanzR8ORn4sv2YynMRci1HAml5SOT7ZBw7kZPjMhazG21Sj+kXIyhvvmwDK+DVBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785764285; c=relaxed/simple; bh=40q8fHgrl8IDhLHqWUcb4B48rq7YY/FRZG1EdbUo6Zc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p5b5eKZC5qqOATFja2qyoZJ8K7fHrgSo5JRBFdLmTye2a7rjQtDItx/QB/Ux1EdNBoeNMbP8iqrTfna3softvrpKtUSgZgcww9ZvdVsglpJuCgioTt9TgBt6gzhdUoffdrMnwCyLTPWSucI4llwucp071TDG00BhafJ8C34GjzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QPbS+zgo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QPbS+zgo" Received: by smtp.kernel.org (Postfix) with ESMTPS id 08419C2BCF4; Mon, 3 Aug 2026 13:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1785764285; bh=40q8fHgrl8IDhLHqWUcb4B48rq7YY/FRZG1EdbUo6Zc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QPbS+zgodnxPQGiJyFIgllRtmV8vNj/3Tv0CUylyalZ7OTfpaFQalUVs7/mNJVPBt ZDYvZly8ujRRcUUep0N0JqorzhPF8vvyszaL0DP7sb6o1aryPLyKDGuk3fn8prDjZP tS50PHX7A65A9xmKtD19ZUHHlczQHbumFWx8gap+KuGyrxhe6pHyv0j0UMEAY9W1xr gxNKVKwKS4f+JKuS4mj22rRbyXKBgjQGG8MnXyvMd+diOhPSQnyxtzLthj4o6igH9R wlMEp4lkItzyEBxAkUYjqD7JR+ScQSl5SbK3MY8UmXsNrGQw/N6i5XhY+aOccfwo48 AYPk3pfBOvQwQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA435C55179; Mon, 3 Aug 2026 13:38:04 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Mon, 03 Aug 2026 06:37:58 -0700 Subject: [PATCH v5 1/3] mm: hugetlb: Consolidate interpretation of gbl_chg within alloc_hugetlb_folio() 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260803-hugetlb-mpol-interpretation-v5-1-af2b7089f8a9@google.com> References: <20260803-hugetlb-mpol-interpretation-v5-0-af2b7089f8a9@google.com> In-Reply-To: <20260803-hugetlb-mpol-interpretation-v5-0-af2b7089f8a9@google.com> To: Alistair Popple , Andrew Morton , Byungchul Park , David Hildenbrand , Gregory Price , Joshua Hahn , Matthew Brost , Muchun Song , Oscar Salvador , Rakie Kim , Ying Huang , Zi Yan , erdemaktas@google.com, fvdl@google.com, jiaqiyan@google.com, jthoughton@google.com, mhocko@kernel.org, michael.roth@amd.com, pasha.tatashin@soleen.com, pbonzini@redhat.com, peterx@redhat.com, pratyush@kernel.org, rick.p.edgecombe@intel.com, rientjes@google.com, roman.gushchin@linux.dev, seanjc@google.com, shakeel.butt@linux.dev, shivankg@amd.com, vannapurve@google.com, yan.y.zhao@intel.com, Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ackerley Tng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785764284; l=2991; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=rwfMlDQJWltPz5tqq1rs54f6f20kc49IZ7Zey0jTeJA=; b=2zSZQf9o6UpYJ9eX/dzPufzBYrXVNfD5XqllHda3DLhg9nu4sCYW4Poxxn/K+5QpGBoDsThlp LKnBnPTEUMdDj7Dri4sNbXQLoI9d8sPZXL/aAUEw2FfYdqAgMaCHYVy X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Endpoint-Received: by B4 Relay for ackerleytng@google.com/20260225 with auth_id=649 X-Original-From: Ackerley Tng Reply-To: ackerleytng@google.com From: Ackerley Tng The dequeue_hugetlb_folio_vma() function currently handles the gbl_chg parameter to determine if a folio can be dequeued based on global page availability. This leaks reservation-specific logic into the dequeueing path. Relocate this logic to alloc_hugetlb_folio() so that dequeue_hugetlb_folio_vma() focuses solely on selecting and dequeuing a folio. In alloc_hugetlb_folio(), only attempt to dequeue a folio if a reservation exists (gbl_chg == 0) or if there are available huge pages in the global pool. No functional change intended. Reviewed-by: James Houghton Acked-by: Oscar Salvador Reviewed-by: Joshua Hahn Signed-off-by: Ackerley Tng --- mm/hugetlb.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e93c4d2456aa4..7985cfd21a03c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1319,7 +1319,7 @@ static unsigned long available_huge_pages(struct hstate *h) static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, struct vm_area_struct *vma, - unsigned long address, long gbl_chg) + unsigned long address) { struct folio *folio = NULL; struct mempolicy *mpol; @@ -1327,13 +1327,6 @@ static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, nodemask_t *nodemask; int nid; - /* - * gbl_chg==1 means the allocation requires a new page that was not - * reserved before. Making sure there's at least one free page. - */ - if (gbl_chg && !available_huge_pages(h)) - goto err; - gfp_mask = htlb_alloc_mask(h); nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask); @@ -1351,9 +1344,6 @@ static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, mpol_cond_put(mpol); return folio; - -err: - return NULL; } #if defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE) && defined(CONFIG_CONTIG_ALLOC) @@ -2923,12 +2913,18 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, goto out_uncharge_cgroup_reservation; spin_lock_irq(&hugetlb_lock); + /* - * glb_chg is passed to indicate whether or not a page must be taken - * from the global free pool (global change). gbl_chg == 0 indicates - * a reservation exists for the allocation. + * Try to dequeue from the pool if either: + * 1) A reservation exists (gbl_chg == 0). + * 2) No reservation exists, but there are unreserved (available) + * pages in the pool; this prefers using pre-allocated pool + * pages over allocating fresh ones from the buddy allocator. */ - folio = dequeue_hugetlb_folio_vma(h, vma, addr, gbl_chg); + folio = NULL; + if (!gbl_chg || available_huge_pages(h)) + folio = dequeue_hugetlb_folio_vma(h, vma, addr); + if (!folio) { spin_unlock_irq(&hugetlb_lock); folio = alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr); -- 2.55.0.508.g3f0d502094-goog