linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ge Yang <yangge1116@126.com>
To: David Hildenbrand <david@redhat.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, 21cnbao@gmail.com,
	baolin.wang@linux.alibaba.com, muchun.song@linux.dev,
	liuzixing@hygon.cn, Oscar Salvador <osalvador@suse.de>,
	Michal Hocko <mhocko@kernel.org>
Subject: Re: [PATCH] replace free hugepage folios after migration
Date: Sat, 21 Dec 2024 20:04:59 +0800	[thread overview]
Message-ID: <333e584c-2688-4a3f-bc1f-2e84d5215005@126.com> (raw)
In-Reply-To: <fe57ef80-bbdb-44dc-97d9-b390778430a4@redhat.com>



在 2024/12/21 0:30, David Hildenbrand 写道:
> On 20.12.24 09:56, Ge Yang wrote:
>>
>>
>> 在 2024/12/20 0:40, David Hildenbrand 写道:
>>> On 18.12.24 07:33, yangge1116@126.com wrote:
>>>> From: yangge <yangge1116@126.com>
>>>
>>> CCing Oscar, who worked on migrating these pages during memory offlining
>>> and alloc_contig_range().
>>>
>>>>
>>>> My machine has 4 NUMA nodes, each equipped with 32GB of memory. I
>>>> have configured each NUMA node with 16GB of CMA and 16GB of in-use
>>>> hugetlb pages. The allocation of contiguous memory via the
>>>> cma_alloc() function can fail probabilistically.
>>>>
>>>> The cma_alloc() function may fail if it sees an in-use hugetlb page
>>>> within the allocation range, even if that page has already been
>>>> migrated. When in-use hugetlb pages are migrated, they may simply
>>>> be released back into the free hugepage pool instead of being
>>>> returned to the buddy system. This can cause the
>>>> test_pages_isolated() function check to fail, ultimately leading
>>>> to the failure of the cma_alloc() function:
>>>> cma_alloc()
>>>>       __alloc_contig_migrate_range() // migrate in-use hugepage
>>>>       test_pages_isolated()
>>>>           __test_page_isolated_in_pageblock()
>>>>                PageBuddy(page) // check if the page is in buddy
>>>
>>> I thought this would be working as expected, at least we tested it with
>>> alloc_contig_range / virtio-mem a while ago.
>>>
>>> On the memory_offlining path, we migrate hugetlb folios, but also
>>> dissolve any remaining free folios even if it means that we will going
>>> below the requested number of hugetlb pages in our pool.
>>>
>>> During alloc_contig_range(), we only migrate them, to then free them up
>>> after migration.
>>>
>>> Under which circumstances doe sit apply that "they may simply be
>>> released back into the free hugepage pool instead of being returned to
>>> the buddy system"?
>>>
>>
>> After migration, in-use hugetlb pages are only released back to the
>> hugetlb pool and are not returned to the buddy system.
> 
> We had
> 
> commit ae37c7ff79f1f030e28ec76c46ee032f8fd07607
> Author: Oscar Salvador <osalvador@suse.de>
> Date:   Tue May 4 18:35:29 2021 -0700
> 
>      mm: make alloc_contig_range handle in-use hugetlb pages
>      alloc_contig_range() will fail if it finds a HugeTLB page within the
>      range, without a chance to handle them.  Since HugeTLB pages can be
>      migrated as any LRU or Movable page, it does not make sense to bail 
> out
>      without trying.  Enable the interface to recognize in-use HugeTLB 
> pages so
>      we can migrate them, and have much better chances to succeed the call.
> 
> 
> And I am trying to figure out if it never worked correctly, or if
> something changed that broke it.
> 
> 
> In start_isolate_page_range()->isolate_migratepages_block(), we do the
> 
>      ret = isolate_or_dissolve_huge_page(page, &cc->migratepages);
> 
> to add these folios to the cc->migratepages list.
> 
> In __alloc_contig_migrate_range(), we migrate the pages using 
> migrate_pages().
> 
> 
> After that, the src hugetlb folios should still be isolated? 
Yes.

But I'm
> getting
> confused when these pages get un-silated and putback to hugetlb/freed.
> 
If the migration is successful, call folio_putback_active_hugetlb to 
release the src hugetlb folios back to the free hugetlb pool.

trace:
unmap_and_move_huge_page
     folio_putback_active_hugetlb
         folio_put
             free_huge_folio

alloc_contig_range_noprof
     __alloc_contig_migrate_range
     if (test_pages_isolated())  //to determine if hugetlb pages in buddy
         isolate_freepages_range //grab isolated pages from freelists.
     else
         undo_isolate_page_range //undo isolate

> 
>>
>> The specific steps for reproduction are as follows:
>> 1,Reserve hugetlb pages. Some of these hugetlb pages are allocated
>> within the CMA area.
>> echo 10240 > /proc/sys/vm/nr_hugepages
>>
>> 2,To ensure that hugetlb pages are in an in-use state, we can use the
>> following command.
>> qemu-system-x86_64 \
>>     -mem-prealloc \
>>     -mem-path /dev/hugepage/ \
>>     ...
>>
>> 3,At this point, using cma_alloc() to allocate contiguous memory may
>> result in a probable failure.
>>
> 
> Will these free hugetlb folios become surplus pages? I would have assumed
> they get freed immediately to the buddy, or does you config maybe allow for
> surplus pages?
> 
These freed hugetlb folios will not become surplus pages. I have not 
configured the system to allow for the existence of surplus pages.




  reply	other threads:[~2024-12-21 12:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-18  6:33 yangge1116
2024-12-19 16:40 ` David Hildenbrand
2024-12-20  8:56   ` Ge Yang
2024-12-20 16:30     ` David Hildenbrand
2024-12-21 12:04       ` Ge Yang [this message]
2024-12-21 14:32         ` David Hildenbrand
2024-12-22 11:50           ` Ge Yang
2024-12-19 18:43 ` SeongJae Park
2024-12-20  9:03   ` Ge Yang
2024-12-21 14:35 ` David Hildenbrand
2024-12-22  8:13   ` Ge Yang
2025-01-08 21:05     ` David Hildenbrand
2025-01-09  9:50       ` Ge Yang

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=333e584c-2688-4a3f-bc1f-2e84d5215005@126.com \
    --to=yangge1116@126.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuzixing@hygon.cn \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=stable@vger.kernel.org \
    /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