From: Charles Haithcock <chaithco@redhat.com>
To: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org
Cc: Charles Haithcock <chaithco@redhat.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Respect mempolicy when calculating surplus huge pages.
Date: Wed, 27 May 2026 16:48:46 -0600 [thread overview]
Message-ID: <20260527224848.1753560-1-chaithco@redhat.com> (raw)
Presently, when calculating how many huge pages are needed when
reserving surplus huge pages, the global count of free huge pages
are used. When reserving with a mempolicy, the global count of free huge
pages is used even if some/all of those free huge pages are on numa
nodes outside of the mempolicy. Fix it so free huge pages only on nodes
within the mempolicy are considered.
Signed-off-by: Charles Haithcock <chaithco@redhat.com>
---
mm/hugetlb.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f24bf49be0..02752ce735 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2255,6 +2255,23 @@ static nodemask_t *policy_mbind_nodemask(gfp_t gfp)
return NULL;
}
+static unsigned int allowed_mems_nr(struct hstate *h)
+{
+ int node;
+ unsigned int nr = 0;
+ nodemask_t *mbind_nodemask;
+ unsigned int *array = h->free_huge_pages_node;
+ gfp_t gfp_mask = htlb_alloc_mask(h);
+
+ mbind_nodemask = policy_mbind_nodemask(gfp_mask);
+ for_each_node_mask(node, cpuset_current_mems_allowed) {
+ if (!mbind_nodemask || node_isset(node, *mbind_nodemask))
+ nr += array[node];
+ }
+
+ return nr;
+}
+
/*
* Increase the hugetlb pool such that it can accommodate a reservation
* of size 'delta'.
@@ -2277,7 +2294,7 @@ static int gather_surplus_pages(struct hstate *h, long delta)
alloc_nodemask = cpuset_current_mems_allowed;
lockdep_assert_held(&hugetlb_lock);
- needed = (h->resv_huge_pages + delta) - h->free_huge_pages;
+ needed = (h->resv_huge_pages + delta) - allowed_mems_nr(h);
if (needed <= 0) {
h->resv_huge_pages += delta;
return 0;
@@ -2312,7 +2329,7 @@ static int gather_surplus_pages(struct hstate *h, long delta)
*/
spin_lock_irq(&hugetlb_lock);
needed = (h->resv_huge_pages + delta) -
- (h->free_huge_pages + allocated);
+ (allowed_mems_nr(h) + allocated);
if (needed > 0) {
if (alloc_ok)
goto retry;
@@ -4513,23 +4530,6 @@ static int __init hugepage_alloc_threads_setup(char *s)
}
__setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup);
-static unsigned int allowed_mems_nr(struct hstate *h)
-{
- int node;
- unsigned int nr = 0;
- nodemask_t *mbind_nodemask;
- unsigned int *array = h->free_huge_pages_node;
- gfp_t gfp_mask = htlb_alloc_mask(h);
-
- mbind_nodemask = policy_mbind_nodemask(gfp_mask);
- for_each_node_mask(node, cpuset_current_mems_allowed) {
- if (!mbind_nodemask || node_isset(node, *mbind_nodemask))
- nr += array[node];
- }
-
- return nr;
-}
-
void hugetlb_report_meminfo(struct seq_file *m)
{
struct hstate *h;
--
2.54.0
next reply other threads:[~2026-05-27 22:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 22:48 Charles Haithcock [this message]
2026-05-30 3:35 ` Andrew Morton
2026-06-02 15:20 ` Joshua Hahn
[not found] <CAMcbwu5=TK_EjZ=wN5fqLC-DVUendE+CBWX0pN7KBF+1ZwD7Vw@mail.gmail.com>
2026-06-09 4:23 ` Joshua Hahn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260527224848.1753560-1-chaithco@redhat.com \
--to=chaithco@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®