Skip to content

Commit

Permalink
linux: use /sys/devices/system/node/possible for memory binding
Browse files Browse the repository at this point in the history
Use this mask to initialize the lookup for get_mempolicy mask required size.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Sep 12, 2018
1 parent 2df3cbc commit 4bcd959
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hwloc/topology-linux.c
Expand Up @@ -1845,13 +1845,30 @@ hwloc_linux_find_kernel_max_numnodes(hwloc_topology_t topology __hwloc_attribute
{
static int _max_numnodes = -1, max_numnodes;
int linuxpolicy;
int fd;

if (_max_numnodes != -1)
/* already computed */
return _max_numnodes;

/* start with a single ulong, it's the minimal and it's enough for most machines */
max_numnodes = HWLOC_BITS_PER_LONG;

/* try to get the max from sysfs */
fd = open("/sys/devices/system/node/possible", O_RDONLY); /* binding only supported in real fsroot, no need for data->root_fd */
if (fd >= 0) {
hwloc_bitmap_t possible_bitmap = hwloc_bitmap_alloc();
if (hwloc__read_fd_as_cpulist(fd, possible_bitmap) == 0) {
int max_possible = hwloc_bitmap_last(possible_bitmap);
hwloc_debug_bitmap("possible NUMA nodes are %s\n", possible_bitmap);

if (max_numnodes < max_possible + 1)
max_numnodes = max_possible + 1;
}
close(fd);
hwloc_bitmap_free(possible_bitmap);
}

while (1) {
unsigned long mask[max_numnodes / HWLOC_BITS_PER_LONG];
int err = hwloc_get_mempolicy(&linuxpolicy, mask, max_numnodes, 0, 0);
Expand Down

0 comments on commit 4bcd959

Please sign in to comment.