memblock: Initialized the memory of memblock.reserve to the MIGRATE_MOVABL
PATCH 1/1 memblock: Initialized the memory of memblock.reserve to the MIGRATE_MOVABL
After sparse_init function requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.
When CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set. The memmap_init function is called during the initialization of the free area of the zone, this function calls for_each_mem_pfn_range to initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set to MIGRATE_MOVABLE according to the alignment of pageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy's MIGRATE_MOVABL list for use.
When CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only the first_deferred_pfn range is initialized in memmap_init. The subsequent free_low_memory_core_early initializes all memblock.reserved memory but not MIGRATE_MOVABL. All memblock.memory is set to MIGRATE_MOVABL when it is placed in buddy via free_low_memory_core_early and deferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy's MIGRATE_UNMOVABL list (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB to MIGRATE_UNMOVABL). Since the huge page alloc requires a MIGRATE_MOVABL page, a fallback is performed to alloc memory from MIGRATE_UNMOVABL for MIGRATE_MOVABL.
Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to MIGRATE_MOVABLE in the free_low_memory_core_early phase following the alignment of pageblock_nr_pages.
Eg:
echo 500000 > /proc/sys/vm/nr_hugepages
cat /proc/pagetypeinfo
before:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…
Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0
Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…
Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0
--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/mm_init.c +6 -0
@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched (); + } + __init_single_page(pfn_to_page(pfn), pfn, zid, nid); }#else
Signature · 1 line
2.34.1
The main purpose of this patch is to unify the migration type settings for memblock.reserve to MIGRATE_MOVABL, both with and without CONFIG_DEFERRED_STRUCT_PAGE_INIT.
Thanks
suhua
Quoted 95 lines · suhua <[email protected]> 于2024年9月25日周三 19:02写道:
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3
4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202200 185 208 87 54 2 240
Node 0, zone Normal, type Reclaimable 2 2 1 23
13 1 2 1 0 1 0
Node 0, zone Normal, type HighAtomic 0 0 0 0
0 0 0 0 0 0 0
Node 0, zone Normal, type Isolate 0 0 0 0
0 0 0 0 0 0 0
Unmovable ≈ 15GBafter:
Free pages count per migrate type at order 0 1 2 3
4 5 6 7 8 9 10
…
Node 0, zone Normal, type Unmovable 0 1 1 0
0 0 0 1 1 1 0
Node 0, zone Normal, type Movable 1563 4107 1119 189
256 368 286 132 109 4 3841
Node 0, zone Normal, type Reclaimable 2 2 1 23
13 1 2 1 0 1 0
Node 0, zone Normal, type HighAtomic 0 0 0 0
0 0 0 0 0 0 0
Node 0, zone Normal, type Isolate 0 0 0 0
0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/mm_init.c +6
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid) if (zone_spans_pfn(zone, pfn)) break; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched (); + } +__init_single_page (pfn_to_page (pfn), pfn, zid, nid);}
#else
--
2.34.1
Mike Rapoport
maintainerQuoted 4 lines · suhua
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.
Quoted 10 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.
Please make sure you spell MIGRATE_MOVABLE and MIGRATE_UNMOVABLE correctly.
Quoted 50 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/mm_init.c +0
-0
mm/mm_init.c static void __meminit init_reserved_page(unsigned long pfn, int nid) · line 729
Quoted 8 lines
mm/mm_init.c +5
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched (); + }
If you are trying to make initialization of pageblock migrate type consistent with or without CONFIG_DEFERRED_STRUCT_PAGE_INIT, move setting of migrate type from deferred_free_pages() to deferred_init_pages().
Quoted 7 lines
mm/mm_init.c +1
-0+ __init_single_page(pfn_to_page(pfn), pfn, zid, nid); }#else Signature · 1 line
2.34.1
Signature · 2 lines
Sincerely yours, Mike.
Hi Mike
Thanks for your advice and sorry for taking so long to reply.
I looked at the logic again. deferred_init_pages is currently used to handle all (memory &&! reserved) area memblock,and put that memory in buddy.
Change it to also handle reserved memory may involve more code changes. I wonder if I can change the commit message: This patch is mainly to
make the migration type to MIGRATE_MOVABLE when the reserve type page is initialized, regardless of whether CONFIG_DEFERRED_STRUCT_PAGE_INIT is set or not?
When not set CONFIG_DEFERRED_STRUCT_PAGE_INIT, initializes memblock of reserve type to MIGRATE_MOVABLE by default at memmap_init initializes memory.
Sincerely yours,
Su
Quoted 93 lines · Mike Rapoport <[email protected]> 于2024年9月29日周日 17:18写道:
Quoted 4 lines · suhua
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.Quoted 10 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.Please make sure you spell
MIGRATE_MOVABLEandMIGRATE_UNMOVABLEcorrectly.Quoted 50 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/mm_init.c +0
-0mm/mm_init.c static void __meminit init_reserved_page(unsigned long pfn, int nid) · line 729
Quoted 8 lines
mm/mm_init.c +5
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched (); + }If you are trying to make initialization of pageblock migrate type consistent with or without
CONFIG_DEFERRED_STRUCT_PAGE_INIT, move setting of migrate type fromdeferred_free_pages()todeferred_init_pages().Quoted 7 lines
mm/mm_init.c +1
-1+ __init_single_page(pfn_to_page(pfn), pfn, zid, nid); }#else --2.34.1
--
Sincerely yours,
Mike.
Mike Rapoport
maintainerHi,
Quoted 3 lines · Su Hua
Hi Mike
Thanks for your advice and sorry for taking so long to reply.
Please don't top-post on the Linux kernel mailing lists
Quoted 10 lines
I looked at the logic again.
deferred_init_pagesis currently used to handle all (memory &&! reserved) area memblock,and put that memory in buddy.
Change it to also handle reserved memory may involve more code changes. I wonder if I can change the commit message: This patch is mainly to
make the migration type toMIGRATE_MOVABLEwhen the reserve type page is initialized, regardless of whetherCONFIG_DEFERRED_STRUCT_PAGE_INITis set or not?
Quoted 3 lines
When not set CONFIG_DEFERRED_STRUCT_PAGE_INIT, initializes memblock of reserve type to
MIGRATE_MOVABLEby default atmemmap_initinitializes memory.
This should be more clearly emphasized in the commit message.
Quoted 69 lines
Sincerely yours,
SuQuoted 64 lines · Mike Rapoport <[email protected]> 于2024年9月29日周日 17:18写道:
Quoted 4 lines · suhua
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.Quoted 10 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.Please make sure you spell
MIGRATE_MOVABLEandMIGRATE_UNMOVABLEcorrectly.Quoted 45 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
mm/mm_init.c +0
-0Quoted 8 lines
mm/mm_init.c static void __meminit init_reserved_page(unsigned long pfn, int nid) · line 728
Quoted 8 lines
mm/mm_init.c +4
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched ();
No need to call cond_resched() here
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
mm/mm_init.c +2
-1+ } + __init_single_page(pfn_to_page(pfn), pfn, zid, nid); }#else --2.34.1
--
Sincerely yours,
Mike.
Signature · 2 lines
Sincerely yours, Mike.
Quoted 8 lines
Hi,
Quoted 3 lines · Su Hua
Hi Mike
Thanks for your advice and sorry for taking so long to reply.
Please don't top-post on the Linux kernel mailing lists
Thank you for the correction.
Quoted 10 lines
Quoted 10 lines
I looked at the logic again.
deferred_init_pagesis currently used to handle all (memory &&! reserved) area memblock,and put that memory in buddy.
Change it to also handle reserved memory may involve more code changes. I wonder if I can change the commit message: This patch is mainly to
make the migration type toMIGRATE_MOVABLEwhen the reserve type page is initialized, regardless of whetherCONFIG_DEFERRED_STRUCT_PAGE_INITis set or not?
Quoted 5 lines
Quoted 3 lines
When not set CONFIG_DEFERRED_STRUCT_PAGE_INIT, initializes memblock of reserve type to
MIGRATE_MOVABLEby default atmemmap_initinitializes memory.This should be more clearly emphasized in the commit message.
Ok,I'll update the commit message.
Quoted 69 lines
Quoted 69 lines
Sincerely yours,
SuQuoted 64 lines · Mike Rapoport <[email protected]> 于2024年9月29日周日 17:18写道:
Quoted 4 lines · suhua
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.Quoted 10 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.Please make sure you spell
MIGRATE_MOVABLEandMIGRATE_UNMOVABLEcorrectly.Quoted 45 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
mm/mm_init.c +0
-0Quoted 8 lines
Quoted 8 lines
mm/mm_init.c static void __meminit init_reserved_page(unsigned long pfn, int nid) · line 728
Quoted 8 lines
mm/mm_init.c +4
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched ();No need to call
cond_resched()here
Alright, there isn't much reserved memory, I'll remove this function.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
mm/mm_init.c +2
-0+ } +__init_single_page (pfn_to_page (pfn), pfn, zid, nid); }#else
--
2.34.1
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
--
Sincerely yours,
Mike.
Sincerely yours,
Su
Quoted 126 lines · Mike Rapoport <[email protected]> 于2024年10月16日周三 20:01写道:
Hi,
Quoted 3 lines · Su Hua
Hi Mike
Thanks for your advice and sorry for taking so long to reply.
Please don't top-post on the Linux kernel mailing lists
Quoted 10 lines
I looked at the logic again.
deferred_init_pagesis currently used to handle all (memory &&! reserved) area memblock,and put that memory in buddy.
Change it to also handle reserved memory may involve more code changes. I wonder if I can change the commit message: This patch is mainly to
make the migration type toMIGRATE_MOVABLEwhen the reserve type page is initialized, regardless of whetherCONFIG_DEFERRED_STRUCT_PAGE_INITis set or not?Quoted 3 lines
When not set CONFIG_DEFERRED_STRUCT_PAGE_INIT, initializes memblock of reserve type to
MIGRATE_MOVABLEby default atmemmap_initinitializes memory.This should be more clearly emphasized in the commit message.
Quoted 69 lines
Sincerely yours,
SuQuoted 64 lines · Mike Rapoport <[email protected]> 于2024年9月29日周日 17:18写道:
Quoted 4 lines · suhua
After
sparse_initfunction requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved.Quoted 10 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INITis not set. Thememmap_initfunction is called during the initialization of the free area of the zone, this function callsfor_each_mem_pfn_rangeto initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set toMIGRATE_MOVABLEaccording to the alignment ofpageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy'sMIGRATE_MOVABLlist for use.Please make sure you spell
MIGRATE_MOVABLEandMIGRATE_UNMOVABLEcorrectly.Quoted 45 lines
When
CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only thefirst_deferred_pfnrange is initialized inmemmap_init. The subsequentfree_low_memory_core_earlyinitializes all memblock.reserved memory but notMIGRATE_MOVABL. All memblock.memory is set toMIGRATE_MOVABLwhen it is placed in buddy viafree_low_memory_core_earlyanddeferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy'sMIGRATE_UNMOVABLlist (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB toMIGRATE_UNMOVABL). Since the huge page alloc requires aMIGRATE_MOVABLpage, a fallback is performed to alloc memory fromMIGRATE_UNMOVABLforMIGRATE_MOVABL.Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to
MIGRATE_MOVABLEin thefree_low_memory_core_earlyphase following the alignment ofpageblock_nr_pages.Eg:
echo 500000 >/proc/sys/vm/nr_hugepages
cat/proc/pagetypeinfobefore:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Unmovable ≈ 15GB
after:
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
…Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0Signed-off-by suhua <[email protected]>--- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
mm/mm_init.c +0
-0Quoted 8 lines
mm/mm_init.c static void __meminit init_reserved_page(unsigned long pfn, int nid) · line 728
Quoted 8 lines
mm/mm_init.c +4
-0@@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid)if (zone_spans_pfn (zone, pfn))break ; } + +if (pageblock_aligned (pfn)) { +set_pageblock_migratetype (pfn_to_page (pfn),MIGRATE_MOVABLE ); +cond_resched ();No need to call
cond_resched()hereQuoted 9 lines
Quoted 9 lines
Quoted 8 lines
mm/mm_init.c +2
-1+ } + __init_single_page(pfn_to_page(pfn), pfn, zid, nid); }#else --2.34.1
Quoted 3 lines
Quoted 3 lines
--
Sincerely yours,
Mike.--
Sincerely yours,
Mike.