linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Jinjiang Tu <tujinjiang@huawei.com>,
	akpm@linux-foundation.org, muchun.song@linux.dev,
	osalvador@suse.de
Cc: linux-mm@kvack.org, wangkefeng.wang@huawei.com, sunnanyong@huawei.com
Subject: Re: [PATCH] mm/hugetlb: fix surplus pages in dissolve_free_huge_page()
Date: Tue, 4 Mar 2025 11:15:56 +0100	[thread overview]
Message-ID: <a932a6dd-30b4-4a9e-b70d-cc20b82ad404@redhat.com> (raw)
In-Reply-To: <a1a70ef7-d97c-e4e2-0d76-a08cb222375d@huawei.com>

On 04.03.25 04:50, Jinjiang Tu wrote:
> 
> 在 2025/3/3 21:45, David Hildenbrand 写道:
>>> --- a/mm/hugetlb.c
>>> +++ b/mm/hugetlb.c
>>> @@ -2135,6 +2135,8 @@ int dissolve_free_hugetlb_folio(struct folio
>>> *folio)
>>>          if (!folio_ref_count(folio)) {
>>>            struct hstate *h = folio_hstate(folio);
>>> +        bool adjust_surplus = false;
>>> +
>>>            if (!available_huge_pages(h))
>>>                goto out;
>>>    @@ -2157,7 +2159,9 @@ int dissolve_free_hugetlb_folio(struct folio
>>> *folio)
>>>                goto retry;
>>>            }
>>>    -        remove_hugetlb_folio(h, folio, false);
>>> +        if (h->surplus_huge_pages_node[folio_nid(folio)])
>>> +            adjust_surplus = true;
>>
>> This change looks good to me
>>
>>> +        remove_hugetlb_folio(h, folio, adjust_surplus);
>>>            h->max_huge_pages--;
>>>            spin_unlock_irq(&hugetlb_lock);
>>>    @@ -2177,7 +2181,7 @@ int dissolve_free_hugetlb_folio(struct folio
>>> *folio)
>>>                rc = hugetlb_vmemmap_restore_folio(h, folio);
>>>                if (rc) {
>>>                    spin_lock_irq(&hugetlb_lock);
>>> -                add_hugetlb_folio(h, folio, false);
>>> +                add_hugetlb_folio(h, folio, adjust_surplus);
>>
>> I'm not quite sure here, though. We dropped the hugetlb_lock, can't
>> some weird concurrent action result in us not having to adjust surplus
>> page anymore?
> In this case, we will get a free surplus folio without reserved.
> 
> The existing code has similar logic. In free_huge_folio(),when
> h->surplus_huge_pages_node[nid] != 0,
> update_and_free_hugetlb_folio->__update_and_free_hugetlb_folio
> may fail due tohugetlb_vmemmap_restore_folio() too, and will treat it as
> surplus folio.

Right, in that scenario we'll even unconditionally treat it as a surplus 
page.

So I guess it's fine (and it's a corner case either way ...)

So with an improved patch description:

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



      reply	other threads:[~2025-03-04 10:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03  6:09 Jinjiang Tu
2025-03-03 10:25 ` David Hildenbrand
2025-03-03 11:16   ` Jinjiang Tu
2025-03-03 11:23     ` Jinjiang Tu
2025-03-03 11:47       ` David Hildenbrand
2025-03-03 12:10         ` Jinjiang Tu
2025-03-03 13:45 ` David Hildenbrand
2025-03-04  3:50   ` Jinjiang Tu
2025-03-04 10:15     ` David Hildenbrand [this message]

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=a932a6dd-30b4-4a9e-b70d-cc20b82ad404@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=sunnanyong@huawei.com \
    --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