linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: Jinjiang Tu <tujinjiang@huawei.com>
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: Fri, 4 Apr 2025 15:18:09 +0200	[thread overview]
Message-ID: <Z-_cES01qItUDs_r@localhost.localdomain> (raw)
In-Reply-To: <Z-6anMyttLDIMWLy@localhost.localdomain>

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?

 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;
 +	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);


-- 
Oscar Salvador
SUSE Labs


  reply	other threads:[~2025-04-04 13:18 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 [this message]
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
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=Z-_cES01qItUDs_r@localhost.localdomain \
    --to=osalvador@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=tujinjiang@huawei.com \
    --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