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 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 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 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
+ mm-compaction-do-not-skip-the-free-scanners-periodic-lock-drop.patch added to mm-new branch
In reply to Kiryl Shutsemau (Meta)The patch titled Subject: mm/compaction: do not skip the free scanner's periodic lock drop has been added to the -mm mm-new branch. Its filename is…
The patch titled
Subject: mm/compaction: do not skip the free scanner's periodic lock drop
has been added to the -mm mm-new branch. Its filename is
mm-compaction-do-not-skip-the-free-scanners-periodic-lock-drop.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-compaction-do-not-skip-the-free-scanners-periodic-lock-drop.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "Kiryl Shutsemau (Meta)" <[email protected]>
Subject: mm/compaction: do not skip the free scanner's periodic lock drop
Date: Mon, 16 Nov 2026 12:57:45 +0000
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 renamed from mm/compaction.c~mm-compaction-do-not-skip-the-free-scanners-periodic-lock-drop +7 -5
@@ -579,7 +579,7 @@ static unsigned long isolate_freepages_bunsigned 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_b/* * 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++;/*
_
Patches currently in -mm which might be from [email protected] are
mm-compaction-do-not-skip-the-free-scanners-periodic-lock-drop.patch