From: Jinjiang Tu <tujinjiang@huawei.com>
To: Oscar Salvador <osalvador@suse.de>
Cc: <muchun.song@linux.dev>, <akpm@linux-foundation.org>,
<david@redhat.com>, <linux-mm@kvack.org>,
<wangkefeng.wang@huawei.com>
Subject: Re: [PATCH v2] mm/hugetlb: fix set_max_huge_pages() when there are surplus pages
Date: Mon, 7 Apr 2025 15:23:08 +0800 [thread overview]
Message-ID: <18dde837-3fb0-43b0-5d02-f78948d68d77@huawei.com> (raw)
In-Reply-To: <Z-_cES01qItUDs_r@localhost.localdomain>
在 2025/4/4 21:18, Oscar Salvador 写道:
> On Thu, Apr 03, 2025 at 04:26:36PM +0200, Oscar Salvador wrote:
>> Unfortunately, this will not fly.
> I did not spend much time, but solving the problem of hvo free pages
> becoming surplus not being accounted twice, should not the following
> fix the entire problem?
Sorry for late replay.
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 39f92aad7bd1..6e9534a825ed 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -3825,6 +3825,7 @@ static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed,
> static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
> nodemask_t *nodes_allowed)
> {
> + unsigned long substract;
> unsigned long min_count;
> unsigned long allocated;
> struct folio *folio;
> @@ -3960,7 +3961,12 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
> * and won't grow the pool anywhere else. Not until one of the
> * sysctls are changed, or the surplus pages go out of use.
> */
> - min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages;
> + if (h->free_huge_pages > persistent_huge_pages(h))
> + substract = h->free_huge_pages - h->surplus_huge_pages;
h->free_huge_pages may be less than h->surplus_huge_pages
> + else
> + h->free_huge_pages;
> +
> + min_count = h->resv_huge_pages + persistent_huge_pages(h) - substract;
> min_count = max(count, min_count);
> try_to_free_low(h, min_count, nodes_allowed);
>
I tries the following diff, and the problem is solved.
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 39f92aad7bd1..4afcd5ce417c 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3826,6 +3826,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
nodemask_t *nodes_allowed)
{
unsigned long min_count;
+ unsigned long persistent_free_count;
unsigned long allocated;
struct folio *folio;
LIST_HEAD(page_list);
@@ -3960,7 +3961,14 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
* and won't grow the pool anywhere else. Not until one of the
* sysctls are changed, or the surplus pages go out of use.
*/
- min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages;
+ persistent_free_count = h->free_huge_pages;
+ if (h->free_huge_pages > persistent_huge_pages(h)) {
+ if (h->free_huge_pages > h->surplus_huge_pages)
+ persistent_free_count -= h->surplus_huge_pages;
+ else
+ persistent_free_count = 0;
+ }
+ min_count = h->resv_huge_pages + persistent_huge_pages(h) - persistent_free_count;
min_count = max(count, min_count);
try_to_free_low(h, min_count, nodes_allowed);
Thanks for reviewing.
next prev parent reply other threads:[~2025-04-07 7:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 8:23 Jinjiang Tu
2025-04-03 3:49 ` Andrew Morton
2025-04-03 14:26 ` Oscar Salvador
2025-04-04 13:18 ` Oscar Salvador
2025-04-06 10:30 ` Oscar Salvador
2025-04-06 10:37 ` Oscar Salvador
2025-04-07 7:26 ` Jinjiang Tu
2025-04-07 7:23 ` Jinjiang Tu [this message]
2025-04-07 9:35 ` Oscar Salvador
2025-04-07 10:00 ` Oscar Salvador
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=18dde837-3fb0-43b0-5d02-f78948d68d77@huawei.com \
--to=tujinjiang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=wangkefeng.wang@huawei.com \
/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