From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E1982DB789 for ; Thu, 9 Jul 2026 23:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783640994; cv=none; b=GolRVZgIoxR5P+B1gZ4FGEDA6RKzMKEnmcrEOAgqq10bybQv/EYly3eREDs7PBWxW/gP8YeYWurg/qya3OmR9e2G6iqW+F3Jr92ajO4yjD/lxVefbChwdnazey9naCxQfcPBuRhCOLj08DOJOvm0N5dNS2fBphOYvsCqXXpyUbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783640994; c=relaxed/simple; bh=D4ed+zjBRDOIXarc7WMa5nBEDZUesOPCZmfkgJjVmF0=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=cge89XJyCmVDJth1DH9d5w/ZRujjOsUFHVXlszAp88GeZtTpohZuSCfa1CbJnrKaWFYrCqBZRmhZ3RpO4+oyVyVtzsfqtaycBUA5/+g+pvZg4DKnPsjNbuRPxHjMdOqpAQW7IHNVcvN8HfTKn5mHS5+8oX+rDYblFHZWi5uUi38= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=EHOtvqF9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="EHOtvqF9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA5341F000E9; Thu, 9 Jul 2026 23:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783640993; bh=14I/OIUOvPE++U6ixxkq7lr8VNi5s9TDJBiz5Ica5m0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=EHOtvqF9fQiz+50/sGzEDe9IPMZTj66d3m1XmucGNT+/13uTlRGuAJBChcLnTgfXT ZuzKJSTIwlv9HyO9OF96u/fzdfx3L1YOL5gboPAzucw371DY4WMjfr6QrV/ugeClmL WNJkapoIk7rowTRHk29ePkCK9zbzUpzuciXhgwl0= Date: Thu, 9 Jul 2026 16:49:52 -0700 From: Andrew Morton To: lirongqing Cc: Yury Norov , Rasmus Villemoes , , Subject: Re: [PATCH] nodemask: use nr_node_ids instead of MAX_NUMNODES in __nodemask_pr_numnodes() Message-Id: <20260709164952.6630ce13f63a3104c2c53572@linux-foundation.org> In-Reply-To: <20260709071739.2408-1-lirongqing@baidu.com> References: <20260709071739.2408-1-lirongqing@baidu.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 9 Jul 2026 15:17:39 +0800 lirongqing wrote: > From: Li RongQing > > __nodemask_pr_numnodes() returns MAX_NUMNODES, a compile-time constant, > as the width for '%*pb[l]' nodemask printing. On systems with few NUMA > nodes this produces excessive zero-padding, e.g. with MAX_NUMNODES=1024 > but only 2 nodes: > > Mems_allowed: 00000000,00000000,...,00000003 (32 groups) Please let's completely describe the effects of this. nodemask_pr_args() is used in several places so I believe that a number of userspace-facing strings will now appear differently? Let's spell out which userspace interfaces are affected, and how. > Use nr_node_ids (the runtime highest-node-id + 1) instead, matching the > behavior of cpumask_pr_args() which uses nr_cpu_ids: > > Mems_allowed: 00000003 > > Move the nr_node_ids declaration earlier in the file (guarded by > __nodemask_pr_numnodes(), and remove the now-duplicate declarations. > > ... > > --- a/include/linux/nodemask.h > +++ b/include/linux/nodemask.h > @@ -95,6 +95,12 @@ > > extern nodemask_t _unused_nodemask_arg_; > > +#if MAX_NUMNODES > 1 > +extern unsigned int nr_node_ids; > +#else > +#define nr_node_ids 1U > +#endif > + > /** > * nodemask_pr_args - printf args to output a nodemask > * @maskp: nodemask to be printed > @@ -105,7 +111,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,7 +444,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; Let's relocate nr_online_nodes also? To keep them together. > static __always_inline void node_set_online(int nid) > @@ -480,7 +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) > -- > 2.9.4