mm: fix execution order in alloc_contig_range_noprof
Subsystems (2)
PATCH 1/1 mm: fix execution order in alloc_contig_range_noprof
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.
--- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
@@ -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; }
Signature · 1 line
2.34.1
Michal Hocko
reviewerQuoted 9 lines · Hua Su
Fix the execution order issue in
alloc_contig_range_noprofwheredrain_all_pageswas called afterstart_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 commitd479960e44f27("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.
Quoted 57 lines
Signed-off-by Hua Su <[email protected]>Signed-off-by Hua Su <[email protected]>--- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/page_alloc.c +5
-5@@ -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; }Signature · 1 line
2.34.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 12 lines · Michal Hocko <[email protected]> 于2026年1月6日周二 22:55写道:
Quoted 9 lines · Hua Su
Fix the execution order issue in
alloc_contig_range_noprofwheredrain_all_pageswas called afterstart_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 commitd479960e44f27("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.
Quoted 3 lines
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.
This submission was discovered during code review. However, it seems I made a mistake.
Disable LRU pagevec is for the problem where migrate page might fail (origin code has already disabled). It seems not related to the isolated page operation.
Quoted 62 lines
Quoted 57 lines
Signed-off-by Hua Su <[email protected]>Signed-off-by Hua Su <[email protected]>--- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/page_alloc.c +5
-6@@ -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; } --Quoted 1 line
2.34.1
--
Michal Hocko
SUSE Labs