Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end

enum pageblock_bits defines the meaning of pageblock bits. Currently
PB_migratetype_bits says the lowest 3 bits represents migratetype and
PB_migrate_end/MIGRATETYPE_MASK's definition rely on it with magical
computation.

Remove the definition of PB_migratetype_bits/PB_migrate_end. Use
PB_migrate_[0|1|2] to represent lowest bits for migratetype. Then we can
simplify related definition.

Also, MIGRATETYPE_AND_ISO_MASK is MIGRATETYPE_MASK add isolation bit. Use
MIGRATETYPE_MASK in the definition of MIGRATETYPE_AND_ISO_MASK looks
cleaner.

No functional change intended.

Link: https://lkml.kernel.org/r/20250827070105.16864-3-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Wei Yang and committed by
Andrew Morton
98c94f10 dd3b304b

+7 -9
+5 -7
include/linux/pageblock-flags.h
··· 13 13 14 14 #include <linux/types.h> 15 15 16 - #define PB_migratetype_bits 3 17 16 /* Bit indices that affect a whole block of pages */ 18 17 enum pageblock_bits { 19 - PB_migrate, 20 - PB_migrate_end = PB_migrate + PB_migratetype_bits - 1, 21 - /* 3 bits required for migrate types */ 18 + PB_migrate_0, 19 + PB_migrate_1, 20 + PB_migrate_2, 22 21 PB_compact_skip,/* If set the block is skipped by compaction */ 23 22 24 23 #ifdef CONFIG_MEMORY_ISOLATION ··· 36 37 37 38 #define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS)) 38 39 39 - #define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1) 40 + #define MIGRATETYPE_MASK (BIT(PB_migrate_0)|BIT(PB_migrate_1)|BIT(PB_migrate_2)) 40 41 41 42 #ifdef CONFIG_MEMORY_ISOLATION 42 - #define MIGRATETYPE_AND_ISO_MASK \ 43 - (((1UL << (PB_migrate_end + 1)) - 1) | BIT(PB_migrate_isolate)) 43 + #define MIGRATETYPE_AND_ISO_MASK (MIGRATETYPE_MASK | BIT(PB_migrate_isolate)) 44 44 #else 45 45 #define MIGRATETYPE_AND_ISO_MASK MIGRATETYPE_MASK 46 46 #endif
+2 -2
mm/page_alloc.c
··· 355 355 356 356 static __always_inline bool is_standalone_pb_bit(enum pageblock_bits pb_bit) 357 357 { 358 - return pb_bit > PB_migrate_end && pb_bit < __NR_PAGEBLOCK_BITS; 358 + return pb_bit >= PB_compact_skip && pb_bit < __NR_PAGEBLOCK_BITS; 359 359 } 360 360 361 361 static __always_inline void ··· 370 370 #else 371 371 BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); 372 372 #endif 373 - BUILD_BUG_ON(__MIGRATE_TYPE_END >= (1 << PB_migratetype_bits)); 373 + BUILD_BUG_ON(__MIGRATE_TYPE_END > MIGRATETYPE_MASK); 374 374 VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); 375 375 376 376 bitmap = get_pageblock_bitmap(page, pfn);