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: Mon, 7 Apr 2025 11:35:27 +0200	[thread overview]
Message-ID: <Z_OcXymduxID6M5t@localhost.localdomain> (raw)
In-Reply-To: <18dde837-3fb0-43b0-5d02-f78948d68d77@huawei.com>

On Mon, Apr 07, 2025 at 03:23:08PM +0800, Jinjiang Tu wrote:
> 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);

I think this is ok, but this needs a big fat comment explaining why we
are doing what we are doing, because this us too subtle to grasp
without any context.

Like why it is ok not to subtract anything from persistent_huge_pages,
and the circumstances that might lead to this like that all free pages
are surplus because of hvo failing to restore and so we do not want
to account twice the same thing.

Actually, while you are at it, it would be great to rename variables and
give them a meaningful name (e.g: min_count and count).
That can be done in a follow-up patch of course.

The reason I am suggesting this is because it is not that easy to
untangle what is going on here, and have more meaningful names might
help.

Thanks


-- 
Oscar Salvador
SUSE Labs


  reply	other threads:[~2025-04-07  9:35 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
2025-04-07  9:35       ` Oscar Salvador [this message]
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_OcXymduxID6M5t@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