* [PATCH] mm/compaction: do not skip the free scanner's periodic lock drop
@ 2026-11-16 12:57 Kiryl Shutsemau (Meta)
2026-11-17 1:37 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: Kiryl Shutsemau (Meta) @ 2026-11-16 12:57 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Johannes Weiner, David Hildenbrand
Cc: Kiryl Shutsemau (Meta),
Mel Gorman, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Zi Yan, Dev Jain, linux-mm, linux-kernel, kernel-team
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.
Fixes: 4fca9730c51d ("mm, compaction: sample pageblocks for free pages")
Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
---
mm/compaction.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index f1b2060eb201..4465c1551406 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -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
--
2.54.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/compaction: do not skip the free scanner's periodic lock drop
2026-11-16 12:57 [PATCH] mm/compaction: do not skip the free scanner's periodic lock drop Kiryl Shutsemau (Meta)
@ 2026-11-17 1:37 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-11-17 1:37 UTC (permalink / raw)
To: Kiryl Shutsemau (Meta)
Cc: SJ Park, Andrew Morton, Vlastimil Babka, Johannes Weiner,
David Hildenbrand, Mel Gorman, Suren Baghdasaryan, Michal Hocko,
Brendan Jackman, Zi Yan, Dev Jain, linux-mm, linux-kernel,
kernel-team
On Mon, 16 Nov 2026 12:57:45 +0000 "Kiryl Shutsemau (Meta)" <kas@kernel.org> wrote:
> 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.
Makes sense to me.
>
> 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.
> Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> ---
> mm/compaction.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index f1b2060eb201..4465c1551406 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -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))
Why don't you let the later two lines unchanged? No strong opinion, no
blocker.
Reviewed-by: SJ Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 1:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 12:57 [PATCH] mm/compaction: do not skip the free scanner's periodic lock drop Kiryl Shutsemau (Meta)
2026-11-17 1:37 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®