mm/compaction: do not skip the free scanner's periodic lock drop
Subsystems (2)
PATCH 1/1 mm/compaction: do not skip the free scanner's periodic lock drop
isolate_freepages_block() drops zone->lock, checks for a fatal signal and calls cond_resched() at every pfn that is a multiple of COMPACT_CLUSTER_MAX.
With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly with zone->lock held and interrupts off.
Count probes instead, and check every COMPACT_CLUSTER_MAX of them.
--- mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
mm/compaction.c +7 -5
@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,unsigned int stride, bool strict) { - int nr_scanned = 0, total_isolated = 0; + int nr_scanned = 0, nr_probes = 0, total_isolated = 0;struct page *page;unsigned long flags =0 ;bool locked = false;
@@ -599,13 +599,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,/* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal -* pending. +* pending. Count probes rather than pfns, as the scan does not +* always land on a multiple of COMPACT_CLUSTER_MAX. */ -if (!(blockpfn %COMPACT_CLUSTER_MAX ) - &&compact_unlock_should_abort (&cc->zone->lock, flags, - &locked, cc)) +if (!(nr_probes %COMPACT_CLUSTER_MAX ) && +compact_unlock_should_abort (&cc->zone->lock, flags, + &locked, cc))break ; + nr_probes++; nr_scanned++;/*
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.54.0
Quoted 11 lines · On Mon, 16 Nov 2026 12:57:45 +0000 "Kiryl Shutsemau (Meta)" <[email protected]>…
isolate_freepages_block()dropszone->lock, checks for a fatal signal and callscond_resched()at every pfn that is a multiple ofCOMPACT_CLUSTER_MAX.With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of
COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly withzone->lockheld and interrupts off.Count probes instead, and check every
COMPACT_CLUSTER_MAXof them.
Makes sense to me.
Quoted 2 lines
Fixes 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")
I understand you intentionally not Cc-ing stable@, buecase the user impact is not that bad. I think that makes sense. I just wanted to call out this for a case that it was not intentional.
Quoted 22 lines
Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>--- mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/compaction.c +1
-1@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,unsigned int stride, bool strict) { - int nr_scanned = 0, total_isolated = 0; + int nr_scanned = 0, nr_probes = 0, total_isolated = 0;struct page *page;unsigned long flags =0 ;bool locked = false;@@ -599,13 +599,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,/* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal
mm/compaction.c static unsigned long isolate_freepages_block(struct compact_control *cc, · line 607
Quoted 10 lines
mm/compaction.c +5
-4-* pending. +* pending. Count probes rather than pfns, as the scan does not +* always land on a multiple of COMPACT_CLUSTER_MAX. */ -if (!(blockpfn %COMPACT_CLUSTER_MAX ) - &&compact_unlock_should_abort (&cc->zone->lock, flags, - &locked, cc)) +if (!(nr_probes %COMPACT_CLUSTER_MAX ) && +compact_unlock_should_abort (&cc->zone->lock, flags, + &locked, cc))
Why don't you let the later two lines unchanged? No strong opinion, no blocker.
Thanks,
SJ
[...]
Quoted 14 lines · SJ Park
Quoted 11 lines · On Mon, 16 Nov 2026 12:57:45 +0000 "Kiryl Shutsemau (Meta)" <[email protected]>…
isolate_freepages_block()dropszone->lock, checks for a fatal signal and callscond_resched()at every pfn that is a multiple ofCOMPACT_CLUSTER_MAX.With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of
COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly withzone->lockheld and interrupts off.Count probes instead, and check every
COMPACT_CLUSTER_MAXof them.
Quoted 8 lines
Makes sense to me.
Quoted 2 lines
Fixes 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")I understand you intentionally not Cc-ing stable@, buecase the user impact is not that bad. I think that makes sense. I just wanted to call out this for a case that it was not intentional.
Right, I have not see the actual user effect of the bug.
Quoted 27 lines
Quoted 27 lines
Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>--- mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/compaction.c +3
-3@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,unsigned int stride, bool strict) { - int nr_scanned = 0, total_isolated = 0; + int nr_scanned = 0, nr_probes = 0, total_isolated = 0;struct page *page;unsigned long flags =0 ;bool locked = false;@@ -599,13 +599,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,/* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal -* pending. +* pending. Count probes rather than pfns, as the scan does not +* always land on a multiple of COMPACT_CLUSTER_MAX. */ - if (!(blockpfn % COMPACT_CLUSTER_MAX)
Quoted 8 lines
mm/compaction.c static unsigned long isolate_freepages_block(struct compact_control *cc, · line 607
Quoted 5 lines
mm/compaction.c +3
-2- &&compact_unlock_should_abort (&cc->zone->lock, flags, - &locked, cc)) +if (!(nr_probes %COMPACT_CLUSTER_MAX ) && +compact_unlock_should_abort (&cc->zone->lock, flags, + &locked, cc))Why don't you let the later two lines unchanged? No strong opinion, no blocker.
&& on the new line is odd to me.
Quoted 1 line
Reviewed-by SJ Park <[email protected]>
Thanks!
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 10 lines · Kiryl Shutsemau (Meta)
isolate_freepages_block()dropszone->lock, checks for a fatal signal and callscond_resched()at every pfn that is a multiple ofCOMPACT_CLUSTER_MAX.With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of
COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly withzone->lockheld and interrupts off.
Quoted 5 lines
Count probes instead, and check every
COMPACT_CLUSTER_MAXof them.Fixes 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>---
Cc stable?
Quoted 20 lines
mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/compaction.c +1
-1@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,unsigned int stride, bool strict) { - int nr_scanned = 0, total_isolated = 0; + int nr_scanned = 0, nr_probes = 0, total_isolated = 0;struct page *page;unsigned long flags =0 ;bool locked = false;@@ -599,13 +599,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,/* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal
mm/compaction.c static unsigned long isolate_freepages_block(struct compact_control *cc, · line 607
Quoted 10 lines
mm/compaction.c +5
-4-* pending. +* pending. Count probes rather than pfns, as the scan does not +* always land on a multiple of COMPACT_CLUSTER_MAX. */ -if (!(blockpfn %COMPACT_CLUSTER_MAX ) - &&compact_unlock_should_abort (&cc->zone->lock, flags, - &locked, cc)) +if (!(nr_probes %COMPACT_CLUSTER_MAX ) && +compact_unlock_should_abort (&cc->zone->lock, flags, + &locked, cc))
I see this is an unrelated change but I don't mind.
Quoted 8 lines
mm/compaction.c +1
-0break ; + nr_probes++; nr_scanned++;/* base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Quoted 13 lines · Dev Jain
Quoted 10 lines · Kiryl Shutsemau (Meta)
isolate_freepages_block()dropszone->lock, checks for a fatal signal and callscond_resched()at every pfn that is a multiple ofCOMPACT_CLUSTER_MAX.With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of
COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly withzone->lockheld and interrupts off.
Quoted 7 lines
Quoted 5 lines
Count probes instead, and check every
COMPACT_CLUSTER_MAXof them.Fixes 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>---
Cc stable?
I have not seen real world problem triggered by the bug. I don't think it is needed.
Quoted 2 lines
Reviewed-by Dev Jain <[email protected]>
Thanks!
Quoted 24 lines
Quoted 24 lines
mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)mm/compaction.c +3
-2@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,unsigned int stride, bool strict) { - int nr_scanned = 0, total_isolated = 0; + int nr_scanned = 0, nr_probes = 0, total_isolated = 0;struct page *page;unsigned long flags =0 ;bool locked = false;@@ -599,13 +599,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,/* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal -* pending. +* pending. Count probes rather than pfns, as the scan does not +* always land on a multiple of COMPACT_CLUSTER_MAX. */
Quoted 8 lines
mm/compaction.c static unsigned long isolate_freepages_block(struct compact_control *cc, · line 607
Quoted 6 lines
mm/compaction.c +3
-3-if (!(blockpfn %COMPACT_CLUSTER_MAX ) - &&compact_unlock_should_abort (&cc->zone->lock, flags, - &locked, cc)) +if (!(nr_probes %COMPACT_CLUSTER_MAX ) && +compact_unlock_should_abort (&cc->zone->lock, flags, + &locked, cc))I see this is an unrelated change but I don't mind.
&& on the new line looks odd to me, it belongs to the first line.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 11 lines · Kiryl Shutsemau (Meta)
isolate_freepages_block()dropszone->lock, checks for a fatal signal and callscond_resched()at every pfn that is a multiple ofCOMPACT_CLUSTER_MAX.With a stride above one, the scan steps over a compound page, or over a high-order free page it has just isolated, to a pfn that is not a multiple of the stride. From there it never reaches a multiple of
COMPACT_CLUSTER_MAX, so the rest of the pageblock is scanned without the check, possibly withzone->lockheld and interrupts off.Count probes instead, and check every
COMPACT_CLUSTER_MAXof them.
Makes sense. The loop is working on one page (regardless of its order) at a time.
Quoted 7 lines
Fixes 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")Signed-off-by Kiryl Shutsemau (Meta) <[email protected]>--- mm/compaction.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Best Regards,
Yan, Zi