From nobody Thu Apr 2 19:18:37 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3E11AC44D for ; Thu, 12 Feb 2026 00:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770856652; cv=none; b=US1v9VPZWbeNC6sEOCTlDs4TWhUtOIOXBjmUSuu0CIKciuOkMhSAAlQKbQLtBQLJXRetLGU24N3iz1pAGasy7rjfhMl5AC1khsEQYM/ygzBKsK7XAohjtg5yWO6XWaOcPt3ibZjhuq5LL9fSNiDf0otjCYJgmHrIBnQWxXAw11U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770856652; c=relaxed/simple; bh=WbOu/6e8uR8HBFqHpqlKdK3+FnhdgP20V84LWErdyq0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OqDkGlAjkXhbrGJd+F2ev9Qc9nXRKKSJtppgcbm94mYetDN/76JXsPXiFZ0VLcBLIqz0qbNmOpe1SJmP1d28k46tLfLtITA67KLdfIgMKtubmwUCY9LVIpRvA6hHbHjYJZz4t/qUtuYMXOO5ujHz35+eWoTZXbjFry6x8Wi0PsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QwALuDq4; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QwALuDq4" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-35301003062so16219921a91.2 for ; Wed, 11 Feb 2026 16:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770856650; x=1771461450; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7+fyXiA+m57FzuXOpgMoIQnVFz3nHsjbKsXBY1bNSP0=; b=QwALuDq4hDTWF4z2/mARw6VlkqVwFmhExhusQcQrJbZgXlo8xEVZh5M/OZ+CloAal9 w2ZNbDjQRyWTAYizFTFfEpzgWYLxWsRxIfdWcIkY1T5TTKEJPXgxZcgOOmy0lkG7iTDF VwmFQwDYgAVwioT/5waJIpN+TTFtt4xmyhVq2Uu75UHfNhnLsVTg8svOzY+S8m9Z7cdg w2UmaVDNmmMNTFRz2PEoQv5i7U9JOydqRj5FYHotYfnzkU92eaDMIm/ggFj/BMWy23rz EWaIDJsCHQOe0oFcK9j/sOduMBqzqanXdUS2cVCMDqv1WlOZo1HriFC71cRYa3ON3nbE BuSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770856650; x=1771461450; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7+fyXiA+m57FzuXOpgMoIQnVFz3nHsjbKsXBY1bNSP0=; b=O+VnTuRZqc/ZW+4a9yyEVgiviDTeUjrqsHtjFOy+Yxv0d7A32tOs8PrXjtFUOZiWvl ow+teHey3LQ+0A1J5xrNN+IUwa1CG4TE9mcpDzQCw1Ecp0IAzw7A2ybhhlph8bui4nZL phQXbvBl7VhqAENgKTHIjH5U49PpxNU8N/+EOkTeMxFtakigav0eli9uXKkXNYuFwDnc cL8jnENtptliko0e7XnKTL0OuLEU+FoU+0+ReCRmytvUE7/fKJ0AWjMS1Scy3/c95wBW olxy9bmsPE5M1nHdDzmx+uDf0TPd00ukFUGVbgihtMatOPdhIw0XheXUeJaExD+vP/nc Jptw== X-Forwarded-Encrypted: i=1; AJvYcCXLrkt1JqOabU7yut3/Q7P0qCanKFPep2CFTdMpjVdufGNxT5tsOs/gaOnr0xpIeL0UBBYC0syDZN1K6vk=@vger.kernel.org X-Gm-Message-State: AOJu0YwJcvmwhY1Wgt4WrN90VAeOWItrSDjT7P0tTSICxWp69VZsKzVp KQ1oxwXiYyvPg5WTt8XrKeX4LDlxin9f9FHr/G/VdyKaj6ECsFn8AOVF32eAX0gtfk8IpjM7ug0 03M3gHFT1YHY1Q3NvnDRHq3QYNQ== X-Received: from pjzr13.prod.google.com ([2002:a17:90b:50d:b0:33b:51fe:1a73]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e45:b0:32e:7bbc:bf13 with SMTP id 98e67ed59e1d1-3568f52e24amr904712a91.34.1770856649529; Wed, 11 Feb 2026 16:37:29 -0800 (PST) Date: Wed, 11 Feb 2026 16:37:13 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <18dbaf2ff9579b285d92f26b9a69e1e302f3bbcc.1770854662.git.ackerleytng@google.com> Subject: [RFC PATCH v1 2/7] mm: hugetlb: Move mpol interpretation out of alloc_buddy_hugetlb_folio_with_mpol() From: Ackerley Tng To: akpm@linux-foundation.org, dan.j.williams@intel.com, david@kernel.org, fvdl@google.com, hannes@cmpxchg.org, jgg@nvidia.com, jiaqiyan@google.com, jthoughton@google.com, kalyazin@amazon.com, mhocko@kernel.org, michael.roth@amd.com, muchun.song@linux.dev, osalvador@suse.de, 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 Cc: ackerleytng@google.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move memory policy interpretation out of alloc_buddy_hugetlb_folio_with_mpol() and into alloc_hugetlb_folio() to separate reading and interpretation of memory policy from actual allocation. This will later allow memory policy to be interpreted outside of the process of allocating a hugetlb folio entirely. This opens doors for other callers of the HugeTLB folio allocation function, such as guest_memfd, where memory may not always be mapped and hence may not have an associated vma. No functional change intended. Signed-off-by: Ackerley Tng Reviewed-by: James Houghton --- mm/hugetlb.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index fd067bd394ee0..aaa23d995b65c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2223,15 +2223,11 @@ static struct folio *alloc_migrate_hugetlb_folio(st= ruct hstate *h, gfp_t gfp_mas */ static struct folio *alloc_buddy_hugetlb_folio_with_mpol(struct hstate *h, - struct vm_area_struct *vma, unsigned long addr) + struct mempolicy *mpol, int nid, nodemask_t *nodemask) { struct folio *folio =3D NULL; - struct mempolicy *mpol; gfp_t gfp_mask =3D htlb_alloc_mask(h); - int nid; - nodemask_t *nodemask; =20 - nid =3D huge_node(vma, addr, gfp_mask, &mpol, &nodemask); if (mpol_is_preferred_many(mpol)) { gfp_t gfp =3D gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); =20 @@ -2243,7 +2239,7 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(str= uct hstate *h, =20 if (!folio) folio =3D alloc_surplus_hugetlb_folio(h, gfp_mask, nid, nodemask); - mpol_cond_put(mpol); + return folio; } =20 @@ -2892,7 +2888,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, map_chg_state map_chg; int ret, idx; struct hugetlb_cgroup *h_cg =3D NULL; - gfp_t gfp =3D htlb_alloc_mask(h) | __GFP_RETRY_MAYFAIL; + gfp_t gfp =3D htlb_alloc_mask(h); =20 idx =3D hstate_index(h); =20 @@ -2963,8 +2959,14 @@ struct folio *alloc_hugetlb_folio(struct vm_area_str= uct *vma, folio =3D dequeue_hugetlb_folio_vma(h, vma, addr); =20 if (!folio) { + struct mempolicy *mpol; + nodemask_t *nodemask; + int nid; + spin_unlock_irq(&hugetlb_lock); - folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr); + nid =3D huge_node(vma, addr, gfp, &mpol, &nodemask); + folio =3D alloc_buddy_hugetlb_folio_with_mpol(h, mpol, nid, nodemask); + mpol_cond_put(mpol); if (!folio) goto out_uncharge_cgroup; spin_lock_irq(&hugetlb_lock); @@ -3023,7 +3025,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_stru= ct *vma, } } =20 - ret =3D mem_cgroup_charge_hugetlb(folio, gfp); + ret =3D mem_cgroup_charge_hugetlb(folio, gfp | __GFP_RETRY_MAYFAIL); /* * Unconditionally increment NR_HUGETLB here. If it turns out that * mem_cgroup_charge_hugetlb failed, then immediately free the page and --=20 2.53.0.310.g728cabbaf7-goog