PATCH 2/2] lib/bitmap.c: guard exotic bitmap functions by CONFIG_NUMA
Hi Rasmus!
Quoted 11 lines
From: Rasmus Villemoes <[email protected]>
Sent: Saturday, March 30, 2019 12:53:51 AM
To: Rasmus Villemoes; Andrew Morton; Andy Shevchenko
Cc: Yury Norov; [email protected]
Subject: [PATCH 2/2]lib/bitmap.c: guard exotic bitmap functions byCONFIG_NUMAThe
bitmap_remap,_bitremap,_ontoand_foldfunctions are only used, via theirnode_wrappers, inmm/mempolicy.c, which is only built forCONFIG_NUMA. The helperbitmap_ord_to_posused by these functions is global, but its only external caller isnode_random()inlib/nodemask.c, which is also guarded byCONFIG_NUMA.
Nice catch. I think you should protect declaration of those functions in include/linux/bitmap.h as well.
I'm concerned about pollution of such a generic portion of code with subsystem-related #ifdefs. Would it make more sense to move numa-specific stuff to lib/bitmap_numa.c and include/linux/bitmap_numa.h (or *_nodemask.h, or whatever)?
Yury
Quoted 40 lines
For !CONFIG_NUMA:
add/remove: 0/6 grow/shrink: 0/0 up/down: 0/-621 (-621)
Function old new deltabitmap_pos_to_ord 20 - -20 bitmap_ord_to_pos 70 - -70 bitmap_bitremap 81 - -81 bitmap_fold 113 - -113 bitmap_onto 123 - -123 bitmap_remap 214 - -214Total: Before=4776, After=4155, chg -13.00%
Signed-off-by Rasmus Villemoes <[email protected]>--- lib/bitmap.c | 2 ++ 1 file changed, 2 insertions(+)lib/bitmap.c +2
-1@@ -649,6 +649,7 @@ int bitmap_parselist_user(const char __user *ubuf,EXPORT_SYMBOL (bitmap_parselist_user); +#ifdef CONFIG_NUMA /** * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap * @buf: pointer to a bitmap @@ -952,6 +953,7 @@ void bitmap_fold(unsigned long *dst, const unsigned long *orig,for_each_set_bit (oldbit, orig, nbits) set_bit(oldbit % sz, dst); } +#endif /* CONFIG_NUMA */ /* * Common code for bitmap_*_region() routines. -- 2.20.1
Quoted 8 lines · Yury Norov
Hi Rasmus!
Quoted 6 lines
From: Rasmus Villemoes <[email protected]>
Sent: Saturday, March 30, 2019 12:53:51 AM
To: Rasmus Villemoes; Andrew Morton; Andy Shevchenko
Cc: Yury Norov; [email protected]
Subject: [PATCH 2/2]lib/bitmap.c: guard exotic bitmap functions byCONFIG_NUMA
Quoted 8 lines
Quoted 5 lines
The
bitmap_remap,_bitremap,_ontoand_foldfunctions are only used, via theirnode_wrappers, inmm/mempolicy.c, which is only built forCONFIG_NUMA. The helperbitmap_ord_to_posused by these functions is global, but its only external caller isnode_random()inlib/nodemask.c, which is also guarded byCONFIG_NUMA.Nice catch. I think you should protect declaration of those functions in
include/linux/bitmap.has well.
Yeah, well, it's not that simple, because one would also need to wrap the static inline __nodes_onto etc. in ifdefs. Normally, there'd be an #else branch defining simple static inline replacements that always fail or return 0, but we can't do that here. So I'd prefer a simple linker error should any user outside NUMA ever appear. Which I very highly doubt.
Quoted 4 lines
I'm concerned about pollution of such a generic portion of code with subsystem-related #ifdefs. Would it make more sense to move numa-specific stuff to
lib/bitmap_numa.candinclude/linux/bitmap_numa.h(or *_nodemask.h, or whatever)?
Well, yes, that might be better, but a lot bigger patch. One could also argue that bitmap.c is _already_ polluted with subsystem specific code (though not in the form of preprocessor directives).
Dunno, I'll defer to Andrew's judgment.
Rasmus
Quoted 15 lines · Rasmus Villemoes
Quoted 14 lines · Yury Norov
Hi Rasmus!
Quoted 11 lines
From: Rasmus Villemoes <[email protected]>
Sent: Saturday, March 30, 2019 12:53:51 AM
To: Rasmus Villemoes; Andrew Morton; Andy Shevchenko
Cc: Yury Norov; [email protected]
Subject: [PATCH 2/2]lib/bitmap.c: guard exotic bitmap functions byCONFIG_NUMAThe
bitmap_remap,_bitremap,_ontoand_foldfunctions are only used, via theirnode_wrappers, inmm/mempolicy.c, which is only built forCONFIG_NUMA. The helperbitmap_ord_to_posused by these functions is global, but its only external caller isnode_random()inlib/nodemask.c, which is also guarded byCONFIG_NUMA.
Quoted 7 lines
Quoted 2 lines
Nice catch. I think you should protect declaration of those functions in
include/linux/bitmap.has well.Yeah, well, it's not that simple, because one would also need to wrap the static inline
__nodes_ontoetc. in ifdefs. Normally, there'd be an #else branch defining simple static inline replacements that always fail or return 0, but we can't do that here.
There are enough examples of conditionally defined functions without stubs, I don't see any problem with it. Anyways, if you don't like doing that, moving the code and declarations to new files would help.
Quoted 2 lines
So I'd prefer a simple linker
error should any user outside NUMA ever appear. Which I very highly doubt.
Linker errors are usually less specific and much longer to obtain at the linker-stage, which is not good.
Quoted 8 lines
Quoted 4 lines
I'm concerned about pollution of such a generic portion of code with subsystem-related #ifdefs. Would it make more sense to move numa-specific stuff to
lib/bitmap_numa.candinclude/linux/bitmap_numa.h(or *_nodemask.h, or whatever)?Well, yes, that might be better, but a lot bigger patch. One could also argue that
bitmap.cis _already_ polluted with subsystem specific code (though not in the form of preprocessor directives).
I probably don't understand the argument. If we find bitmap.c polluted, we should try clean it, right?