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 E33CC31A07F for ; Thu, 2 Jul 2026 16:21:51 +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=1783009312; cv=none; b=UTzAjb4X2l8bcQ8Lvm9G/eMvR6b2cqztWk57qf4cQ5zEq00Ei4GsxZ24XeRVOih6BUDl+rbpgfsy2/r7TS/Vu0LYhaB9qaGhdpFDm6FWi9D8fdH/d12+6R6X6dCelgpzat8DGRTFdvpwPLZPJDOMGfhFyUIHJgs0+lo1VRTEx3U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783009312; c=relaxed/simple; bh=JKUPHn+ON0y8hX9UPzvrdzLwxV2VFv9l2NWOLxBNkRA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hw1J8qE041dUappGTlOZVMXAoDMmxB6lup4PaHN/ga9uDZie06cf8IU1gSDDkBNfvfK7JoSsQQ9fUeolzmzLzJoOTHHf2iMu24kHFH59KaCRLlSqW5u2KBinc1DEhjXvIuErOqtWtC8JeDWYuf5N7uS3Htn+4+qnbC9jPr6ElJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ti7Mz9Ya; 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="ti7Mz9Ya" Received: by smtp.kernel.org (Postfix) with ESMTPS id ADD65C19425; Thu, 2 Jul 2026 16:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1783009311; bh=JKUPHn+ON0y8hX9UPzvrdzLwxV2VFv9l2NWOLxBNkRA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ti7Mz9YatsyoB/gfvjWedQa+6J5Hxlyo33saBqucZRsWKEPxe/Obkk8yr5CMougc2 q+vcvBkvkuXdpt7B38UN2by8QBhD06XX4usJ6+7HSiHzOHvUrTiABLWZaS6I/CEcdF wib+eDG1M3BtM7IQA3DtQw74K65Dkx1a8qtQpju6WRy9tiq3psx8t4khfc4l56p8PE J3AEfqNhFzzs86n+ndcj8vB+mquY1+BBLuYQ5YIdMM7C5o+HPj5FXCsn6xN0I3OVAe Kt3t/HDvjVqDQrlijG1Zpw5OmV1hbmwVBvqQeTt8URG4h/Q3+QKehMtwbU+Bd2kA9S Y28S9G2WtEiHA== 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 8C06DC43327; Thu, 2 Jul 2026 16:21:51 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Thu, 02 Jul 2026 09:21:45 -0700 Subject: [PATCH v4 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: <20260702-hugetlb-open-up-v4-1-d53cefcccf34@google.com> References: <20260702-hugetlb-open-up-v4-0-d53cefcccf34@google.com> In-Reply-To: <20260702-hugetlb-open-up-v4-0-d53cefcccf34@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=1783009310; l=2916; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=PQsyOzfX9+PQ8T9PPNJLY8Z3RoFea017nxtvG/bhOlo=; b=ChgTU8riHdeT6cYfFiotFgy9mfljKEFS6FjcjQLNC7hLvACp4afY2rgZ8Hl8xCz1NDqa98UCH k1PJBMRdBDPB9lflpwkwhYymknRTs1IAbUhBpowPwAojL1qAZy4YQg5 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 571212b80835e..83ab9390db565 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,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.55.0.rc0.799.gd6f94ed593-goog