Skip to contentSkip to conversation

mm/compaction: fix low_pfn advance on isolating hugetlb

PATCH Applied Wei Yang 5 participants 22 messages Sep 10, 2025 – Sep 23, 2025

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/compaction: fix low_pfn advance on isolating hugetlb

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
---
 mm/compaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +1 -1
index bf021b31c7ec..1e8f8eca318c 100644
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;
 				goto isolate_success_no_list;
 			}
 
Signature · 1 line
2.34.1
author
#1 lore raw
Quoted 15 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Quoted 6 lines

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Quoted 9 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

Quoted 5 lines
mm/compaction.c +0 -0
 				goto isolate_success_no_list;
 			}
 
Signature · 1 line
2.34.1
Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#2 lore raw
Quoted 18 lines · Wei Yang
Quoted 17 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Quoted 8 lines
Quoted 4 lines
Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 10 lines
Quoted 6 lines
mm/compaction.c +0 -0
 				goto isolate_success_no_list;
 			}
 
Signature · 1 line
2.34.1
Signature · 2 lines
Wei Yang
Help you, Help me

Best Regards,
Yan, Zi

reviewer
#3 lore raw
Quoted 50 lines · Zi Yan
Quoted 18 lines · Wei Yang
Quoted 17 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Quoted 8 lines
Quoted 4 lines
Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Best Regards,
Yan, Zi

reviewer
#4 lore raw
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

+ if (PageHuge(page) && cc->alloc_contig) {
+ ret = isolate_or_dissolve_huge_page(page);
+
+ /*

+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */

+ if (ret < 0) {
+ /* Do not report -EBUSY down the chain */
+ if (ret == -EBUSY)
+ ret = 0;
+ low_pfn += (1UL << compound_order(page)) - 1;
+ goto isolate_fail;
+ }
+
+ /*

+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */

+ }
+

Quoted 37 lines
Quoted 28 lines
Quoted 6 lines
Quoted 2 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 6 lines

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Best Regards,
Yan, Zi

Best Regards,
Yan, Zi

author
#5 lore raw
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 45 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 34 lines
Quoted 34 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 22 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Quoted 6 lines
Quoted 2 lines

Best Regards,
Yan, Zi

Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me
author
#6 lore raw
Quoted 97 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 49 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 38 lines
Quoted 37 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#7 lore raw
Quoted 103 lines · Wei Yang
Quoted 102 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 53 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 42 lines
Quoted 29 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Quoted 8 lines
Quoted 3 lines

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

OK, that sounds inefficient and inconsistent with your fix.

While at it, can you also change two “low_pfn += (1UL << order) - 1” to skip the rest of hugetlb?

--
Best Regards,
Yan, Zi

author
#8 lore raw
Quoted 111 lines · Zi Yan
Quoted 109 lines · Wei Yang
Quoted 97 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 49 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 38 lines
Quoted 37 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

Quoted 8 lines
Quoted 2 lines

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

OK, that sounds inefficient and inconsistent with your fix.

While at it, can you also change two “low_pfn += (1UL << order) - 1” to skip the rest of hugetlb?

Sure, glad to.

You prefer do the fix in one patch or have a separate one?

Quoted 3 lines

--
Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#9 lore raw
Quoted 117 lines · Wei Yang
Quoted 116 lines · Zi Yan
Quoted 103 lines · Wei Yang
Quoted 102 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 53 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 42 lines
Quoted 29 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Quoted 8 lines
Quoted 3 lines

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

OK, that sounds inefficient and inconsistent with your fix.

Quoted 7 lines
Quoted 3 lines

While at it, can you also change two “low_pfn += (1UL << order) - 1” to skip the rest of hugetlb?

Sure, glad to.

You prefer do the fix in one patch or have a separate one?

A separate one is better, since these are optimizations, whereas your current patch is a fix.

--
Best Regards,
Yan, Zi

#10 lore raw
Quoted 123 lines · Zi Yan
Quoted 121 lines · Wei Yang
Quoted 119 lines · Zi Yan
Quoted 103 lines · Wei Yang
Quoted 102 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 53 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 42 lines
Quoted 29 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Quoted 8 lines
Quoted 3 lines

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

OK, that sounds inefficient and inconsistent with your fix.

While at it, can you also change two “low_pfn += (1UL << order) - 1” to skip the rest of hugetlb?

Quoted 6 lines
Quoted 3 lines

Sure, glad to.

You prefer do the fix in one patch or have a separate one?

A separate one is better, since these are optimizations, whereas your current patch is a fix.

I'm afraid we should not do that. Because the order getting from compound_order(page) is not stable without lock protection for a hugetlb, This is why we add a sanity check 'if (order <= MAX_PAGE_ORDER)' before advancing low_pfn.

reviewer
#11 lore raw
Quoted 124 lines · Baolin Wang
Quoted 123 lines · Zi Yan
Quoted 121 lines · Wei Yang
Quoted 119 lines · Zi Yan
Quoted 103 lines · Wei Yang
Quoted 102 lines · Wei Yang
Quoted 32 lines · Zi Yan
Quoted 16 lines · Zi Yan
Quoted 14 lines · Zi Yan
Quoted 12 lines · Wei Yang
Quoted 11 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")

This behavior seems to be introduced by commit 369fa227c219 ("mm: make alloc_contig_range handle free hugetlb pages”). The related change is:

(quoted diff) +2 -0
+               if (PageHuge(page) && cc->alloc_contig) {
+                       ret = isolate_or_dissolve_huge_page(page);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+                       /*
+                        * Fail isolation in case isolate_or_dissolve_huge_page()
+                        * reports an error. In case of -ENOMEM, abort right away.
+                        */
+                       if (ret < 0) {
+                                /* Do not report -EBUSY down the chain */
+                               if (ret == -EBUSY)
+                                       ret = 0;
+                               low_pfn += (1UL << compound_order(page)) - 1;

The compound_order(page) return 1 for a tail page.

See below.

Quoted 53 lines
(quoted diff) +11 -0
+                               goto isolate_fail;
+                       }
+
+                       /*
+                        * Ok, the hugepage was dissolved. Now these pages are
+                        * Buddy and cannot be re-allocated because they are
+                        * isolated. Fall-through as the check below handles
+                        * Buddy pages.
+                        */
+               }
+
Quoted 42 lines
Quoted 29 lines
Quoted 7 lines
Quoted 3 lines
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

In addition, there are two other “low_pfn += (1UL << order) - 1” in the if (PageHuge(page)), why not change them too if you think page can point to the middle of a hugetlb?

Quoted 8 lines
Quoted 3 lines

The order here is get from compound_order(page), which is 1 for a tail page.

So it looks right. Maybe I misunderstand it?

Oops, compound_order(page) returns 0 for tail page.

What I want to say is low_pfn advance by 1 for tail page. Sorry for the misleading.

OK, that sounds inefficient and inconsistent with your fix.

While at it, can you also change two “low_pfn += (1UL << order) - 1” to skip the rest of hugetlb?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Sure, glad to.

You prefer do the fix in one patch or have a separate one?

A separate one is better, since these are optimizations, whereas your current patch is a fix.

I'm afraid we should not do that. Because the order getting from compound_order(page) is not stable without lock protection for a hugetlb, This is why we add a sanity check 'if (order <= MAX_PAGE_ORDER)' before advancing low_pfn.

But if page is not the head, "low_pfn += (1UL << order) - 1" will skip more than the hugetlb. But it is OK, since these two are isolate_fail cases and make alloc_contig = true fail anyway.

OK. It seems that we should leave two "low_pfn += (1UL << order) - 1" unchanged.

--
Best Regards,
Yan, Zi

author
#12 lore raw
In reply to Zi Yan
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 18 lines
Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 8 lines
Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#13 lore raw
Quoted 59 lines · Wei Yang
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 21 lines
Quoted 21 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

--
Best Regards,
Yan, Zi

#14 lore raw
Quoted 63 lines · Zi Yan
Quoted 61 lines · Wei Yang
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 23 lines
Quoted 22 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

author
#15 lore raw
Quoted 68 lines · Vishal Moola (Oracle)
Quoted 67 lines · Zi Yan
Quoted 65 lines · Wei Yang
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 26 lines
Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

I think you want to say tail pfn > head pfn?

Quoted 3 lines

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

I may not follow you here, below is the call flow for isolate_migratepages_block() invoked during __alloc_contig_pages().

__alloc_contig_pages(nr_pages, ..);
    start = ALIGN(zone->zone_start_pfn, nr_pages);
    alloc_contig_range_noprof(start, ..);
        __alloc_contig_migrate_range(.., start, ..);
            pfn = start;
            isolate_migratepages_range(.., pfn, ..);
                isolate_migratepages_block(.., pfn, ..);
                    page = pfn_to_page(pfn);
    start += nr_pages;

In the loop of __alloc_contig_pages(), it iterate on each nr_pages range. And nr_pages seems could be any positive number, so it looks the first pfn checked by isolate_migratepages_block() could be not aligned with page order or less than MAX_PAGE_ORDER. This mean it could be a tail page per my understanding.

Maybe I missed some point here?

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#16 lore raw
Quoted 97 lines · Wei Yang
Quoted 68 lines · Vishal Moola (Oracle)
Quoted 67 lines · Zi Yan
Quoted 65 lines · Wei Yang
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 26 lines
Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

I think you want to say tail pfn > head pfn?

Quoted 3 lines

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

I may not follow you here, below is the call flow for isolate_migratepages_block() invoked during __alloc_contig_pages().

__alloc_contig_pages(nr_pages, ..);
    start = ALIGN(zone->zone_start_pfn, nr_pages);
    alloc_contig_range_noprof(start, ..);
        __alloc_contig_migrate_range(.., start, ..);
            pfn = start;
            isolate_migratepages_range(.., pfn, ..);
                isolate_migratepages_block(.., pfn, ..);
                    page = pfn_to_page(pfn);
    start += nr_pages;
Quoted 6 lines

In the loop of __alloc_contig_pages(), it iterate on each nr_pages range. And nr_pages seems could be any positive number, so it looks the first pfn checked by isolate_migratepages_block() could be not aligned with page order or less than MAX_PAGE_ORDER. This mean it could be a tail page per my understanding.

Maybe I missed some point here?

You are right.

But nr_pages cannot be any positive number, since ALIGN only accepts power of 2 as the alignment. So alloc_contig_pages() might need another fix to handle the case nr_pages is not power of 2.

Oh, after I checked pfn_range_valid_contig(), I find your example does not apply, since it returns false when any page in the range is PageHuge. This means with your example, PageHuge branch will never be executed. But alloc_contig_range_noprof() is exported and can be used directly, the @start input can be any pfn, which can be in the middle of PageHuge. So your fix is still needed for this case.

--
Best Regards,
Yan, Zi

#17 lore raw
Quoted 99 lines · Zi Yan
Quoted 97 lines · Wei Yang
Quoted 68 lines · Vishal Moola (Oracle)
Quoted 67 lines · Zi Yan
Quoted 65 lines · Wei Yang
Quoted 25 lines · Zi Yan
Quoted 23 lines · Wei Yang
Quoted 21 lines · Wei Yang

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 7 lines
Quoted 3 lines

Forgot to cc stable.

Is there any bug report to justify the backport? Since it is more likely to be a performance issue instead of a correctness issue.

OK, I thought cc-stable is paired with fixes tag.

If not, please drop it.

Quoted 26 lines
Quoted 18 lines
Quoted 10 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

I think you want to say tail pfn > head pfn?

Quoted 3 lines

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

I may not follow you here, below is the call flow for isolate_migratepages_block() invoked during __alloc_contig_pages().

__alloc_contig_pages(nr_pages, ..);
    start = ALIGN(zone->zone_start_pfn, nr_pages);
    alloc_contig_range_noprof(start, ..);
        __alloc_contig_migrate_range(.., start, ..);
            pfn = start;
            isolate_migratepages_range(.., pfn, ..);
                isolate_migratepages_block(.., pfn, ..);
                    page = pfn_to_page(pfn);
    start += nr_pages;
Quoted 6 lines
Quoted 6 lines

In the loop of __alloc_contig_pages(), it iterate on each nr_pages range. And nr_pages seems could be any positive number, so it looks the first pfn checked by isolate_migratepages_block() could be not aligned with page order or less than MAX_PAGE_ORDER. This mean it could be a tail page per my understanding.

Maybe I missed some point here?

That looks right, I missed the comment:

        /* Scan block by block. First and last block may be incomplete */
Quoted 6 lines

You are right.

But nr_pages cannot be any positive number, since ALIGN only accepts power of 2 as the alignment. So alloc_contig_pages() might need another fix to handle the case nr_pages is not power of 2.

Quoted 6 lines

Oh, after I checked pfn_range_valid_contig(), I find your example does not apply, since it returns false when any page in the range is PageHuge. This means with your example, PageHuge branch will never be executed. But alloc_contig_range_noprof() is exported and can be used directly, the @start input can be any pfn, which can be in the middle of PageHuge. So your fix is still needed for this case.

Makes sense to me.

author
#18 lore raw

On Fri, Sep 12, 2025 at 10:22:01AM -0700, Vishal Moola (Oracle) wrote:
[...]

Quoted 70 lines
Quoted 54 lines
Quoted 54 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 17 lines
Quoted 9 lines

---
mm/compaction.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c +0 -0
index bf021b31c7ec..1e8f8eca318c 100644

mm/compaction.c isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, · line 992

Quoted 5 lines
mm/compaction.c +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;

One question is why we advance compound_nr() in original version.

Quoted 4 lines

Yes, there are several places advancing compound_nr(), but it seems to iterate on the same large page and do the same thing and advance 1 again.

Not sure which part story I missed.

isolate_migratepages_block() starts from the beginning of a pageblock. How likely the code hit in the middle of a hugetlb?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

OK, this is a kind of optimization based on the knowledge it is not likely to be a tail page?

No, it might be that most of the time page is the head, or people assume so.

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

I think you want to say tail pfn > head pfn?

Quoted 3 lines

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

I may not follow you here, below is the call flow for isolate_migratepages_block() invoked during __alloc_contig_pages().

__alloc_contig_pages(nr_pages, ..);
    start = ALIGN(zone->zone_start_pfn, nr_pages);
    alloc_contig_range_noprof(start, ..);
        __alloc_contig_migrate_range(.., start, ..);
            pfn = start;
            isolate_migratepages_range(.., pfn, ..);
                isolate_migratepages_block(.., pfn, ..);
                    page = pfn_to_page(pfn);
    start += nr_pages;
Quoted 6 lines
Quoted 6 lines

In the loop of __alloc_contig_pages(), it iterate on each nr_pages range. And nr_pages seems could be any positive number, so it looks the first pfn checked by isolate_migratepages_block() could be not aligned with page order or less than MAX_PAGE_ORDER. This mean it could be a tail page per my understanding.

Maybe I missed some point here?

That looks right, I missed the comment:

       /* Scan block by block. First and last block may be incomplete */
Quoted 6 lines

You are right.

But nr_pages cannot be any positive number, since ALIGN only accepts power of 2 as the alignment. So alloc_contig_pages() might need another fix to handle the case nr_pages is not power of 2.

Quoted 8 lines
Quoted 6 lines

Oh, after I checked pfn_range_valid_contig(), I find your example does not apply, since it returns false when any page in the range is PageHuge. This means with your example, PageHuge branch will never be executed. But alloc_contig_range_noprof() is exported and can be used directly, the @start input can be any pfn, which can be in the middle of PageHuge. So your fix is still needed for this case.

Makes sense to me.

Thanks :-)

Signature · 2 lines
Wei Yang
Help you, Help me
author
#19 lore raw
In reply to Zi Yan

On Thu, Sep 11, 2025 at 09:29:39PM -0400, Zi Yan wrote:
[...]

Quoted 29 lines
Quoted 29 lines
Quoted 4 lines

For compound pages, we will always have tail pfn < head pfn, so we should always find the head page first.

I think you want to say tail pfn > head pfn?

Quoted 3 lines

If you did find a case where we somehow encounter a tail page here, I'd love to see it. And then you'd also want to make sure the other compaction trackers are appropriately accounted for.

I may not follow you here, below is the call flow for isolate_migratepages_block() invoked during __alloc_contig_pages().

__alloc_contig_pages(nr_pages, ..);
    start = ALIGN(zone->zone_start_pfn, nr_pages);
    alloc_contig_range_noprof(start, ..);
        __alloc_contig_migrate_range(.., start, ..);
            pfn = start;
            isolate_migratepages_range(.., pfn, ..);
                isolate_migratepages_block(.., pfn, ..);
                    page = pfn_to_page(pfn);
    start += nr_pages;

In the loop of __alloc_contig_pages(), it iterate on each nr_pages range. And nr_pages seems could be any positive number, so it looks the first pfn checked by isolate_migratepages_block() could be not aligned with page order or less than MAX_PAGE_ORDER. This mean it could be a tail page per my understanding.

Quoted 8 lines
Quoted 1 line

Maybe I missed some point here?

You are right.

But nr_pages cannot be any positive number, since ALIGN only accepts power of 2 as the alignment. So alloc_contig_pages() might need another fix to handle the case nr_pages is not power of 2.

You are right, I missed ALIGN() requirement.

So here we should use roundup().

Quoted 2 lines

Oh, after I checked pfn_range_valid_contig(), I find your example does not apply, since it returns false when any page in the range is PageHuge.

You are right, here hide some magic...

Quoted 5 lines

This means with your example, PageHuge branch will never be executed. But alloc_contig_range_noprof() is exported and can be used directly, the @start input can be any pfn, which can be in the middle of PageHuge. So your fix is still needed for this case.

Then the next question is why we filter PageHuge() in pfn_range_valid_contig(). Looks we can handle PageHuge() by isolating and migrate it.

Quoted 3 lines

--
Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#20 lore raw

There has been a lot of discussion here, little clarity and no recorded acks. I'm inclined to just drop the patch and to ask that issue be reopened.

Comments?

Thanks.

From: Wei Yang <[email protected]>
Subject: mm/compaction: fix low_pfn advance on isolating hugetlb
Date: Wed, 10 Sep 2025 09:22:40 +0000

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc "Vishal Moola (Oracle)" <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Brendan Jackman <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Wei Yang <[email protected]>
Cc Zi Yan <[email protected]>

---

 mm/compaction.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c renamed from mm/compaction.c~mm-compaction-fix-low_pfn-advance-on-isolating-hugetlb +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compac
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;
 				goto isolate_success_no_list;
 			}
 

_

reviewer Acked-by
#21 lore raw
Quoted 60 lines · Andrew Morton

There has been a lot of discussion here, little clarity and no recorded acks. I'm inclined to just drop the patch and to ask that issue be reopened.

Comments?

Thanks.

From: Wei Yang <[email protected]>
Subject: mm/compaction: fix low_pfn advance on isolating hugetlb
Date: Wed, 10 Sep 2025 09:22:40 +0000

Commit 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()") converts api from page to folio. But the low_pfn advance for hugetlb page seems wrong when low_pfn doesn't point to head page.

Originally, if page is a hugetlb tail page, compound_nr() return 1, which means low_pfn only advance one in next iteration. After the change, low_pfn would advance more than the hugetlb range, since folio_nr_pages() always return total number of the large page. This results in skipping some range to isolate and then to migrate.

The worst case for alloc_contig is it does all the isolation and migration, but finally find some range is still not isolated. And then undo all the work and try a new range.

Advance low_pfn to the end of hugetlb.

Fixes 56ae0bb349b4 ("mm: compaction: convert to use a folio in isolate_migratepages_block()")
Cc "Vishal Moola (Oracle)" <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Brendan Jackman <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Wei Yang <[email protected]>
Cc Zi Yan <[email protected]>

---

 mm/compaction.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/compaction.c renamed from mm/compaction.c~mm-compaction-fix-low_pfn-advance-on-isolating-hugetlb +1 -1
@@ -989,7 +989,7 @@ isolate_migratepages_block(struct compac
 				 * Hugepage was successfully isolated and placed
 				 * on the cc->migratepages list.
 				 */
-				low_pfn += folio_nr_pages(folio) - 1;
+				low_pfn += folio_nr_pages(folio) - folio_page_idx(folio, page) - 1;
 				goto isolate_success_no_list;
 			}
 
Quoted 1 line

_

--
Best Regards,
Yan, Zi