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 6689818DB01 for ; Tue, 19 May 2026 00:19:49 +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=1779149989; cv=none; b=q8XJ4z4+/YSM7JTyPzwXz0ZDlUnzsu2KKvaQz/2zlgbKRDm+KBnQXZ15O2/kMKpFK3bMjAH4DDwyzm42X1gyYAKFEDUghkh6bj7+xUqrqrHZbf+DdXYCwEdv6ih/Ui8fKUUl6fpPAtqaZrRBEsL/guX6nS9QUglbNG1ZQXuoaoA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779149989; c=relaxed/simple; bh=DmF912XBXWSZg+goW1bFDdFsol5YVx4sSEtgnClKN1k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BRJr2cSK4MX9FbYUqDlRyeq9lRuvGe3/LDs2XxSv9l4OCVXRqIOCHLH26gpiG/ZKchSHcvseZMaiIdUYG8BES+rlz1Jpka25DiQyHy+d7KiqJ/GROfKqfTrFKyAn/DHAKr0v1k+lZNIgl7mi2R/hSHAbdIE1N6sdQJjZZapwixo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jog/QEL/; 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="jog/QEL/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1D870C2BCB8; Tue, 19 May 2026 00:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779149989; bh=DmF912XBXWSZg+goW1bFDdFsol5YVx4sSEtgnClKN1k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jog/QEL/Mtj6SyktShDjWR+b0urP8hq/27Yb3AHS8Brlshe7wjXWSa3/ycz7WSgiG oykV+LN7ZJhVY0ccWQqHKOaYH7XscLcMuYQ4HG20uf5MuNE2vvIhUHnwXCRwkkgOl8 t2JWwdqIETULelt/1jBzmvaaE8b7CYGztlflYUq0TCgJivFObhj2XqaMrDgNn2X2Tb A1LEt0gpYba+72tMtBqRzxieML8D/nr/32TBmbgiXEsh8tl5+uJH/2KS6nII27VjWN CCKYYFLot0sbpVldHGFWjoXP/AzFWT3zMDcPFn/mJKy+4kjuWfgTOdgxwbh5aAqzNt j0wAo1frEXKng== 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 08AF6CD343F; Tue, 19 May 2026 00:19:49 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Mon, 18 May 2026 17:19:40 -0700 Subject: [PATCH v3 1/6] 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: <20260518-hugetlb-open-up-v3-1-e14b302477f8@google.com> References: <20260518-hugetlb-open-up-v3-0-e14b302477f8@google.com> In-Reply-To: <20260518-hugetlb-open-up-v3-0-e14b302477f8@google.com> To: Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , fvdl@google.com, jiaqiyan@google.com, joshua.hahnjy@gmail.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, Zi Yan , Matthew Brost , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Dan Williams , Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ackerley Tng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779149988; l=2912; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=AePQ5ge08BDvno3Z2sz00AANV/evPZ/MLFYsGkJ3Hf0=; b=0skywfukH1jzfYFODEad/4ypPJF3H2kngkFerrbzsvccVY7o7T5yItuX2PowuUM77EcPbwDhF MwzZdmsTk/RBAMrVi2w8pIQySnBvDmHLk/qra4e6oRCSiyOsn5aDJ5F 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 | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f24bf49be047e..190ab539a97d4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1336,7 +1336,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; @@ -1344,13 +1344,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); @@ -1368,9 +1361,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) @@ -2939,12 +2929,17 @@ 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. + * gbl_chg == 0 indicates a reservation exists for the + * allocation, so try dequeuing a page. In case there was no + * reservation, try dequeuing a page if there are available + * pages in the global pool. */ - 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.54.0.563.g4f69b47b94-goog