From nobody Sat Jul 25 22:03:24 2026 Received: from outbound.baidu.com (mx16.baidu.com [111.202.115.101]) by smtp.subspace.kernel.org (Postfix) with SMTP id 18F333947B0 for ; Mon, 13 Jul 2026 07:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.115.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783929084; cv=none; b=rSSzpSIXLPwiOM3U0mdsKZZ6tvAQtEPhtazddK+bisHfckwfEdplA+AD9sFoi4Yc9t3rFK15bZzX7nbP1KDlxvvuaGSz08GmEqpQVfjMOEH0Bg87tw876h4Z4ipGAu27hPxQ8+MKKtqQn4X25M6ipD8rlAP04WVamLeFMmjj1jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783929084; c=relaxed/simple; bh=1hRA/VdeLE/H9JvPkzLp8vt7P6FB8OI1p6jyC6mtZrw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Q3fu2JxHiBJ1OJlzi42mM8cYbso8ejiJ6ZD6sfld9+7u7rjaYKA7t46OypFgR7nbCBUnA1WM1EfcsMuRjWLWG15RJB2fRTkYzXXSTZf3t/EBZwCHh6e4or12Rzm+HOoRdpQe4uQUGv+62TXWp98g4a0zpa2smoeIruGCtKI3SH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b=gvknQOu+; arc=none smtp.client-ip=111.202.115.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b="gvknQOu+" X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: Yury Norov , Rasmus Villemoes , CC: Li RongQing , Andrew Morton , Subject: [PATCH v2] nodemask: reduce bitmap width to nr_node_ids in __nodemask_pr_numnodes() Date: Mon, 13 Jul 2026 15:51:04 +0800 Message-ID: <20260713075104.2196-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: bjhj-exc3.internal.baidu.com (172.31.3.13) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1783929073; bh=qcEJ54+AUEewVbFtDXCKNzdvv1NVqWy7FgqDnJtEHK8=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=gvknQOu+ZPGI8aQnj0l6DuqwaRvcwP+VWGOq+p7ve4BpSWK1zirtStHbKhc4vIgQr yR1aQ7riPFJhL5xZb1cq6qB+yD01z0tAXESyrwHgzMEWbklz22F2mPle9p1o1ZbFPH 6id+yLDO2BkFv58MTNBPMxjfeUUOzuuh0z/Q+kUZSPkd7yqc+GdsYbxAtPGRunQt4L UbuR8StN7diA0ZdOsuYTuxLWeuwQmK9+dJZBqydksEZlGcjkJDrznlz8/9prPZfTBq DByWLnqq7FrEiU/Im4cOlaqAR+Zcs2492v7hRmozlI8wsSix8VpT8+6W9kBBy0OVV0 +g+lWkJH0Q3Nw== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing __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//status prints Mems_allowed with '%*pb' using the nodemask_pr_args() helper. On systems built with MAX_NUMNODES=3D1024 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//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//status Mems_allowed_list * mempolicy strings in /proc//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 Cc: Rasmus Villemoes Cc: Andrew Morton Cc: linux-mm@kvack.org Signed-off-by: Li RongQing --- 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=20 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 @@ =20 extern nodemask_t _unused_nodemask_arg_; =20 +#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 nodem= ask_t *m) { @@ -438,9 +446,6 @@ static __always_inline unsigned int next_memory_node(in= t nid) return next_node(nid, node_states[N_MEMORY]); } =20 -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_sta= tes 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 =20 #define node_set_online(node) node_set_state((node), N_ONLINE) #define node_set_offline(node) node_clear_state((node), N_ONLINE) --=20 2.9.4