Skip to contentSkip to conversation

include/linux/nodemask.h: Use nr_node_ids (not MAX_NUMNODES) in __nodemask_pr_numnodes()

PATCH Superseded Waiman Long 2 participants 2 messages Dec 19, 2018 – Dec 21, 2018 Bitmap API

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 include/linux/nodemask.h: Use nr_node_ids (not MAX_NUMNODES) in __nodemask_pr_numnodes()

When viewing the /proc/<pid>/status file, one can see output lines like

Cpus_allowed: ffffffff,ffffffff,ffffffff
Cpus_allowed_list: 0-95
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f
Mems_allowed_list: 0-3

The "Mems_allowed" line uses the "%*pb" format string while the "Mems_allowed_list" line uses the "%*pbl" format string together with the nodemask_pr_args() macro.

The "Mems_allowed" looks insane compared with the others. It is because the nodemask_pr_args() macro uses MAX_NUMNODES as the number of nodes to iterate. The cpumask_pr_args() macro uses nr_cpu_ids instead of MAX_CPUS. For nodes, there is a corresponding nr_node_ids. So it makes sense to use nr_node_ids instead to be consistent with "Cpus_allowed:".

With that change, the "Mems_allowed" line becomes sane again.

Mems_allowed: f

There are currently 10 call sites of nodemask_pr_args() in the kernel. Of them, only cpuset_task_status_allowed() in kernel/cgroup/cpuset.c uses the "%*pb" format string that will be affected by this change. That cpuset function is called by proc_pid_status() only.

v3: Fix build problem with MAX_NUMNODES=1.

---
 include/linux/nodemask.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
include/linux/nodemask.h +8 -4
index 5a30ad5..9e3a30d 100644
@@ -98,6 +98,13 @@
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
 
+#if MAX_NUMNODES > 1
+extern int nr_node_ids;
+extern int nr_online_nodes;
+#else
+#define nr_node_ids	MAX_NUMNODES
+#endif
+
 /**
  * nodemask_pr_args - printf args to output a nodemask
  * @maskp: nodemask to be printed
@@ -108,7 +115,7 @@
 				__nodemask_pr_bits(maskp)
 static inline unsigned int __nodemask_pr_numnodes(const nodemask_t *m)
 {
-	return m ? MAX_NUMNODES : 0;
+	return m ? nr_node_ids : 0;
 }
 static inline const unsigned long *__nodemask_pr_bits(const nodemask_t *m)
 {
@@ -444,9 +451,6 @@ static inline int next_memory_node(int nid)
 	return next_node(nid, node_states[N_MEMORY]);
 }
 
-extern int nr_node_ids;
-extern int nr_online_nodes;
-
 static inline void node_set_online(int nid)
 {
 	node_set_state(nid, N_ONLINE);
Signature · 1 line
1.8.3.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Waiman,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.20-rc7 next-20181220]
[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/Waiman-Long/include-linux-nodemask-h-Use-nr_node_ids-not-MAX_NUMNODES-in-__nodemask_pr_numnodes/20181221-082352
config: riscv-tinyconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 8.1.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=riscv

All warnings (new ones prefixed by >>):

In file included from include/linux/sched.h:22,
from arch/riscv/kernel/asm-offsets.c:18:

>> include/linux/nodemask.h:492: warning: "nr_node_ids" redefined
    #define nr_node_ids  1

include/linux/nodemask.h:105: note: this is the location of the previous definition

    #define nr_node_ids MAX_NUMNODES

vim +/nr_node_ids +492 include/linux/nodemask.h

13808910 Christoph Lameter 2007-10-16  485  
13808910 Christoph Lameter 2007-10-16  486  #define for_each_node_state(node, __state) \
13808910 Christoph Lameter 2007-10-16  487  	for ( (node) = 0; (node) == 0; (node) = 1)
13808910 Christoph Lameter 2007-10-16  488  
8357f869 KAMEZAWA Hiroyuki 2006-03-27  489  #define first_online_node	0
8d060bf4 David Rientjes    2014-08-06  490  #define first_memory_node	0
8357f869 KAMEZAWA Hiroyuki 2006-03-27  491  #define next_online_node(nid)	(MAX_NUMNODES)

74c7aa8b Christoph Lameter 2007-02-20 @492 #define nr_node_ids 1
62bc62a8 Christoph Lameter 2009-06-16 493 #define nr_online_nodes 1
13808910 Christoph Lameter 2007-10-16 494

:::::: The code at line 492 was first introduced by commit
:::::: 74c7aa8b8581e0ba8d6d17c623b9279aaabbb0cf [PATCH] Replace highest_possible_node_id() with nr_node_ids

:::::: TO: Christoph Lameter <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation