Message ID | 1543997155-18344-1-git-send-email-kernelfans@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm/pageblock: throw compiling time error if pageblock_bits can not hold MIGRATE_TYPES | expand |
Hi Pingfan, Thank you for the patch! Yet something to improve: [auto build test ERROR on linus/master] [also build test ERROR on v4.20-rc5 next-20181206] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Pingfan-Liu/mm-pageblock-throw-compiling-time-error-if-pageblock_bits-can-not-hold-MIGRATE_TYPES/20181207-034245 config: x86_64-randconfig-x011-201848 (attached as .config) compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64 All error/warnings (new ones prefixed by >>): In file included from include/asm-generic/bug.h:5:0, from arch/x86/include/asm/bug.h:47, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from include/linux/mm.h:9, from mm/page_alloc.c:18: mm/page_alloc.c: In function 'set_pfnblock_flags_mask': >> include/linux/compiler.h:372:38: error: call to '__compiletime_assert_428' declared with attribute error: BUILD_BUG_ON failed: order_base_2(MIGRATE_TYPES) != PB_migratetype_bits _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) ^ include/linux/compiler.h:353:4: note: in definition of macro '__compiletime_assert' prefix ## suffix(); \ ^~~~~~ include/linux/compiler.h:372:2: note: in expansion of macro '_compiletime_assert' _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) ^~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:45:37: note: in expansion of macro 'compiletime_assert' #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) ^~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:69:2: note: in expansion of macro 'BUILD_BUG_ON_MSG' BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) ^~~~~~~~~~~~~~~~ >> mm/page_alloc.c:428:2: note: in expansion of macro 'BUILD_BUG_ON' BUILD_BUG_ON(order_base_2(MIGRATE_TYPES) != PB_migratetype_bits); ^~~~~~~~~~~~ vim +/__compiletime_assert_428 +372 include/linux/compiler.h 9a8ab1c3 Daniel Santos 2013-02-21 358 9a8ab1c3 Daniel Santos 2013-02-21 359 #define _compiletime_assert(condition, msg, prefix, suffix) \ 9a8ab1c3 Daniel Santos 2013-02-21 360 __compiletime_assert(condition, msg, prefix, suffix) 9a8ab1c3 Daniel Santos 2013-02-21 361 9a8ab1c3 Daniel Santos 2013-02-21 362 /** 9a8ab1c3 Daniel Santos 2013-02-21 363 * compiletime_assert - break build and emit msg if condition is false 9a8ab1c3 Daniel Santos 2013-02-21 364 * @condition: a compile-time constant condition to check 9a8ab1c3 Daniel Santos 2013-02-21 365 * @msg: a message to emit if condition is false 9a8ab1c3 Daniel Santos 2013-02-21 366 * 9a8ab1c3 Daniel Santos 2013-02-21 367 * In tradition of POSIX assert, this macro will break the build if the 9a8ab1c3 Daniel Santos 2013-02-21 368 * supplied condition is *false*, emitting the supplied error message if the 9a8ab1c3 Daniel Santos 2013-02-21 369 * compiler has support to do so. 9a8ab1c3 Daniel Santos 2013-02-21 370 */ 9a8ab1c3 Daniel Santos 2013-02-21 371 #define compiletime_assert(condition, msg) \ 9a8ab1c3 Daniel Santos 2013-02-21 @372 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) 9a8ab1c3 Daniel Santos 2013-02-21 373 :::::: The code at line 372 was first introduced by commit :::::: 9a8ab1c39970a4938a72d94e6fd13be88a797590 bug.h, compiler.h: introduce compiletime_assert & BUILD_BUG_ON_MSG :::::: TO: Daniel Santos <daniel.santos@pobox.com> :::::: CC: Linus Torvalds <torvalds@linux-foundation.org> --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
On Wed, Dec 5, 2018 at 4:06 PM Pingfan Liu <kernelfans@gmail.com> wrote: > > 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. > 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. > > Signed-off-by: Pingfan Liu <kernelfans@gmail.com> > --- > include/linux/pageblock-flags.h | 5 +++-- > mm/page_alloc.c | 2 +- > 2 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h > index 9132c5c..fe0aec4 100644 > --- a/include/linux/pageblock-flags.h > +++ b/include/linux/pageblock-flags.h > @@ -25,11 +25,12 @@ > > #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, > - /* 3 bits required for migrate types */ > + PB_migrate_end = PB_migrate + PB_migratetype_bits - 1, > + /* n bits required for migrate types */ > PB_migrate_skip,/* If set the block is skipped by compaction */ > > /* > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2ec9cc4..537020f 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -425,7 +425,7 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, > unsigned long bitidx, word_bitidx; > unsigned long old_word, word; > > - BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); > + BUILD_BUG_ON(order_base_2(MIGRATE_TYPES) != PB_migratetype_bits); > Sorry, I made a mistake. It should be (PB_migratetype_bits -1). I will send out V2 Regards, Pingfan > bitmap = get_pageblock_bitmap(page, pfn); > bitidx = pfn_to_bitidx(page, pfn); > -- > 2.7.4 >
diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h index 9132c5c..fe0aec4 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -25,11 +25,12 @@ #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, - /* 3 bits required for migrate types */ + PB_migrate_end = PB_migrate + PB_migratetype_bits - 1, + /* n bits required for migrate types */ PB_migrate_skip,/* If set the block is skipped by compaction */ /* diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2ec9cc4..537020f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -425,7 +425,7 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, unsigned long bitidx, word_bitidx; unsigned long old_word, word; - BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); + BUILD_BUG_ON(order_base_2(MIGRATE_TYPES) != PB_migratetype_bits); bitmap = get_pageblock_bitmap(page, pfn); bitidx = pfn_to_bitidx(page, pfn);
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. 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. Signed-off-by: Pingfan Liu <kernelfans@gmail.com> --- include/linux/pageblock-flags.h | 5 +++-- mm/page_alloc.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)