containing the cpu where the allocation takes place.
Internally, the Preferred policy uses a single node--the
- preferred_node member of struct mempolicy. A "distinguished
- value of this preferred_node, currently '-1', is interpreted
- as "the node containing the cpu where the allocation takes
- place"--local allocation. "Local" allocation policy can be
- viewed as a Preferred policy that starts at the node containing
- the cpu where the allocation takes place.
+ preferred_node member of struct mempolicy. When the internal
+ mode flag MPOL_F_LOCAL is set, the preferred_node is ignored and
+ the policy is interpreted as local allocation. "Local" allocation
+ policy can be viewed as a Preferred policy that starts at the node
+ containing the cpu where the allocation takes place.
It is possible for the user to specify that local allocation is
always preferred by passing an empty nodemask with this mode.
struct mempolicy default_policy = {
.refcnt = ATOMIC_INIT(1), /* never free it */
.mode = MPOL_PREFERRED,
- .v = { .preferred_node = -1 },
+ .flags = MPOL_F_LOCAL,
};
static const struct mempolicy_operations {
static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes)
{
if (!nodes)
- pol->v.preferred_node = -1; /* local allocation */
+ pol->flags |= MPOL_F_LOCAL; /* local allocation */
else if (nodes_empty(*nodes))
return -EINVAL; /* no allowed nodes */
else
if (pol->flags & MPOL_F_STATIC_NODES) {
int node = first_node(pol->w.user_nodemask);
- if (node_isset(node, *nodes))
+ if (node_isset(node, *nodes)) {
pol->v.preferred_node = node;
- else
- pol->v.preferred_node = -1;
+ pol->flags &= ~MPOL_F_LOCAL;
+ } else
+ pol->flags |= MPOL_F_LOCAL;
} else if (pol->flags & MPOL_F_RELATIVE_NODES) {
mpol_relative_nodemask(&tmp, &pol->w.user_nodemask, nodes);
pol->v.preferred_node = first_node(tmp);
- } else if (pol->v.preferred_node != -1) {
+ } else if (!(pol->flags & MPOL_F_LOCAL)) {
pol->v.preferred_node = node_remap(pol->v.preferred_node,
pol->w.cpuset_mems_allowed,
*nodes);
*nodes = p->v.nodes;
break;
case MPOL_PREFERRED:
- if (p->v.preferred_node >= 0)
+ if (!(p->flags & MPOL_F_LOCAL))
node_set(p->v.preferred_node, *nodes);
/* else return empty node mask for local allocation */
break;
/* Return a zonelist indicated by gfp for node representing a mempolicy */
static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy)
{
- int nd;
+ int nd = numa_node_id();
switch (policy->mode) {
case MPOL_PREFERRED:
- nd = policy->v.preferred_node;
- if (nd < 0)
- nd = numa_node_id();
+ if (!(policy->flags & MPOL_F_LOCAL))
+ nd = policy->v.preferred_node;
break;
case MPOL_BIND:
/*
* current node is part of the mask, we use the zonelist for
* the first node in the mask instead.
*/
- nd = numa_node_id();
if (unlikely(gfp & __GFP_THISNODE) &&
unlikely(!node_isset(nd, policy->v.nodes)))
nd = first_node(policy->v.nodes);
break;
case MPOL_INTERLEAVE: /* should not happen */
- nd = numa_node_id();
break;
default:
- nd = 0;
BUG();
}
return node_zonelist(nd, gfp);
*/
unsigned slab_node(struct mempolicy *policy)
{
- if (!policy)
+ if (!policy || policy->flags & MPOL_F_LOCAL)
return numa_node_id();
switch (policy->mode) {
case MPOL_PREFERRED:
- if (unlikely(policy->v.preferred_node >= 0))
- return policy->v.preferred_node;
- return numa_node_id();
+ /*
+ * handled MPOL_F_LOCAL above
+ */
+ return policy->v.preferred_node;
case MPOL_INTERLEAVE:
return interleave_nodes(policy);
case MPOL_INTERLEAVE:
return nodes_equal(a->v.nodes, b->v.nodes);
case MPOL_PREFERRED:
- return a->v.preferred_node == b->v.preferred_node;
+ return a->v.preferred_node == b->v.preferred_node &&
+ a->flags == b->flags;
default:
BUG();
return 0;
}
/*
- * "local" is pseudo-policy: MPOL_PREFERRED with preferred_node == -1
+ * "local" is pseudo-policy: MPOL_PREFERRED with MPOL_F_LOCAL flag
* Used only for mpol_to_str()
*/
#define MPOL_LOCAL (MPOL_INTERLEAVE + 1)
{
char *p = buffer;
int l;
- int nid;
nodemask_t nodes;
unsigned short mode;
unsigned short flags = pol ? pol->flags : 0;
case MPOL_PREFERRED:
nodes_clear(nodes);
- nid = pol->v.preferred_node;
- if (nid < 0)
+ if (flags & MPOL_F_LOCAL)
mode = MPOL_LOCAL; /* pseudo-policy */
else
- node_set(nid, nodes);
+ node_set(pol->v.preferred_node, nodes);
break;
case MPOL_BIND:
strcpy(p, policy_types[mode]);
p += l;
- if (flags) {
+ if (flags & MPOL_MODE_FLAGS) {
int need_bar = 0;
if (buffer + maxlen < p + 2)