Skip to content

Commit e904bce

Browse files
x-y-zakpm00
authored andcommitted
mm/page_isolation: make page isolation a standalone bit
During page isolation, the original migratetype is overwritten, since MIGRATE_* are enums and stored in pageblock bitmaps. Change MIGRATE_ISOLATE to be stored a standalone bit, PB_migrate_isolate, like PB_compact_skip, so that migratetype is not lost during pageblock isolation. Link: https://lkml.kernel.org/r/20250617021115.2331563-3-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 42f46ed commit e904bce

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

include/linux/mmzone.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ enum migratetype {
7979
* __free_pageblock_cma() function.
8080
*/
8181
MIGRATE_CMA,
82+
__MIGRATE_TYPE_END = MIGRATE_CMA,
83+
#else
84+
__MIGRATE_TYPE_END = MIGRATE_HIGHATOMIC,
8285
#endif
8386
#ifdef CONFIG_MEMORY_ISOLATION
8487
MIGRATE_ISOLATE, /* can't allocate from here */

include/linux/page-isolation.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ static inline bool is_migrate_isolate(int migratetype)
1111
{
1212
return migratetype == MIGRATE_ISOLATE;
1313
}
14+
#define get_pageblock_isolate(page) \
15+
get_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate)
16+
#define clear_pageblock_isolate(page) \
17+
clear_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate)
18+
#define set_pageblock_isolate(page) \
19+
set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate)
1420
#else
1521
static inline bool is_migrate_isolate_page(struct page *page)
1622
{
@@ -20,6 +26,16 @@ static inline bool is_migrate_isolate(int migratetype)
2026
{
2127
return false;
2228
}
29+
static inline bool get_pageblock_isolate(struct page *page)
30+
{
31+
return false;
32+
}
33+
static inline void clear_pageblock_isolate(struct page *page)
34+
{
35+
}
36+
static inline void set_pageblock_isolate(struct page *page)
37+
{
38+
}
2339
#endif
2440

2541
#define MEMORY_OFFLINE 0x1

include/linux/pageblock-flags.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ enum pageblock_bits {
2121
/* 3 bits required for migrate types */
2222
PB_compact_skip,/* If set the block is skipped by compaction */
2323

24+
#ifdef CONFIG_MEMORY_ISOLATION
25+
/*
26+
* Pageblock isolation is represented with a separate bit, so that
27+
* the migratetype of a block is not overwritten by isolation.
28+
*/
29+
PB_migrate_isolate, /* If set the block is isolated */
30+
#endif
2431
/*
2532
* Assume the bits will always align on a word. If this assumption
2633
* changes then get/set pageblock needs updating.
@@ -32,6 +39,13 @@ enum pageblock_bits {
3239

3340
#define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1)
3441

42+
#ifdef CONFIG_MEMORY_ISOLATION
43+
#define MIGRATETYPE_AND_ISO_MASK \
44+
(((1UL << (PB_migrate_end + 1)) - 1) | BIT(PB_migrate_isolate))
45+
#else
46+
#define MIGRATETYPE_AND_ISO_MASK MIGRATETYPE_MASK
47+
#endif
48+
3549
#if defined(CONFIG_HUGETLB_PAGE)
3650

3751
#ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE

mm/page_alloc.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,12 @@ get_pfnblock_bitmap_bitidx(const struct page *page, unsigned long pfn,
365365
unsigned long *bitmap;
366366
unsigned long word_bitidx;
367367

368+
#ifdef CONFIG_MEMORY_ISOLATION
369+
BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 8);
370+
#else
368371
BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
369-
BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits));
372+
#endif
373+
BUILD_BUG_ON(__MIGRATE_TYPE_END >= (1 << PB_migratetype_bits));
370374
VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page);
371375

372376
bitmap = get_pageblock_bitmap(page, pfn);
@@ -439,7 +443,16 @@ bool get_pfnblock_bit(const struct page *page, unsigned long pfn,
439443
__always_inline enum migratetype
440444
get_pfnblock_migratetype(const struct page *page, unsigned long pfn)
441445
{
442-
return __get_pfnblock_flags_mask(page, pfn, MIGRATETYPE_MASK);
446+
unsigned long mask = MIGRATETYPE_AND_ISO_MASK;
447+
unsigned long flags;
448+
449+
flags = __get_pfnblock_flags_mask(page, pfn, mask);
450+
451+
#ifdef CONFIG_MEMORY_ISOLATION
452+
if (flags & BIT(PB_migrate_isolate))
453+
return MIGRATE_ISOLATE;
454+
#endif
455+
return flags & MIGRATETYPE_MASK;
443456
}
444457

445458
/**
@@ -519,8 +532,16 @@ __always_inline void set_pageblock_migratetype(struct page *page,
519532
migratetype < MIGRATE_PCPTYPES))
520533
migratetype = MIGRATE_UNMOVABLE;
521534

535+
#ifdef CONFIG_MEMORY_ISOLATION
536+
if (migratetype == MIGRATE_ISOLATE) {
537+
set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate);
538+
return;
539+
}
540+
/* MIGRATETYPE_AND_ISO_MASK clears PB_migrate_isolate if it is set */
541+
#endif
522542
__set_pfnblock_flags_mask(page, page_to_pfn(page),
523-
(unsigned long)migratetype, MIGRATETYPE_MASK);
543+
(unsigned long)migratetype,
544+
MIGRATETYPE_AND_ISO_MASK);
524545
}
525546

526547
#ifdef CONFIG_DEBUG_VM

0 commit comments

Comments
 (0)