This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] malloc: s/max_node/num_nodes/
- From: Joern Engel <joern at purestorage dot com>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Cc: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>, Joern Engel <joern at purestorage dot com>
- Date: Mon, 25 Jan 2016 16:25:18 -0800
- Subject: [PATCH] malloc: s/max_node/num_nodes/
- Authentication-results: sourceware.org; auth=none
- References: <1453767942-19369-1-git-send-email-joern at purestorage dot com>
Costa complained and I once had a bug because I confused max_node for
num_nodes. Also renames parse_node_count and turns it into a function.
You expect something called foo_init to have side-effects, but not
necessarily something called parse_foo.
JIRA: PURE-27597
---
tpc/malloc2.13/arena.h | 22 ++++++++++++----------
tpc/malloc2.13/malloc.c | 7 +++++--
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/tpc/malloc2.13/arena.h b/tpc/malloc2.13/arena.h
index 9236a3231f07..685822897d97 100644
--- a/tpc/malloc2.13/arena.h
+++ b/tpc/malloc2.13/arena.h
@@ -297,7 +297,7 @@ ptmalloc_init_minimal (void)
static struct malloc_state *_int_new_arena(size_t size, int numa_node);
-static int max_node = -1;
+static int num_nodes = 0;
#include <sys/types.h>
#include <dirent.h>
@@ -306,26 +306,28 @@ static int max_node = -1;
/*
* Wouldn't it be nice to get this with a single syscall instead?
*/
-static void parse_node_count(void)
+static int numa_node_count(void)
{
DIR *d;
struct dirent *de;
+ int ret;
d = opendir("/sys/devices/system/node");
if (!d) {
- max_node = 0;
+ ret = 1;
} else {
while ((de = readdir(d)) != NULL) {
int nd;
if (strncmp(de->d_name, "node", 4))
continue;
nd = strtoul(de->d_name + 4, NULL, 0);
- if (max_node < nd)
- max_node = nd;
+ if (ret < nd + 1)
+ ret = nd + 1;
}
closedir(d);
}
- assert(max_node < MAX_NUMA_NODES);
+ assert(ret <= MAX_NUMA_NODES);
+ return ret;
}
static void ptmalloc_init(void)
@@ -355,8 +357,8 @@ static void ptmalloc_init(void)
mutex_init(&main_arena.mutex);
main_arena.next = &main_arena;
main_arena.numa_node = -1;
- parse_node_count();
- for (i = 0; i <= max_node; i++) {
+ num_nodes = numa_node_count();
+ for (i = 0; i < num_nodes; i++) {
numa_arena[i] = _int_new_arena(0, i);
numa_arena[i]->local_next = numa_arena[i];
(void)mutex_unlock(&numa_arena[i]->mutex);
@@ -474,8 +476,8 @@ static void mbind_memory(void *mem, size_t size, int node)
unsigned long node_mask = 1 << node;
int err;
- assert(max_node < sizeof(unsigned long));
- err = mbind(mem, size, MPOL_PREFERRED, &node_mask, max_node + 1, 0);
+ assert(num_nodes <= sizeof(unsigned long));
+ err = mbind(mem, size, MPOL_PREFERRED, &node_mask, num_nodes, 0);
assert(!err);
}
diff --git a/tpc/malloc2.13/malloc.c b/tpc/malloc2.13/malloc.c
index 94b7e223ec6f..46b3545aaa8f 100644
--- a/tpc/malloc2.13/malloc.c
+++ b/tpc/malloc2.13/malloc.c
@@ -2154,9 +2154,12 @@ struct malloc_par {
static struct malloc_state main_arena;
/*
- * For numa locality, have a per-node list of arenas.
+ * For numa locality, have a per-node list of arenas. 64 ought to be
+ * enough to anybody - for a while, at least. Having it match
+ * wordsize is convenient, as mbind_memory() will need to be changed
+ * at the same time MAX_NUMA_NODES.
*/
-#define MAX_NUMA_NODES 2
+#define MAX_NUMA_NODES sizeof(unsigned long)
static struct malloc_state *numa_arena[MAX_NUMA_NODES];
/* There is only one instance of the malloc parameters. */
--
2.7.0.rc3