From:	Thomas Renninger <trenn@suse.de>
To:	linux-numa@vger.kernel.org
Subject: [PATCH] Fix CPUless nodes numactl --hardware output
Date:	Fri, 21 May 2010 12:13:21 +0200

Fix CPUless nodes numactl --hardware output

A typical setup on IA64 in some kind of interleaved is to expose all memory
in one node while other nodes hold the CPUs and have no memory.

The introduction of nodes_allowed_list in version 2.0.3 which checks for
nodes without memory and the usage in numactl.c (--hardware) to only show
nodes with memory is wrong.

Also the libnuma variable numa_all_nodes_ptr is named suspicious.
It's not all nodes, but all nodes with memory. But this naming is in there
even before 2.0.2. But numactl --hardware must not check for it as the
memoryless nodes also have to be printed.

This patch reverts this change.
Broken output (2 nodes hold CPUs and have no memory, one node has no CPUs, but
the memory):

available: 1 nodes (2)

node 2 size: 32623 MB
node 2 free: 20848 MB
node distances:
node   0   1   2 
  0:   0   0  10 
  1:  20  20  20 
  2:  10  20  20

Output with 2.0.2 or 2.0.3 with this patch:

available: 3 nodes (0-2)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 0 MB
node 0 free: 0 MB
node 1 cpus: 8 9 10 11 12 13 14 15
node 1 size: 0 MB
node 1 free: 0 MB
node 2 cpus:
node 2 size: 32623 MB
node 2 free: 20842 MB
node distances:
node   0   1   2 
  0:   0   0  10 
  1:  20  20  20 
  2:  10  20  20

Signed-off-by: Thomas Renninger <trenn@suse.de>

---
 libnuma.c |   11 -----------
 numactl.c |   15 ++++-----------
 2 files changed, 4 insertions(+), 22 deletions(-)

Index: numactl-test/numactl.c
===================================================================
--- numactl-test.orig/numactl.c
+++ numactl-test/numactl.c
@@ -205,27 +205,20 @@ void print_node_cpus(int node)
 
 	cpus = numa_allocate_cpumask();
 	err = numa_node_to_cpus(node, cpus);
-	if (err >= 0)
+	if (err >= 0) {
 		for (i = 0; i < cpus->size; i++)
 			if (numa_bitmask_isbitset(cpus, i))
 				printf(" %d", i);
+	}
 	putchar('\n');
 }
 
 void hardware(void)
 {
-	int i, numconfigurednodes=0;
+	int i;
 	int maxnode = numa_num_configured_nodes()-1;
 
-	for (i = 0; i<=maxnode; i++)
-		if (numa_bitmask_isbitset(numa_all_nodes_ptr, i))
-			numconfigurednodes++;
-	if (nodes_allowed_list)
-		printf("available: %d nodes (%s)\n",
-			numconfigurednodes, nodes_allowed_list);
-	else
-		printf("available: %d nodes (0-%d)\n", maxnode+1, maxnode); 	
-		
+	printf("available: %d nodes (0-%d)\n", 1+maxnode, maxnode);
 	for (i = 0; i <= maxnode; i++) {
 		char buf[64];
 		long long fr;
Index: numactl-test/libnuma.c
===================================================================
--- numactl-test.orig/libnuma.c
+++ numactl-test/libnuma.c
@@ -54,8 +54,6 @@ struct bitmask *numa_all_cpus_ptr = NULL
 static unsigned long *node_cpu_mask_v1[NUMA_NUM_NODES];
 struct bitmask **node_cpu_mask_v2;
 
-char *nodes_allowed_list = NULL;
-
 WEAK void numa_error(char *where);
 
 #ifdef __thread
@@ -460,15 +458,6 @@ set_task_constraints(void)
 			maxprocnode =
 				read_mask(mask, numa_all_nodes_ptr);
 		}
-		if (strncmp(buffer,"Mems_allowed_list:",18) == 0) {
-			size_t len = strlen(mask);
-
-			nodes_allowed_list = malloc(len);
-			if (nodes_allowed_list) {
-				memcpy(nodes_allowed_list, mask, len-1);
-				nodes_allowed_list[len-1] = '\0';
-			}
-		}
 	}
 	fclose(f);
 	free(buffer);
