Skip to contentSkip to conversation

mm/pageblock: throw compiling time error if pageblock_bits can not hold MIGRATE_TYPES

PATCH In review Pingfan Liu 2 participants 2 messages Dec 11, 2018 – Dec 14, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mm/pageblock: throw compiling time error if pageblock_bits can not hold MIGRATE_TYPES

Currently, NR_PAGEBLOCK_BITS and MIGRATE_TYPES are not associated by code. If someone adds extra migrate type, then he may forget to enlarge the NR_PAGEBLOCK_BITS. Hence it requires some way to fix. NR_PAGEBLOCK_BITS depends on MIGRATE_TYPES, while these macro spread on two different .h file with reverse dependency, it is a little hard to refer to MIGRATE_TYPES in pageblock-flag.h. This patch tries to remind such relation in compiling-time.

Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Alexander Duyck <[email protected]>

---
v2->v3:
using '>' instead of "==" option since NR_PAGEBLOCK_BITS allows wasted bits

 include/linux/pageblock-flags.h | 3 ++-
 mm/page_alloc.c                 | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/pageblock-flags.h +2 -1
index 9132c5c..06a6632 100644
@@ -25,10 +25,11 @@
 
 #include <linux/types.h>
 
+#define PB_migratetype_bits 3
 /* Bit indices that affect a whole block of pages */
 enum pageblock_bits {
 	PB_migrate,
-	PB_migrate_end = PB_migrate + 3 - 1,
+	PB_migrate_end = PB_migrate + PB_migratetype_bits - 1,
 			/* 3 bits required for migrate types */
 	PB_migrate_skip,/* If set the block is skipped by compaction */
 
mm/page_alloc.c +1 -0
index 2ec9cc4..29ee87e 100644
@@ -426,6 +426,7 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
 	unsigned long old_word, word;
 
 	BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
+	BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits));
 
 	bitmap = get_pageblock_bitmap(page, pfn);
 	bitidx = pfn_to_bitidx(page, pfn);
Signature · 1 line
2.7.4
Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · Pingfan Liu

Currently, NR_PAGEBLOCK_BITS and MIGRATE_TYPES are not associated by code. If someone adds extra migrate type, then he may forget to enlarge the NR_PAGEBLOCK_BITS. Hence it requires some way to fix. NR_PAGEBLOCK_BITS depends on MIGRATE_TYPES, while these macro spread on two different .h file with reverse dependency, it is a little hard to refer to MIGRATE_TYPES in pageblock-flag.h. This patch tries to remind such relation in compiling-time.