lib/nodemask: inline next_node_in() and node_random()
authorYury Norov <yury.norov@gmail.com>
Mon, 25 Jul 2022 16:39:17 +0000 (09:39 -0700)
committerYury Norov <yury.norov@gmail.com>
Mon, 1 Aug 2022 15:13:21 +0000 (08:13 -0700)
The functions are pretty thin wrappers around find_bit engine, and
keeping them in c-file prevents compiler from small_const_nbits()
optimization, which must take place for all systems with MAX_NUMNODES
less than BITS_PER_LONG (default is 16 for me).

Moving them to header file doesn't blow up the kernel size:
add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880)

CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Paul Mackerras <paulus@samba.org>
CC: Rasmus Villemoes <linux@rasmusvillemoes.dk>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
CC: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Yury Norov <yury.norov@gmail.com>
MAINTAINERS
include/linux/nodemask.h
lib/Makefile
lib/nodemask.c

index 7c0b8f2..19c8d0e 100644 (file)
@@ -3540,7 +3540,6 @@ F:        lib/bitmap.c
 F:     lib/cpumask.c
 F:     lib/find_bit.c
 F:     lib/find_bit_benchmark.c
 F:     lib/cpumask.c
 F:     lib/find_bit.c
 F:     lib/find_bit_benchmark.c
-F:     lib/nodemask.c
 F:     lib/test_bitmap.c
 F:     tools/include/linux/bitmap.h
 F:     tools/include/linux/find.h
 F:     lib/test_bitmap.c
 F:     tools/include/linux/bitmap.h
 F:     tools/include/linux/find.h
index 0f233b7..4b71a96 100644 (file)
@@ -94,6 +94,7 @@
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
 #include <linux/numa.h>
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
 #include <linux/numa.h>
+#include <linux/random.h>
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
@@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp)
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
  * the first node in src if needed.  Returns MAX_NUMNODES if src is empty.
  */
 #define next_node_in(n, src) __next_node_in((n), &(src))
-unsigned int __next_node_in(int node, const nodemask_t *srcp);
+static inline unsigned int __next_node_in(int node, const nodemask_t *srcp)
+{
+       unsigned int ret = __next_node(node, srcp);
+
+       if (ret == MAX_NUMNODES)
+               ret = __first_node(srcp);
+       return ret;
+}
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
 
 static inline void init_nodemask_of_node(nodemask_t *mask, int node)
 {
@@ -493,14 +501,20 @@ static inline int num_node_state(enum node_states state)
 
 #endif
 
 
 #endif
 
+static inline int node_random(const nodemask_t *maskp)
+{
 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
 #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1)
-extern int node_random(const nodemask_t *maskp);
+       int w, bit = NUMA_NO_NODE;
+
+       w = nodes_weight(*maskp);
+       if (w)
+               bit = bitmap_ord_to_pos(maskp->bits,
+                       get_random_int() % w, MAX_NUMNODES);
+       return bit;
 #else
 #else
-static inline int node_random(const nodemask_t *mask)
-{
        return 0;
        return 0;
-}
 #endif
 #endif
+}
 
 #define node_online_map        node_states[N_ONLINE]
 #define node_possible_map      node_states[N_POSSIBLE]
 
 #define node_online_map        node_states[N_ONLINE]
 #define node_possible_map      node_states[N_POSSIBLE]
index f99bf61..731cea0 100644 (file)
@@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
         flex_proportions.o ratelimit.o show_mem.o \
         is_single_threaded.o plist.o decompress.o kobject_uevent.o \
         earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
         flex_proportions.o ratelimit.o show_mem.o \
         is_single_threaded.o plist.o decompress.o kobject_uevent.o \
         earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
-        nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
+        nmi_backtrace.o win_minmax.o memcat_p.o \
         buildid.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
         buildid.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
index e22647f..b8a433d 100644 (file)
@@ -3,14 +3,6 @@
 #include <linux/module.h>
 #include <linux/random.h>
 
 #include <linux/module.h>
 #include <linux/random.h>
 
-unsigned int __next_node_in(int node, const nodemask_t *srcp)
-{
-       unsigned int ret = __next_node(node, srcp);
-
-       if (ret == MAX_NUMNODES)
-               ret = __first_node(srcp);
-       return ret;
-}
 EXPORT_SYMBOL(__next_node_in);
 
 #ifdef CONFIG_NUMA
 EXPORT_SYMBOL(__next_node_in);
 
 #ifdef CONFIG_NUMA