在 2024/12/20 0:40, David Hildenbrand 写道:
On 18.12.24 07:33, yangge1116@xxxxxxx wrote:
From: yangge <yangge1116@xxxxxxx>
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.
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.