Skip to content

Commit d1554fb

Browse files
x-y-zakpm00
authored andcommitted
mm/page_isolation: remove migratetype parameter from more functions
migratetype is no longer overwritten during pageblock isolation, start_isolate_page_range(), has_unmovable_pages(), and set_migratetype_isolate() no longer need which migratetype to restore during isolation failure. For has_unmoable_pages(), it needs to know if the isolation is for CMA allocation, so adding PB_ISOLATE_MODE_CMA_ALLOC provide the information. At the same time change isolation flags to enum pb_isolate_mode (PB_ISOLATE_MODE_MEM_OFFLINE, PB_ISOLATE_MODE_CMA_ALLOC, PB_ISOLATE_MODE_OTHER). Remove REPORT_FAILURE and check PB_ISOLATE_MODE_MEM_OFFLINE, since only PB_ISOLATE_MODE_MEM_OFFLINE reports isolation failures. alloc_contig_range() no longer needs migratetype. Replace it with a newly defined acr_flags_t to tell if an allocation is for CMA. So does __alloc_contig_migrate_range(). Add ACR_FLAGS_NONE (set to 0) to indicate ordinary allocations. Link: https://lkml.kernel.org/r/20250617021115.2331563-7-ziy@nvidia.com Signed-off-by: Zi Yan <ziy@nvidia.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: David Hildenbrand <david@redhat.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Brendan Jackman <jackmanb@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kirill A. Shuemov <kirill.shutemov@linux.intel.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Michal Hocko <mhocko@suse.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Richard Chang <richardycc@google.com> Cc: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 7a3324e commit d1554fb

File tree

8 files changed

+80
-68
lines changed

8 files changed

+80
-68
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ static int virtio_mem_fake_offline(struct virtio_mem *vm, unsigned long pfn,
12431243
if (atomic_read(&vm->config_changed))
12441244
return -EAGAIN;
12451245

1246-
rc = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE,
1246+
rc = alloc_contig_range(pfn, pfn + nr_pages, ACR_FLAGS_NONE,
12471247
GFP_KERNEL);
12481248
if (rc == -ENOMEM)
12491249
/* whoops, out of memory */

include/linux/gfp.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,14 @@ static inline bool gfp_compaction_allowed(gfp_t gfp_mask)
423423
extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma);
424424

425425
#ifdef CONFIG_CONTIG_ALLOC
426+
427+
typedef unsigned int __bitwise acr_flags_t;
428+
#define ACR_FLAGS_NONE ((__force acr_flags_t)0) // ordinary allocation request
429+
#define ACR_FLAGS_CMA ((__force acr_flags_t)BIT(0)) // allocate for CMA
430+
426431
/* The below functions must be run on a range from a single zone. */
427432
extern int alloc_contig_range_noprof(unsigned long start, unsigned long end,
428-
unsigned migratetype, gfp_t gfp_mask);
433+
acr_flags_t alloc_flags, gfp_t gfp_mask);
429434
#define alloc_contig_range(...) alloc_hooks(alloc_contig_range_noprof(__VA_ARGS__))
430435

431436
extern struct page *alloc_contig_pages_noprof(unsigned long nr_pages, gfp_t gfp_mask,

include/linux/page-isolation.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ static inline void set_pageblock_isolate(struct page *page)
3838
}
3939
#endif
4040

41-
#define MEMORY_OFFLINE 0x1
42-
#define REPORT_FAILURE 0x2
41+
/*
42+
* Pageblock isolation modes:
43+
* PB_ISOLATE_MODE_MEM_OFFLINE - isolate to offline (!allocate) memory
44+
* e.g., skip over PageHWPoison() pages and
45+
* PageOffline() pages. Unmovable pages will be
46+
* reported in this mode.
47+
* PB_ISOLATE_MODE_CMA_ALLOC - isolate for CMA allocations
48+
* PB_ISOLATE_MODE_OTHER - isolate for other purposes
49+
*/
50+
enum pb_isolate_mode {
51+
PB_ISOLATE_MODE_MEM_OFFLINE,
52+
PB_ISOLATE_MODE_CMA_ALLOC,
53+
PB_ISOLATE_MODE_OTHER,
54+
};
4355

4456
void __meminit init_pageblock_migratetype(struct page *page,
4557
enum migratetype migratetype,
@@ -49,10 +61,10 @@ bool pageblock_isolate_and_move_free_pages(struct zone *zone, struct page *page)
4961
bool pageblock_unisolate_and_move_free_pages(struct zone *zone, struct page *page);
5062

5163
int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
52-
int migratetype, int flags);
64+
enum pb_isolate_mode mode);
5365

5466
void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
5567

5668
int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,
57-
int isol_flags);
69+
enum pb_isolate_mode mode);
5870
#endif

include/trace/events/kmem.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,25 @@ TRACE_EVENT(mm_page_alloc_extfrag,
304304
__entry->change_ownership)
305305
);
306306

307+
#ifdef CONFIG_CONTIG_ALLOC
307308
TRACE_EVENT(mm_alloc_contig_migrate_range_info,
308309

309310
TP_PROTO(unsigned long start,
310311
unsigned long end,
311312
unsigned long nr_migrated,
312313
unsigned long nr_reclaimed,
313314
unsigned long nr_mapped,
314-
int migratetype),
315+
acr_flags_t alloc_flags),
315316

316-
TP_ARGS(start, end, nr_migrated, nr_reclaimed, nr_mapped, migratetype),
317+
TP_ARGS(start, end, nr_migrated, nr_reclaimed, nr_mapped, alloc_flags),
317318

318319
TP_STRUCT__entry(
319320
__field(unsigned long, start)
320321
__field(unsigned long, end)
321322
__field(unsigned long, nr_migrated)
322323
__field(unsigned long, nr_reclaimed)
323324
__field(unsigned long, nr_mapped)
324-
__field(int, migratetype)
325+
__field(acr_flags_t, alloc_flags)
325326
),
326327

327328
TP_fast_assign(
@@ -330,17 +331,18 @@ TRACE_EVENT(mm_alloc_contig_migrate_range_info,
330331
__entry->nr_migrated = nr_migrated;
331332
__entry->nr_reclaimed = nr_reclaimed;
332333
__entry->nr_mapped = nr_mapped;
333-
__entry->migratetype = migratetype;
334+
__entry->alloc_flags = alloc_flags;
334335
),
335336

336-
TP_printk("start=0x%lx end=0x%lx migratetype=%d nr_migrated=%lu nr_reclaimed=%lu nr_mapped=%lu",
337+
TP_printk("start=0x%lx end=0x%lx alloc_flags=%d nr_migrated=%lu nr_reclaimed=%lu nr_mapped=%lu",
337338
__entry->start,
338339
__entry->end,
339-
__entry->migratetype,
340+
__entry->alloc_flags,
340341
__entry->nr_migrated,
341342
__entry->nr_reclaimed,
342343
__entry->nr_mapped)
343344
);
345+
#endif
344346

345347
TRACE_EVENT(mm_setup_per_zone_wmarks,
346348

mm/cma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
822822

823823
pfn = cmr->base_pfn + (bitmap_no << cma->order_per_bit);
824824
mutex_lock(&cma->alloc_mutex);
825-
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, gfp);
825+
ret = alloc_contig_range(pfn, pfn + count, ACR_FLAGS_CMA, gfp);
826826
mutex_unlock(&cma->alloc_mutex);
827827
if (ret == 0) {
828828
page = pfn_to_page(pfn);

mm/memory_hotplug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,8 +1962,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
19621962

19631963
/* set above range as isolated */
19641964
ret = start_isolate_page_range(start_pfn, end_pfn,
1965-
MIGRATE_MOVABLE,
1966-
MEMORY_OFFLINE | REPORT_FAILURE);
1965+
PB_ISOLATE_MODE_MEM_OFFLINE);
19671966
if (ret) {
19681967
reason = "failure to isolate range";
19691968
goto failed_removal_pcplists_disabled;
@@ -2033,7 +2032,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
20332032
goto failed_removal_isolated;
20342033
}
20352034

2036-
ret = test_pages_isolated(start_pfn, end_pfn, MEMORY_OFFLINE);
2035+
ret = test_pages_isolated(start_pfn, end_pfn,
2036+
PB_ISOLATE_MODE_MEM_OFFLINE);
20372037

20382038
} while (ret);
20392039

mm/page_alloc.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6693,11 +6693,12 @@ static void alloc_contig_dump_pages(struct list_head *page_list)
66936693

66946694
/*
66956695
* [start, end) must belong to a single zone.
6696-
* @migratetype: using migratetype to filter the type of migration in
6696+
* @alloc_flags: using acr_flags_t to filter the type of migration in
66976697
* trace_mm_alloc_contig_migrate_range_info.
66986698
*/
66996699
static int __alloc_contig_migrate_range(struct compact_control *cc,
6700-
unsigned long start, unsigned long end, int migratetype)
6700+
unsigned long start, unsigned long end,
6701+
acr_flags_t alloc_flags)
67016702
{
67026703
/* This function is based on compact_zone() from compaction.c. */
67036704
unsigned int nr_reclaimed;
@@ -6769,7 +6770,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
67696770
putback_movable_pages(&cc->migratepages);
67706771
}
67716772

6772-
trace_mm_alloc_contig_migrate_range_info(start, end, migratetype,
6773+
trace_mm_alloc_contig_migrate_range_info(start, end, alloc_flags,
67736774
total_migrated,
67746775
total_reclaimed,
67756776
total_mapped);
@@ -6840,10 +6841,7 @@ static int __alloc_contig_verify_gfp_mask(gfp_t gfp_mask, gfp_t *gfp_cc_mask)
68406841
* alloc_contig_range() -- tries to allocate given range of pages
68416842
* @start: start PFN to allocate
68426843
* @end: one-past-the-last PFN to allocate
6843-
* @migratetype: migratetype of the underlying pageblocks (either
6844-
* #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
6845-
* in range must have the same migratetype and it must
6846-
* be either of the two.
6844+
* @alloc_flags: allocation information
68476845
* @gfp_mask: GFP mask. Node/zone/placement hints are ignored; only some
68486846
* action and reclaim modifiers are supported. Reclaim modifiers
68496847
* control allocation behavior during compaction/migration/reclaim.
@@ -6860,7 +6858,7 @@ static int __alloc_contig_verify_gfp_mask(gfp_t gfp_mask, gfp_t *gfp_cc_mask)
68606858
* need to be freed with free_contig_range().
68616859
*/
68626860
int alloc_contig_range_noprof(unsigned long start, unsigned long end,
6863-
unsigned migratetype, gfp_t gfp_mask)
6861+
acr_flags_t alloc_flags, gfp_t gfp_mask)
68646862
{
68656863
unsigned long outer_start, outer_end;
68666864
int ret = 0;
@@ -6875,6 +6873,9 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
68756873
.alloc_contig = true,
68766874
};
68776875
INIT_LIST_HEAD(&cc.migratepages);
6876+
enum pb_isolate_mode mode = (alloc_flags & ACR_FLAGS_CMA) ?
6877+
PB_ISOLATE_MODE_CMA_ALLOC :
6878+
PB_ISOLATE_MODE_OTHER;
68786879

68796880
gfp_mask = current_gfp_context(gfp_mask);
68806881
if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask))
@@ -6901,7 +6902,7 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
69016902
* put back to page allocator so that buddy can use them.
69026903
*/
69036904

6904-
ret = start_isolate_page_range(start, end, migratetype, 0);
6905+
ret = start_isolate_page_range(start, end, mode);
69056906
if (ret)
69066907
goto done;
69076908

@@ -6917,7 +6918,7 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
69176918
* allocated. So, if we fall through be sure to clear ret so that
69186919
* -EBUSY is not accidentally used or returned to caller.
69196920
*/
6920-
ret = __alloc_contig_migrate_range(&cc, start, end, migratetype);
6921+
ret = __alloc_contig_migrate_range(&cc, start, end, alloc_flags);
69216922
if (ret && ret != -EBUSY)
69226923
goto done;
69236924

@@ -6951,7 +6952,7 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end,
69516952
outer_start = find_large_buddy(start);
69526953

69536954
/* Make sure the range is really isolated. */
6954-
if (test_pages_isolated(outer_start, end, 0)) {
6955+
if (test_pages_isolated(outer_start, end, mode)) {
69556956
ret = -EBUSY;
69566957
goto done;
69576958
}
@@ -6994,8 +6995,8 @@ static int __alloc_contig_pages(unsigned long start_pfn,
69946995
{
69956996
unsigned long end_pfn = start_pfn + nr_pages;
69966997

6997-
return alloc_contig_range_noprof(start_pfn, end_pfn, MIGRATE_MOVABLE,
6998-
gfp_mask);
6998+
return alloc_contig_range_noprof(start_pfn, end_pfn, ACR_FLAGS_NONE,
6999+
gfp_mask);
69997000
}
70007001

70017002
static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,

0 commit comments

Comments
 (0)