Skip to content

Commit

Permalink
libnuma: Export interface to set/get preferred nodes
Browse files Browse the repository at this point in the history
For now this will just fall back to single node with warning when
needed.

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 c9fb863 commit 7213fe5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,8 @@ void numa_set_bind_policy(int strict)
{
if (strict)
bind_policy = MPOL_BIND;
else if (has_preferred_many)
bind_policy = MPOL_PREFERRED_MANY;
else
bind_policy = MPOL_PREFERRED;
}
Expand Down Expand Up @@ -1839,6 +1841,20 @@ int numa_has_preferred_many(void)
return has_preferred_many;
}

void numa_set_preferred_many(struct bitmask *bitmask)
{
if (!has_preferred_many) {
numa_error("Unable to handle MANY preferred nodes. Falling back to first node\n");
__numa_set_preferred(bitmask);
}
setpol(MPOL_PREFERRED_MANY, bitmask);
}

struct bitmask *numa_preferred_many()
{
return __numa_preferred();
}

void numa_set_localalloc(void)
{
setpol(MPOL_LOCAL, numa_no_nodes_ptr);
Expand Down
6 changes: 6 additions & 0 deletions numa.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ void numa_set_preferred(int node);
/* Returns whether or not the platform supports MPOL_PREFERRED_MANY */
int numa_has_preferred_many(void);

/* Set of nodes to preferably allocate memory from for task. */
void numa_set_preferred_many(struct bitmask *bitmask);

/* Return preferred nodes */
struct bitmask *numa_preferred_many(void);

/* Set local memory allocation policy for task */
void numa_set_localalloc(void);

Expand Down
2 changes: 2 additions & 0 deletions versions.ldscript
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ libnuma_1.5 {
libnuma_1.6{
global:
numa_has_preferred_many;
numa_set_preferred_many;
numa_preferred_many;
local:
*;
} libnuma_1.5;

0 comments on commit 7213fe5

Please sign in to comment.