From: "Tim Pepper" <lnxninja@linux.vnet.ibm.com>
To: linux-numa@vger.kernel.org
Subject: [PATCH 3 of 5] Fix numa_num_configured_nodes() to match man page description
Date: Wed, 22 Sep 2010 11:04:15 -0700 [thread overview]
Message-ID: <20100922180414.GF31877@tpepper-t61p.dolavim.us> (raw)
Author: Tim Pepper <lnxninja@linux.vnet.ibm.com>
Date: Tue Sep 21 13:39:54 2010 -0700
Fix numa_num_configured_nodes() to match man page description
numa_num_configured_nodes() is currently returning simply the highest
node number plus one. The man page says it should be the number of nodes
with memory. It is for use in conjunction with the numa_all_nodes_ptr
nodemask which tracks nodes with memory (from which the calling process
is allowed to allocate).
Signed-off-by: Tim Pepper <lnxninja@linux.vnet.ibm.com>
---
libnuma.c | 29 ++++++++++++++++++++++++++---
1 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/libnuma.c b/libnuma.c
index 39a1bc0..641ad26 100644
--- a/libnuma.c
+++ b/libnuma.c
@@ -51,6 +51,7 @@ struct bitmask *numa_all_cpus_ptr = NULL;
of numa_no_nodes and numa_all_nodes, but the loader does not correctly
handle versioning of BSS versus small data items */
+static struct bitmask *numa_memnode_ptr = NULL;
static unsigned long *node_cpu_mask_v1[NUMA_NUM_NODES];
struct bitmask **node_cpu_mask_v2;
@@ -102,6 +103,8 @@ numa_fini(void)
numa_bitmask_free(numa_all_nodes_ptr);
if (numa_no_nodes_ptr)
numa_bitmask_free(numa_no_nodes_ptr);
+ if (numa_memnode_ptr)
+ numa_bitmask_free(numa_memnode_ptr);
}
/*
@@ -289,13 +292,17 @@ int numa_pagesize(void)
make_internal_alias(numa_pagesize);
/*
- * Find the highest numbered existing memory node: maxconfigurednode.
+ * Find nodes with memory (numa_memnode_ptr) and the highest numbered
+ * existing node (maxconfigurednode).
*/
static void
set_configured_nodes(void)
{
DIR *d;
struct dirent *de;
+ long long freep;
+
+ numa_memnode_ptr = numa_allocate_nodemask();
d = opendir("/sys/devices/system/node");
if (!d) {
@@ -306,6 +313,8 @@ set_configured_nodes(void)
if (strncmp(de->d_name, "node", 4))
continue;
nd = strtoul(de->d_name+4, NULL, 0);
+ if (numa_node_size64(nd, &freep) > 0)
+ numa_bitmask_setbit(numa_memnode_ptr, nd);
if (maxconfigurednode < nd)
maxconfigurednode = nd;
}
@@ -569,8 +578,8 @@ static void
set_sizes(void)
{
sizes_set++;
- set_configured_nodes(); /* configured nodes listed in /sys */
set_nodemask_size(); /* size of kernel nodemask_t */
+ set_configured_nodes(); /* configured nodes listed in /sys */
set_numa_max_cpu(); /* size of kernel cpumask_t */
set_configured_cpus(); /* cpus listed in /sys/devices/system/cpu */
set_task_constraints(); /* cpus and nodes for current task */
@@ -579,7 +588,21 @@ set_sizes(void)
int
numa_num_configured_nodes(void)
{
- return maxconfigurednode+1;
+ /*
+ * NOTE: this function's behavior matches the documentation (ie: it
+ * returns a count of nodes with memory) despite the poor function
+ * naming. We also cannot use the similarly poorly named
+ * numa_all_nodes_ptr as it only tracks nodes with memory from which
+ * the calling process can allocate. Think sparse nodes, memory-less
+ * nodes, cpusets...
+ */
+ int memnodecount=0, i;
+
+ for (i=0; i <= maxconfigurednode; i++) {
+ if (numa_bitmask_isbitset(numa_memnode_ptr, i))
+ memnodecount++;
+ }
+ return memnodecount;
}
int
reply other threads:[~2010-09-22 18:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100922180414.GF31877@tpepper-t61p.dolavim.us \
--to=lnxninja@linux.vnet.ibm.com \
--cc=linux-numa@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).