Skip to content

Commit

Permalink
Update to support multiple nodes
Browse files Browse the repository at this point in the history
Probably should squash stuff in with this.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Signed-off-by: Feng Tang <feng.tang@intel.com>
  • Loading branch information
Ben Widawsky authored and andikleen committed Dec 9, 2021
1 parent 34a278a commit 0c844d8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
4 changes: 3 additions & 1 deletion libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,9 @@ static struct bitmask *__numa_preferred(void)
numa_bitmask_clearall(bmp);
getpol(&policy, bmp);

if (policy != MPOL_PREFERRED && policy != MPOL_BIND)
if (policy != MPOL_PREFERRED &&
policy != MPOL_PREFERRED_MANY &&
policy != MPOL_BIND)
return bmp;

if (numa_bitmask_weight(bmp) > 1)
Expand Down
14 changes: 14 additions & 0 deletions numactl.8
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ numactl \- Control NUMA policy for processes or shared memory
] [
.B \-\-preferred node
] [
.B \-\-preferred-many nodes
] [
.B \-\-membind nodes
] [
.B \-\-cpunodebind nodes
Expand Down Expand Up @@ -176,6 +178,14 @@ This should only be used with
.I \-\-membind, \-m
only, otherwise ignored.
.TP
.B \-\-preferred-many=node
Preferably allocate memory on
.I nodes,
but if memory cannot be allocated there fall back to other nodes.
This option takes a mask of preferred nodes where the closest node to local is
considered most preferred.
Relative notation may be used.
.TP
.B \-\-show, \-s
Show NUMA policy settings of the current process.
.TP
Expand All @@ -195,6 +205,7 @@ above (
.I \-\-interleave,
.I \-\-localalloc,
.I \-\-preferred,
.I \-\-preferred-many,
.I \-\-membind
).
.TP
Expand Down Expand Up @@ -297,6 +308,9 @@ also in the same node.
numactl \-\-preferred=1 numactl \-\-show
Set preferred node 1 and show the resulting state.

numactl \-\-preferred-many=0x3 numactl \-\-show
Set preferred nodes 1 and 2, and show the resulting state.

numactl --interleave=all --shm /tmp/shmkey
Interleave all of the sysv shared memory region specified by
/tmp/shmkey over all nodes.
Expand Down
40 changes: 27 additions & 13 deletions numactl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct option opts[] = {
{"all", 0, 0, 'a'},
{"interleave", 1, 0, 'i' },
{"preferred", 1, 0, 'p' },
{"preferred-many", 1, 0, 'P' },
{"cpubind", 1, 0, 'c' },
{"cpunodebind", 1, 0, 'N' },
{"physcpubind", 1, 0, 'C' },
Expand Down Expand Up @@ -67,8 +68,9 @@ void usage(void)
{
fprintf(stderr,
"usage: numactl [--all | -a] [--balancing | -b] [--interleave= | -i <nodes>]\n"
" [--preferred= | -p <node>] [--physcpubind= | -C <cpus>]\n"
" [--cpunodebind= | -N <nodes>] [--membind= | -m <nodes>]\n"
" [--preferred= | -p <node>] [--preferred-many= | -P <nodes>]\n"
" [--physcpubind= | -C <cpus>] [--cpunodebind= | -N <nodes>]\n"
" [--membind= | -m <nodes>] [--localalloc | -l] command args ...\n"
" [--localalloc | -l] command args ...\n"
" numactl [--show | -s]\n"
" numactl [--hardware | -H]\n"
Expand Down Expand Up @@ -132,8 +134,7 @@ void show_physcpubind(void)

void show(void)
{
unsigned long prefnode;
struct bitmask *membind, *interleave, *cpubind;
struct bitmask *membind, *interleave, *cpubind, *preferred;
unsigned long cur;
int policy;

Expand All @@ -145,7 +146,7 @@ void show(void)

cpubind = numa_get_run_node_mask();

prefnode = numa_preferred();
preferred = numa_preferred_many();
interleave = numa_get_interleave_mask();
membind = numa_get_membind();
cur = numa_get_interleave_node();
Expand All @@ -159,8 +160,10 @@ void show(void)
printf("preferred node: ");
switch (policy) {
case MPOL_PREFERRED:
assert(prefnode != -1);
printf("%ld\n", prefnode);
if (numa_bitmask_weight(preferred))
printf("%d\n", find_first(preferred));
else
printf("%d\n", 0);
break;
case MPOL_DEFAULT:
printf("current\n");
Expand All @@ -171,6 +174,9 @@ void show(void)
case MPOL_BIND:
printf("%d\n", find_first(membind));
break;
case MPOL_PREFERRED_MANY:
printf("%ld (preferred-many)\n",cur);
break;
}
if (policy == MPOL_INTERLEAVE) {
printmask("interleavemask", interleave);
Expand All @@ -180,6 +186,7 @@ void show(void)
printmask("cpubind", cpubind); // for compatibility
printmask("nodebind", cpubind);
printmask("membind", membind);
printmask("preferred", preferred);
}

char *fmt_mem(unsigned long long mem, char *buf)
Expand Down Expand Up @@ -524,9 +531,11 @@ int main(int ac, char **av)
numa_set_bind_policy(0);
checkerror("setting membind");
break;
case 'P': /* --preferred-many */
if (!numa_has_preferred_many())
complain("preferred-many requested without kernel support");
case 'p': /* --preferred */
checknuma();
setpolicy(MPOL_PREFERRED);
if (parse_all)
mask = numactl_parse_nodestring(optarg, ALL);
else
Expand All @@ -535,16 +544,21 @@ int main(int ac, char **av)
printf ("<%s> is invalid\n", optarg);
usage();
}
if (numa_bitmask_weight(mask) != 1)
usage();
errno = 0;
did_node_cpu_parse = 1;
numa_set_bind_policy(0);
if (shmfd >= 0)
if (shmfd >= 0) {
numa_tonode_memory(shmptr, shmlen, node);
else
} else if (c == 'p') {
if (numa_bitmask_weight(mask) != 1)
usage();

setpolicy(MPOL_PREFERRED);
numa_set_preferred(find_first(mask));
numa_bitmask_free(mask);
} else {
setpolicy(MPOL_PREFERRED_MANY);
numa_set_preferred_many(mask);
}
checkerror("setting preferred node");
break;
case 'l': /* --local */
Expand Down
1 change: 1 addition & 0 deletions shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ void verify_shm(int policy, struct bitmask *nodes)
}
ilnode = interleave_next(ilnode, nodes2);
break;
case MPOL_PREFERRED_MANY:
case MPOL_PREFERRED:
case MPOL_BIND:
if (!numa_bitmask_isbitset(nodes2, node)) {
Expand Down

0 comments on commit 0c844d8

Please sign in to comment.