mm/page_alloc: Do not isolate redundant pageblock
Subsystems (2)
PATCH 1/1 mm/page_alloc: Do not isolate redundant pageblock
Current pageblock isolation logic could isolate each pageblock individually since commit d9dddbf55667 ("mm/page_alloc: prevent merging between isolated and other pageblocks"). So we not need to concern about page allocator merges buddies from different pageblocks and changes MIGRATE_ISOLATE to some other migration type.
--- mm/page_alloc.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
mm/page_alloc.c +8 -18
@@ -8313,16 +8313,14 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, }#ifdef CONFIG_CONTIG_ALLOC -static unsigned long pfn_max_align_down (unsigned long pfn) +static unsigned long pfn_align_down (unsigned long pfn) { - return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages) - 1); +return pfn & ~(pageblock_nr_pages -1 ); } -static unsigned long pfn_max_align_up (unsigned long pfn) +static unsigned long pfn_align_up (unsigned long pfn) { - return ALIGN(pfn, max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages)); +return ALIGN (pfn, pageblock_nr_pages); }/* [start, end) must belong to a single zone. */
@@ -8415,14 +8413,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,INIT_LIST_HEAD (&cc.migratepages);/* -* What we do here is we mark all pageblocks in range as -* MIGRATE_ISOLATE. Because pageblock and max order pages may -* have different sizes, and due to the way page allocator -* work, we align the range to biggest of the two pages so -* that page allocator won't try to merge buddies from -* different pageblocks and change MIGRATE_ISOLATE to some -* other migration type. -* * Once the pageblocks are marked as MIGRATE_ISOLATE, we * migrate the pages from an unaligned range (ie. pages that * we are interested in). This will put all the pages in
@@ -8438,8 +8428,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,* put back to page allocator so that buddy can use them. */ - ret =start_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype,0 ); + ret =start_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype,0 );if (ret)return ret;
@@ -8522,8 +8512,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); done: -undo_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype); +undo_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype);return ret; }EXPORT_SYMBOL (alloc_contig_range);
Signature · 1 line
2.11.0
Quoted 5 lines · Muchun Song
Current pageblock isolation logic could isolate each pageblock individually since commit
d9dddbf55667("mm/page_alloc: prevent merging between isolated and other pageblocks"). So we not need to concern about page allocator merges buddies from different pageblocks and changesMIGRATE_ISOLATEto some other migration type.
Yeah, that should be the case now.
Quoted 18 lines
Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)mm/page_alloc.c +1
-3@@ -8313,16 +8313,14 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, }#ifdef CONFIG_CONTIG_ALLOC -static unsigned long pfn_max_align_down (unsigned long pfn) +static unsigned long pfn_align_down (unsigned long pfn) { - return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages) - 1);
mm/page_alloc.c struct page *has_unmovable_pages(struct zone *zone, struct page *page, · line 8324
Quoted 10 lines
mm/page_alloc.c +3
-3+return pfn & ~(pageblock_nr_pages -1 ); } -static unsigned long pfn_max_align_up (unsigned long pfn) +static unsigned long pfn_align_up (unsigned long pfn) { - return ALIGN(pfn, max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages)); +return ALIGN (pfn, pageblock_nr_pages); }
How bout just removing these wrappers completely and using ALIGN and ALIGN_DOWN directly, as there are just two uses for each?
Quoted 39 lines
mm/page_alloc.c +4
-12/* [start, end) must belong to a single zone. */ @@ -8415,14 +8413,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,INIT_LIST_HEAD (&cc.migratepages);/* -* What we do here is we mark all pageblocks in range as -* MIGRATE_ISOLATE. Because pageblock and max order pages may -* have different sizes, and due to the way page allocator -* work, we align the range to biggest of the two pages so -* that page allocator won't try to merge buddies from -* different pageblocks and change MIGRATE_ISOLATE to some -* other migration type. -* * Once the pageblocks are marked as MIGRATE_ISOLATE, we * migrate the pages from an unaligned range (ie. pages that * we are interested in). This will put all the pages in @@ -8438,8 +8428,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,* put back to page allocator so that buddy can use them. */ - ret =start_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype,0 ); + ret =start_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype,0 );if (ret)return ret;@@ -8522,8 +8512,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); done: -undo_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype); +undo_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype);return ret; }EXPORT_SYMBOL (alloc_contig_range);
Quoted 31 lines · Vlastimil Babka
Quoted 5 lines · Muchun Song
Current pageblock isolation logic could isolate each pageblock individually since commit
d9dddbf55667("mm/page_alloc: prevent merging between isolated and other pageblocks"). So we not need to concern about page allocator merges buddies from different pageblocks and changesMIGRATE_ISOLATEto some other migration type.Yeah, that should be the case now.
Quoted 21 lines
Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)mm/page_alloc.c +2
-3@@ -8313,16 +8313,14 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, }#ifdef CONFIG_CONTIG_ALLOC -static unsigned long pfn_max_align_down (unsigned long pfn) +static unsigned long pfn_align_down (unsigned long pfn) { - return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages) - 1); +return pfn & ~(pageblock_nr_pages -1 ); }
Quoted 10 lines
mm/page_alloc.c struct page *has_unmovable_pages(struct zone *zone, struct page *page, · line 8324
Quoted 7 lines
mm/page_alloc.c +2
-3-static unsigned long pfn_max_align_up (unsigned long pfn) +static unsigned long pfn_align_up (unsigned long pfn) { - return ALIGN(pfn, max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages)); +return ALIGN (pfn, pageblock_nr_pages); }How bout just removing these wrappers completely and using ALIGN and
ALIGN_DOWNdirectly, as there are just two uses for each?
Sounds good to me. Will do.
Quoted 41 lines
Quoted 40 lines
mm/page_alloc.c +4
-12/* [start, end) must belong to a single zone. */ @@ -8415,14 +8413,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,INIT_LIST_HEAD (&cc.migratepages);/* -* What we do here is we mark all pageblocks in range as -* MIGRATE_ISOLATE. Because pageblock and max order pages may -* have different sizes, and due to the way page allocator -* work, we align the range to biggest of the two pages so -* that page allocator won't try to merge buddies from -* different pageblocks and change MIGRATE_ISOLATE to some -* other migration type. -* * Once the pageblocks are marked as MIGRATE_ISOLATE, we * migrate the pages from an unaligned range (ie. pages that * we are interested in). This will put all the pages in @@ -8438,8 +8428,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,* put back to page allocator so that buddy can use them. */ - ret =start_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype,0 ); + ret =start_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype,0 );if (ret)return ret;@@ -8522,8 +8512,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); done: -undo_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype); +undo_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype);return ret; }EXPORT_SYMBOL (alloc_contig_range);
Signature · 2 lines
Yours, Muchun
Quoted 64 lines · Muchun Song
Current pageblock isolation logic could isolate each pageblock individually since commit
d9dddbf55667("mm/page_alloc: prevent merging between isolated and other pageblocks"). So we not need to concern about page allocator merges buddies from different pageblocks and changesMIGRATE_ISOLATEto some other migration type.Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)mm/page_alloc.c +6
-16@@ -8313,16 +8313,14 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, }#ifdef CONFIG_CONTIG_ALLOC -static unsigned long pfn_max_align_down (unsigned long pfn) +static unsigned long pfn_align_down (unsigned long pfn) { - return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages) - 1); +return pfn & ~(pageblock_nr_pages -1 ); } -static unsigned long pfn_max_align_up (unsigned long pfn) +static unsigned long pfn_align_up (unsigned long pfn) { - return ALIGN(pfn, max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages)); +return ALIGN (pfn, pageblock_nr_pages); }/* [start, end) must belong to a single zone. */ @@ -8415,14 +8413,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,INIT_LIST_HEAD (&cc.migratepages);/* -* What we do here is we mark all pageblocks in range as -* MIGRATE_ISOLATE. Because pageblock and max order pages may -* have different sizes, and due to the way page allocator -* work, we align the range to biggest of the two pages so -* that page allocator won't try to merge buddies from -* different pageblocks and change MIGRATE_ISOLATE to some -* other migration type. -* * Once the pageblocks are marked as MIGRATE_ISOLATE, we * migrate the pages from an unaligned range (ie. pages that * we are interested in). This will put all the pages in @@ -8438,8 +8428,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,* put back to page allocator so that buddy can use them. */ - ret =start_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype,0 ); + ret =start_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype,0 );if (ret)return ret;
mm/page_alloc.c int alloc_contig_range(unsigned long start, unsigned long end, · line 8519
Quoted 10 lines
mm/page_alloc.c +2
-2@@ -8522,8 +8512,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); done: -undo_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype); +undo_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype);return ret; }EXPORT_SYMBOL (alloc_contig_range);
Last time I checked, set_migratetype_isolate()->has_unmovable_pages() was not prepared for that in case of !CMA and !ZONE_MOVABLE.
Assume you have an unmovable MAX_ORDER - 1 page that spans two pageblocks (e.g., x86-64). Assume you try to isolate the second pageblock. IIRC, you would answer "yes", as the refcount of all involved pages is 0.
How did you test this works as expected?
Signature · 3 lines
Thanks, David / dhildenb
Quoted 79 lines · David Hildenbrand
Quoted 64 lines · Muchun Song
Current pageblock isolation logic could isolate each pageblock individually since commit
d9dddbf55667("mm/page_alloc: prevent merging between isolated and other pageblocks"). So we not need to concern about page allocator merges buddies from different pageblocks and changesMIGRATE_ISOLATEto some other migration type.Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)mm/page_alloc.c +6
-16@@ -8313,16 +8313,14 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, }#ifdef CONFIG_CONTIG_ALLOC -static unsigned long pfn_max_align_down (unsigned long pfn) +static unsigned long pfn_align_down (unsigned long pfn) { - return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages) - 1); +return pfn & ~(pageblock_nr_pages -1 ); } -static unsigned long pfn_max_align_up (unsigned long pfn) +static unsigned long pfn_align_up (unsigned long pfn) { - return ALIGN(pfn, max_t(unsigned long, MAX_ORDER_NR_PAGES, - pageblock_nr_pages)); +return ALIGN (pfn, pageblock_nr_pages); }/* [start, end) must belong to a single zone. */ @@ -8415,14 +8413,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,INIT_LIST_HEAD (&cc.migratepages);/* -* What we do here is we mark all pageblocks in range as -* MIGRATE_ISOLATE. Because pageblock and max order pages may -* have different sizes, and due to the way page allocator -* work, we align the range to biggest of the two pages so -* that page allocator won't try to merge buddies from -* different pageblocks and change MIGRATE_ISOLATE to some -* other migration type. -* * Once the pageblocks are marked as MIGRATE_ISOLATE, we * migrate the pages from an unaligned range (ie. pages that * we are interested in). This will put all the pages in @@ -8438,8 +8428,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,* put back to page allocator so that buddy can use them. */ - ret =start_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype,0 ); + ret =start_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype,0 );if (ret)return ret;mm/page_alloc.c int alloc_contig_range(unsigned long start, unsigned long end, · line 8519
Quoted 10 lines
mm/page_alloc.c +2
-2@@ -8522,8 +8512,8 @@ int alloc_contig_range(unsigned long start, unsigned long end,free_contig_range (end, outer_end - end); done: -undo_isolate_page_range (pfn_max_align_down (start), -pfn_max_align_up (end), migratetype); +undo_isolate_page_range (pfn_align_down (start),pfn_align_up (end), + migratetype);return ret; }EXPORT_SYMBOL (alloc_contig_range);Last time I checked, set_migratetype_isolate()->has_unmovable_pages() was not prepared for that in case of !CMA and !ZONE_MOVABLE.
Quoted 8 lines
Assume you have an unmovable
MAX_ORDER- 1 page that spans two pageblocks (e.g., x86-64). Assume you try to isolate the second pageblock. IIRC, you would answer "yes", as the refcount of all involved pages is 0.How did you test this works as expected?
And I forgot to mention, in case it's a movable MAX_ORDER - 1 page (or simply free), would __alloc_contig_migrate_range() do the right thing and migrate the whole page?
Signature · 3 lines
Thanks, David / dhildenb