* [PATCH] mm: fix execution order in alloc_contig_range_noprof
@ 2026-01-05 13:32 Hua Su
2026-01-06 14:55 ` Michal Hocko
0 siblings, 1 reply; 2+ messages in thread
From: Hua Su @ 2026-01-05 13:32 UTC (permalink / raw)
To: akpm, vbabka, surenb, mhocko, jackmanb, hannes, ziy, suhua.tanke
Cc: linux-mm, linux-kernel, Hua Su
Fix the execution order issue in alloc_contig_range_noprof where
drain_all_pages was called after start_isolate_page_range, which
may be lead to race conditions.
Based on community patches commit ec6e8c7e0314 ("mm, page_alloc:
disable pcplists during memory offline") and commit d479960e44f27
("mm: disable LRU pagevec during the migration temporarily"), we
disable pcplists and LRU cache before page isolation to ensure no
pages are left in per-cpu lists during isolation.
Signed-off-by: Hua Su <huasu@xiaomi.com>
Signed-off-by: Hua Su <suhua.tanke@gmail.com>
---
mm/page_alloc.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6a47443c48ff..d08f929ca64c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6815,8 +6815,6 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
.reason = MR_CONTIG_RANGE,
};
- lru_cache_disable();
-
while (pfn < end || !list_empty(&cc->migratepages)) {
if (fatal_signal_pending(current)) {
ret = -EINTR;
@@ -6850,7 +6848,6 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
break;
}
- lru_cache_enable();
if (ret < 0) {
if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY)
alloc_contig_dump_pages(&cc->migratepages);
@@ -6973,6 +6970,9 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask))
return -EINVAL;
+ zone_pcp_disable(cc.zone);
+ lru_cache_disable();
+
/*
* What we do here is we mark all pageblocks in range as
* MIGRATE_ISOLATE. Because pageblock and max order pages may
@@ -6998,8 +6998,6 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
if (ret)
goto done;
- drain_all_pages(cc.zone);
-
/*
* In case of -EBUSY, we'd like to know which page causes problem.
* So, just fall through. test_pages_isolated() has a tracepoint
@@ -7076,6 +7074,8 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
start, end, outer_start, outer_end);
}
done:
+ lru_cache_enable();
+ zone_pcp_enable(cc.zone);
undo_isolate_page_range(start, end);
return ret;
}
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: fix execution order in alloc_contig_range_noprof
2026-01-05 13:32 [PATCH] mm: fix execution order in alloc_contig_range_noprof Hua Su
@ 2026-01-06 14:55 ` Michal Hocko
0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2026-01-06 14:55 UTC (permalink / raw)
To: Hua Su
Cc: akpm, vbabka, surenb, jackmanb, hannes, ziy, linux-mm,
linux-kernel, Hua Su
On Mon 05-01-26 21:32:50, Hua Su wrote:
> Fix the execution order issue in alloc_contig_range_noprof where
> drain_all_pages was called after start_isolate_page_range, which
> may be lead to race conditions.
>
> Based on community patches commit ec6e8c7e0314 ("mm, page_alloc:
> disable pcplists during memory offline") and commit d479960e44f27
> ("mm: disable LRU pagevec during the migration temporarily"), we
> disable pcplists and LRU cache before page isolation to ensure no
> pages are left in per-cpu lists during isolation.
What exactly is the problem you are trying to fix here? Is this based on
code review or are you hitting any real problem. I find the changelog
rather hard to grasp.
> Signed-off-by: Hua Su <huasu@xiaomi.com>
> Signed-off-by: Hua Su <suhua.tanke@gmail.com>
> ---
> mm/page_alloc.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6a47443c48ff..d08f929ca64c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -6815,8 +6815,6 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
> .reason = MR_CONTIG_RANGE,
> };
>
> - lru_cache_disable();
> -
> while (pfn < end || !list_empty(&cc->migratepages)) {
> if (fatal_signal_pending(current)) {
> ret = -EINTR;
> @@ -6850,7 +6848,6 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
> break;
> }
>
> - lru_cache_enable();
> if (ret < 0) {
> if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY)
> alloc_contig_dump_pages(&cc->migratepages);
> @@ -6973,6 +6970,9 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
> if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask))
> return -EINVAL;
>
> + zone_pcp_disable(cc.zone);
> + lru_cache_disable();
> +
> /*
> * What we do here is we mark all pageblocks in range as
> * MIGRATE_ISOLATE. Because pageblock and max order pages may
> @@ -6998,8 +6998,6 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
> if (ret)
> goto done;
>
> - drain_all_pages(cc.zone);
> -
> /*
> * In case of -EBUSY, we'd like to know which page causes problem.
> * So, just fall through. test_pages_isolated() has a tracepoint
> @@ -7076,6 +7074,8 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
> start, end, outer_start, outer_end);
> }
> done:
> + lru_cache_enable();
> + zone_pcp_enable(cc.zone);
> undo_isolate_page_range(start, end);
> return ret;
> }
> --
> 2.34.1
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-06 14:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 13:32 [PATCH] mm: fix execution order in alloc_contig_range_noprof Hua Su
2026-01-06 14:55 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox