The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes()
@ 2026-07-13  7:51 lirongqing
  2026-07-14 13:10 ` Yury Norov
  0 siblings, 1 reply; 4+ messages in thread
From: lirongqing @ 2026-07-13  7:51 UTC (permalink / raw)
  To: Yury Norov, Rasmus Villemoes, linux-kernel
  Cc: Li RongQing, Andrew Morton, linux-mm

From: Li RongQing <lirongqing@baidu.com>

__nodemask_pr_numnodes() currently returns MAX_NUMNODES as the field
width for '%*pb[l]' nodemask printing. MAX_NUMNODES is a compile-time
upper bound and can be much larger than the runtime node id range,
resulting in excessive zero padding in bitmap-form output.

For example, /proc/<pid>/status prints Mems_allowed with '%*pb' using
the nodemask_pr_args() helper. On systems built with MAX_NUMNODES=1024
but booted with a much smaller possible-node range, this produces:

  Mems_allowed: 00000000,00000000,...,00000003

Switch to nr_node_ids, matching the behavior of cpumask_pr_args() which
uses nr_cpu_ids. This reduces the output width from MAX_NUMNODES bits
to the runtime node id range:

  Mems_allowed: 3

Visible impact on in-tree users:
- Bitmap format ('%*pb') users:
  * /proc/<pid>/status Mems_allowed (format changes as shown above)

- List format ('%*pbl') users, output is unchanged, as list formatter
  only prints set bit ranges:
  * /sys/devices/system/node/{possible,online,has_normal_memory, ...}
  * NVMe multipath sysfs numa_nodes
  * memory tier sysfs nodelist
  * cpuset cgroup mems and effective_mems files
  * /proc/<pid>/status Mems_allowed_list
  * mempolicy strings in /proc/<pid>/numa_maps
  * SLUB debugfs output
  * Kernel log messages printing nodemasks

Move nr_node_ids and nr_online_nodes declarations earlier in the file
to allow __nodemask_pr_numnodes() to use nr_node_ids.

Cc: Yury Norov <yury.norov@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
Changes from v1:
- List the unaffected '%*pbl' users explicitly, noting that their
  visible output is unchanged since the list formatter only prints
  set bit ranges regardless of field width.
- Move the nr_node_ids and nr_online_nodes declarations earlier 

include/linux/nodemask.h | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index b842aa5..607373b 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -95,6 +95,14 @@
 
 extern nodemask_t _unused_nodemask_arg_;
 
+#if MAX_NUMNODES > 1
+extern unsigned int nr_node_ids;
+extern unsigned int nr_online_nodes;
+#else
+#define nr_node_ids		1U
+#define nr_online_nodes		1U
+#endif
+
 /**
  * nodemask_pr_args - printf args to output a nodemask
  * @maskp: nodemask to be printed
@@ -105,7 +113,7 @@ extern nodemask_t _unused_nodemask_arg_;
 				__nodemask_pr_bits(maskp)
 static __always_inline unsigned int __nodemask_pr_numnodes(const nodemask_t *m)
 {
-	return m ? MAX_NUMNODES : 0;
+	return m ? nr_node_ids : 0;
 }
 static __always_inline const unsigned long *__nodemask_pr_bits(const nodemask_t *m)
 {
@@ -438,9 +446,6 @@ static __always_inline unsigned int next_memory_node(int nid)
 	return next_node(nid, node_states[N_MEMORY]);
 }
 
-extern unsigned int nr_node_ids;
-extern unsigned int nr_online_nodes;
-
 static __always_inline void node_set_online(int nid)
 {
 	node_set_state(nid, N_ONLINE);
@@ -480,8 +485,6 @@ static __always_inline int num_node_state(enum node_states state)
 #define first_memory_node	0
 #define next_online_node(nid)	(MAX_NUMNODES)
 #define next_memory_node(nid)	(MAX_NUMNODES)
-#define nr_node_ids		1U
-#define nr_online_nodes		1U
 
 #define node_set_online(node)	   node_set_state((node), N_ONLINE)
 #define node_set_offline(node)	   node_clear_state((node), N_ONLINE)
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes()
  2026-07-13  7:51 [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes() lirongqing
@ 2026-07-14 13:10 ` Yury Norov
  2026-07-27 11:56   ` 答复: [????] " Li,Rongqing
  0 siblings, 1 reply; 4+ messages in thread
From: Yury Norov @ 2026-07-14 13:10 UTC (permalink / raw)
  To: lirongqing
  Cc: Yury Norov, Rasmus Villemoes, linux-kernel, Andrew Morton,
	linux-mm

On Mon, Jul 13, 2026 at 03:51:04PM +0800, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> __nodemask_pr_numnodes() currently returns MAX_NUMNODES as the field
> width for '%*pb[l]' nodemask printing. MAX_NUMNODES is a compile-time
> upper bound and can be much larger than the runtime node id range,
> resulting in excessive zero padding in bitmap-form output.
> 
> For example, /proc/<pid>/status prints Mems_allowed with '%*pb' using
> the nodemask_pr_args() helper. On systems built with MAX_NUMNODES=1024
> but booted with a much smaller possible-node range, this produces:
> 
>   Mems_allowed: 00000000,00000000,...,00000003
> 
> Switch to nr_node_ids, matching the behavior of cpumask_pr_args() which
> uses nr_cpu_ids. This reduces the output width from MAX_NUMNODES bits
> to the runtime node id range:
> 
>   Mems_allowed: 3
> 
> Visible impact on in-tree users:
> - Bitmap format ('%*pb') users:
>   * /proc/<pid>/status Mems_allowed (format changes as shown above)

OK, let me take it for testing. If no complains from users, it's a
nice cleanup.
 
> - List format ('%*pbl') users, output is unchanged, as list formatter
>   only prints set bit ranges:
>   * /sys/devices/system/node/{possible,online,has_normal_memory, ...}
>   * NVMe multipath sysfs numa_nodes
>   * memory tier sysfs nodelist
>   * cpuset cgroup mems and effective_mems files
>   * /proc/<pid>/status Mems_allowed_list
>   * mempolicy strings in /proc/<pid>/numa_maps
>   * SLUB debugfs output
>   * Kernel log messages printing nodemasks
> 
> Move nr_node_ids and nr_online_nodes declarations earlier in the file
> to allow __nodemask_pr_numnodes() to use nr_node_ids.
> 
> Cc: Yury Norov <yury.norov@gmail.com>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> Changes from v1:
> - List the unaffected '%*pbl' users explicitly, noting that their
>   visible output is unchanged since the list formatter only prints
>   set bit ranges regardless of field width.
> - Move the nr_node_ids and nr_online_nodes declarations earlier 
> 
> include/linux/nodemask.h | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
> index b842aa5..607373b 100644
> --- a/include/linux/nodemask.h
> +++ b/include/linux/nodemask.h
> @@ -95,6 +95,14 @@
>  
>  extern nodemask_t _unused_nodemask_arg_;
>  
> +#if MAX_NUMNODES > 1
> +extern unsigned int nr_node_ids;
> +extern unsigned int nr_online_nodes;
> +#else
> +#define nr_node_ids		1U
> +#define nr_online_nodes		1U
> +#endif
> +
>  /**
>   * nodemask_pr_args - printf args to output a nodemask
>   * @maskp: nodemask to be printed
> @@ -105,7 +113,7 @@ extern nodemask_t _unused_nodemask_arg_;
>  				__nodemask_pr_bits(maskp)
>  static __always_inline unsigned int __nodemask_pr_numnodes(const nodemask_t *m)
>  {
> -	return m ? MAX_NUMNODES : 0;
> +	return m ? nr_node_ids : 0;
>  }
>  static __always_inline const unsigned long *__nodemask_pr_bits(const nodemask_t *m)
>  {
> @@ -438,9 +446,6 @@ static __always_inline unsigned int next_memory_node(int nid)
>  	return next_node(nid, node_states[N_MEMORY]);
>  }
>  
> -extern unsigned int nr_node_ids;
> -extern unsigned int nr_online_nodes;
> -
>  static __always_inline void node_set_online(int nid)
>  {
>  	node_set_state(nid, N_ONLINE);
> @@ -480,8 +485,6 @@ static __always_inline int num_node_state(enum node_states state)
>  #define first_memory_node	0
>  #define next_online_node(nid)	(MAX_NUMNODES)
>  #define next_memory_node(nid)	(MAX_NUMNODES)
> -#define nr_node_ids		1U
> -#define nr_online_nodes		1U
>  
>  #define node_set_online(node)	   node_set_state((node), N_ONLINE)
>  #define node_set_offline(node)	   node_clear_state((node), N_ONLINE)
> -- 
> 2.9.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* 答复: [????] Re: [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes()
  2026-07-14 13:10 ` Yury Norov
@ 2026-07-27 11:56   ` Li,Rongqing
  2026-07-28  1:30     ` Yury Norov
  0 siblings, 1 reply; 4+ messages in thread
From: Li,Rongqing @ 2026-07-27 11:56 UTC (permalink / raw)
  To: Yury Norov
  Cc: Yury Norov, Rasmus Villemoes, linux-kernel@vger.kernel.org,
	Andrew Morton, linux-mm@kvack.org



> -----邮件原件-----
> 发件人: Yury Norov <ynorov@nvidia.com>
> 发送时间: 2026年7月14日 21:11
> 收件人: Li,Rongqing <lirongqing@baidu.com>
> 抄送: Yury Norov <yury.norov@gmail.com>; Rasmus Villemoes
> <linux@rasmusvillemoes.dk>; linux-kernel@vger.kernel.org; Andrew Morton
> <akpm@linux-foundation.org>; linux-mm@kvack.org
> 主题: [????] Re: [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in
> __nodemask_pr_numnodes()
> 
> On Mon, Jul 13, 2026 at 03:51:04PM +0800, lirongqing wrote:
> > From: Li RongQing <lirongqing@baidu.com>
> >
> > __nodemask_pr_numnodes() currently returns MAX_NUMNODES as the field
> > width for '%*pb[l]' nodemask printing. MAX_NUMNODES is a compile-time
> > upper bound and can be much larger than the runtime node id range,
> > resulting in excessive zero padding in bitmap-form output.
> >
> > For example, /proc/<pid>/status prints Mems_allowed with '%*pb' using
> > the nodemask_pr_args() helper. On systems built with MAX_NUMNODES=1024
> > but booted with a much smaller possible-node range, this produces:
> >
> >   Mems_allowed: 00000000,00000000,...,00000003
> >
> > Switch to nr_node_ids, matching the behavior of cpumask_pr_args()
> > which uses nr_cpu_ids. This reduces the output width from MAX_NUMNODES
> > bits to the runtime node id range:
> >
> >   Mems_allowed: 3
> >
> > Visible impact on in-tree users:
> > - Bitmap format ('%*pb') users:
> >   * /proc/<pid>/status Mems_allowed (format changes as shown above)
> 
> OK, let me take it for testing. If no complains from users, it's a nice cleanup.
> 

Hi Yury Norov:

Gentle ping on this change. It has been under testing for about two weeks since your last comment. Have there been any user reports or other concerns?

Thanks.

[Li,Rongqing] 


> > - List format ('%*pbl') users, output is unchanged, as list formatter
> >   only prints set bit ranges:
> >   * /sys/devices/system/node/{possible,online,has_normal_memory, ...}
> >   * NVMe multipath sysfs numa_nodes
> >   * memory tier sysfs nodelist
> >   * cpuset cgroup mems and effective_mems files
> >   * /proc/<pid>/status Mems_allowed_list
> >   * mempolicy strings in /proc/<pid>/numa_maps
> >   * SLUB debugfs output
> >   * Kernel log messages printing nodemasks
> >
> > Move nr_node_ids and nr_online_nodes declarations earlier in the file
> > to allow __nodemask_pr_numnodes() to use nr_node_ids.
> >
> > Cc: Yury Norov <yury.norov@gmail.com>
> > Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: linux-mm@kvack.org
> > Signed-off-by: Li RongQing <lirongqing@baidu.com>
> > ---
> > Changes from v1:
> > - List the unaffected '%*pbl' users explicitly, noting that their
> >   visible output is unchanged since the list formatter only prints
> >   set bit ranges regardless of field width.
> > - Move the nr_node_ids and nr_online_nodes declarations earlier
> >
> > include/linux/nodemask.h | 15 +++++++++------
> >  1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index
> > b842aa5..607373b 100644
> > --- a/include/linux/nodemask.h
> > +++ b/include/linux/nodemask.h
> > @@ -95,6 +95,14 @@
> >
> >  extern nodemask_t _unused_nodemask_arg_;
> >
> > +#if MAX_NUMNODES > 1
> > +extern unsigned int nr_node_ids;
> > +extern unsigned int nr_online_nodes;
> > +#else
> > +#define nr_node_ids		1U
> > +#define nr_online_nodes		1U
> > +#endif
> > +
> >  /**
> >   * nodemask_pr_args - printf args to output a nodemask
> >   * @maskp: nodemask to be printed
> > @@ -105,7 +113,7 @@ extern nodemask_t _unused_nodemask_arg_;
> >  				__nodemask_pr_bits(maskp)
> >  static __always_inline unsigned int __nodemask_pr_numnodes(const
> > nodemask_t *m)  {
> > -	return m ? MAX_NUMNODES : 0;
> > +	return m ? nr_node_ids : 0;
> >  }
> >  static __always_inline const unsigned long *__nodemask_pr_bits(const
> > nodemask_t *m)  { @@ -438,9 +446,6 @@ static __always_inline unsigned
> > int next_memory_node(int nid)
> >  	return next_node(nid, node_states[N_MEMORY]);  }
> >
> > -extern unsigned int nr_node_ids;
> > -extern unsigned int nr_online_nodes;
> > -
> >  static __always_inline void node_set_online(int nid)  {
> >  	node_set_state(nid, N_ONLINE);
> > @@ -480,8 +485,6 @@ static __always_inline int num_node_state(enum
> node_states state)
> >  #define first_memory_node	0
> >  #define next_online_node(nid)	(MAX_NUMNODES)
> >  #define next_memory_node(nid)	(MAX_NUMNODES)
> > -#define nr_node_ids		1U
> > -#define nr_online_nodes		1U
> >
> >  #define node_set_online(node)	   node_set_state((node), N_ONLINE)
> >  #define node_set_offline(node)	   node_clear_state((node), N_ONLINE)
> > --
> > 2.9.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 答复: [????] Re: [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes()
  2026-07-27 11:56   ` 答复: [????] " Li,Rongqing
@ 2026-07-28  1:30     ` Yury Norov
  0 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2026-07-28  1:30 UTC (permalink / raw)
  To: Li,Rongqing
  Cc: Yury Norov, Rasmus Villemoes, linux-kernel@vger.kernel.org,
	Andrew Morton, linux-mm@kvack.org

On Mon, Jul 27, 2026 at 11:56:35AM +0000, Li,Rongqing wrote:
> Hi Yury Norov:
> 
> Gentle ping on this change. It has been under testing for about two weeks since your last comment. Have there been any user reports or other concerns?

It's in -next and scheduled for 7.2.

Thanks,
Yury

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-28  1:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  7:51 [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes() lirongqing
2026-07-14 13:10 ` Yury Norov
2026-07-27 11:56   ` 答复: [????] " Li,Rongqing
2026-07-28  1:30     ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox