diff options
author | Michal Sekletár <msekleta@redhat.com> | 2020-09-01 12:12:32 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-08 08:16:03 +0200 |
commit | 332d387f47b1ba94abefd3f060a452bc00ba611f (patch) | |
tree | ab64d1f5643805199347fb2f9c0185b4de8b0449 /src/shared/numa-util.c | |
parent | 6743a1caf4037f03dc51a1277855018e4ab61957 (diff) | |
download | systemd-332d387f47b1ba94abefd3f060a452bc00ba611f.tar.gz |
core: introduce support for setting NUMAMask= to special "all" value
Fixes #14113
Diffstat (limited to 'src/shared/numa-util.c')
-rw-r--r-- | src/shared/numa-util.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/shared/numa-util.c b/src/shared/numa-util.c index 187992dc69..3ec8ffc5b2 100644 --- a/src/shared/numa-util.c +++ b/src/shared/numa-util.c @@ -5,6 +5,8 @@ #include "alloc-util.h" #include "cpu-set-util.h" +#include "dirent-util.h" +#include "fd-util.h" #include "fileio.h" #include "macro.h" #include "missing_syscall.h" @@ -124,6 +126,61 @@ int numa_to_cpu_set(const NUMAPolicy *policy, CPUSet *ret) { return 0; } +static int numa_max_node(void) { + _cleanup_closedir_ DIR *d = NULL; + struct dirent *de; + int r, max_node = 0; + + d = opendir("/sys/devices/system/node"); + if (!d) + return -errno; + + FOREACH_DIRENT(de, d, break) { + int node; + const char *n; + + (void) dirent_ensure_type(d, de); + + if (de->d_type != DT_DIR) + continue; + + n = startswith(de->d_name, "node"); + if (!n) + continue; + + r = safe_atoi(n, &node); + if (r < 0) + continue; + + if (node > max_node) + max_node = node; + } + + return max_node; +} + +int numa_mask_add_all(CPUSet *mask) { + int m; + + assert(mask); + + m = numa_max_node(); + if (m < 0) { + log_debug_errno(m, "Failed to determine maximum NUMA node index, assuming 1023: %m"); + m = 1023; /* CONFIG_NODES_SHIFT is set to 10 on x86_64, i.e. 1024 NUMA nodes in total */ + } + + for (int i = 0; i <= m; i++) { + int r; + + r = cpu_set_add(mask, i); + if (r < 0) + return r; + } + + return 0; +} + static const char* const mpol_table[] = { [MPOL_DEFAULT] = "default", [MPOL_PREFERRED] = "preferred", |