Commit a3b51e01 authored by David Rientjes's avatar David Rientjes Committed by Linus Torvalds

mempolicy: convert MPOL constants to enum

The mempolicy mode constants, MPOL_DEFAULT, MPOL_PREFERRED, MPOL_BIND, and
MPOL_INTERLEAVE, are better declared as part of an enum since they are
sequentially numbered and cannot be combined.

The policy member of struct mempolicy is also converted from type short to
type unsigned short.  A negative policy does not have any legitimate meaning,
so it is possible to change its type in preparation for adding optional mode
flags later.

The equivalent member of struct shmem_sb_info is also changed from int to
unsigned short.

For compatibility, the policy formal to get_mempolicy() remains as a pointer
to an int:

	int get_mempolicy(int *policy, unsigned long *nmask,
			  unsigned long maxnode, unsigned long addr,
			  unsigned long flags);

although the only possible values is the range of type unsigned short.

Cc: Paul Jackson <pj@sgi.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1b27d05b
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
*/ */
/* Policies */ /* Policies */
#define MPOL_DEFAULT 0 enum {
#define MPOL_PREFERRED 1 MPOL_DEFAULT,
#define MPOL_BIND 2 MPOL_PREFERRED,
#define MPOL_INTERLEAVE 3 MPOL_BIND,
MPOL_INTERLEAVE,
#define MPOL_MAX MPOL_INTERLEAVE MPOL_MAX, /* always last member of enum */
};
/* Flags for get_mem_policy */ /* Flags for get_mem_policy */
#define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */ #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
...@@ -64,7 +65,7 @@ struct mm_struct; ...@@ -64,7 +65,7 @@ struct mm_struct;
*/ */
struct mempolicy { struct mempolicy {
atomic_t refcnt; atomic_t refcnt;
short policy; /* See MPOL_* above */ unsigned short policy; /* See MPOL_* above */
union { union {
short preferred_node; /* preferred */ short preferred_node; /* preferred */
nodemask_t nodes; /* interleave/bind */ nodemask_t nodes; /* interleave/bind */
...@@ -134,7 +135,7 @@ struct shared_policy { ...@@ -134,7 +135,7 @@ struct shared_policy {
spinlock_t lock; spinlock_t lock;
}; };
void mpol_shared_policy_init(struct shared_policy *info, int policy, void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
nodemask_t *nodes); nodemask_t *nodes);
int mpol_set_shared_policy(struct shared_policy *info, int mpol_set_shared_policy(struct shared_policy *info,
struct vm_area_struct *vma, struct vm_area_struct *vma,
...@@ -202,7 +203,7 @@ static inline int mpol_set_shared_policy(struct shared_policy *info, ...@@ -202,7 +203,7 @@ static inline int mpol_set_shared_policy(struct shared_policy *info,
} }
static inline void mpol_shared_policy_init(struct shared_policy *info, static inline void mpol_shared_policy_init(struct shared_policy *info,
int policy, nodemask_t *nodes) unsigned short policy, nodemask_t *nodes)
{ {
} }
......
...@@ -34,7 +34,7 @@ struct shmem_sb_info { ...@@ -34,7 +34,7 @@ struct shmem_sb_info {
uid_t uid; /* Mount uid for root directory */ uid_t uid; /* Mount uid for root directory */
gid_t gid; /* Mount gid for root directory */ gid_t gid; /* Mount gid for root directory */
mode_t mode; /* Mount mode for root directory */ mode_t mode; /* Mount mode for root directory */
int policy; /* Default NUMA memory alloc policy */ unsigned short policy; /* Default NUMA memory alloc policy */
nodemask_t policy_nodes; /* nodemask for preferred and bind */ nodemask_t policy_nodes; /* nodemask for preferred and bind */
}; };
......
...@@ -114,7 +114,7 @@ static void mpol_rebind_policy(struct mempolicy *pol, ...@@ -114,7 +114,7 @@ static void mpol_rebind_policy(struct mempolicy *pol,
const nodemask_t *newmask); const nodemask_t *newmask);
/* Do sanity checking on a policy */ /* Do sanity checking on a policy */
static int mpol_check_policy(int mode, nodemask_t *nodes) static int mpol_check_policy(unsigned short mode, nodemask_t *nodes)
{ {
int was_empty, is_empty; int was_empty, is_empty;
...@@ -159,6 +159,8 @@ static int mpol_check_policy(int mode, nodemask_t *nodes) ...@@ -159,6 +159,8 @@ static int mpol_check_policy(int mode, nodemask_t *nodes)
if (!was_empty && is_empty) if (!was_empty && is_empty)
return -EINVAL; return -EINVAL;
break; break;
default:
BUG();
} }
return 0; return 0;
} }
...@@ -185,7 +187,7 @@ static int is_valid_nodemask(nodemask_t *nodemask) ...@@ -185,7 +187,7 @@ static int is_valid_nodemask(nodemask_t *nodemask)
} }
/* Create a new policy */ /* Create a new policy */
static struct mempolicy *mpol_new(int mode, nodemask_t *nodes) static struct mempolicy *mpol_new(unsigned short mode, nodemask_t *nodes)
{ {
struct mempolicy *policy; struct mempolicy *policy;
...@@ -218,6 +220,8 @@ static struct mempolicy *mpol_new(int mode, nodemask_t *nodes) ...@@ -218,6 +220,8 @@ static struct mempolicy *mpol_new(int mode, nodemask_t *nodes)
} }
policy->v.nodes = *nodes; policy->v.nodes = *nodes;
break; break;
default:
BUG();
} }
policy->policy = mode; policy->policy = mode;
policy->cpuset_mems_allowed = cpuset_mems_allowed(current); policy->cpuset_mems_allowed = cpuset_mems_allowed(current);
...@@ -462,7 +466,7 @@ static void mpol_set_task_struct_flag(void) ...@@ -462,7 +466,7 @@ static void mpol_set_task_struct_flag(void)
} }
/* Set the process memory policy */ /* Set the process memory policy */
static long do_set_mempolicy(int mode, nodemask_t *nodes) static long do_set_mempolicy(unsigned short mode, nodemask_t *nodes)
{ {
struct mempolicy *new; struct mempolicy *new;
...@@ -759,7 +763,7 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int * ...@@ -759,7 +763,7 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
#endif #endif
static long do_mbind(unsigned long start, unsigned long len, static long do_mbind(unsigned long start, unsigned long len,
unsigned long mode, nodemask_t *nmask, unsigned short mode, nodemask_t *nmask,
unsigned long flags) unsigned long flags)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
...@@ -769,9 +773,8 @@ static long do_mbind(unsigned long start, unsigned long len, ...@@ -769,9 +773,8 @@ static long do_mbind(unsigned long start, unsigned long len,
int err; int err;
LIST_HEAD(pagelist); LIST_HEAD(pagelist);
if ((flags & ~(unsigned long)(MPOL_MF_STRICT | if (flags & ~(unsigned long)(MPOL_MF_STRICT |
MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) MPOL_MF_MOVE | MPOL_MF_MOVE_ALL))
|| mode > MPOL_MAX)
return -EINVAL; return -EINVAL;
if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE)) if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
return -EPERM; return -EPERM;
...@@ -804,7 +807,7 @@ static long do_mbind(unsigned long start, unsigned long len, ...@@ -804,7 +807,7 @@ static long do_mbind(unsigned long start, unsigned long len,
if (!new) if (!new)
flags |= MPOL_MF_DISCONTIG_OK; flags |= MPOL_MF_DISCONTIG_OK;
pr_debug("mbind %lx-%lx mode:%ld nodes:%lx\n",start,start+len, pr_debug("mbind %lx-%lx mode:%d nodes:%lx\n", start, start + len,
mode, nmask ? nodes_addr(*nmask)[0] : -1); mode, nmask ? nodes_addr(*nmask)[0] : -1);
down_write(&mm->mmap_sem); down_write(&mm->mmap_sem);
...@@ -905,6 +908,8 @@ asmlinkage long sys_mbind(unsigned long start, unsigned long len, ...@@ -905,6 +908,8 @@ asmlinkage long sys_mbind(unsigned long start, unsigned long len,
nodemask_t nodes; nodemask_t nodes;
int err; int err;
if (mode >= MPOL_MAX)
return -EINVAL;
err = get_nodes(&nodes, nmask, maxnode); err = get_nodes(&nodes, nmask, maxnode);
if (err) if (err)
return err; return err;
...@@ -918,7 +923,7 @@ asmlinkage long sys_set_mempolicy(int mode, unsigned long __user *nmask, ...@@ -918,7 +923,7 @@ asmlinkage long sys_set_mempolicy(int mode, unsigned long __user *nmask,
int err; int err;
nodemask_t nodes; nodemask_t nodes;
if (mode < 0 || mode > MPOL_MAX) if (mode < 0 || mode >= MPOL_MAX)
return -EINVAL; return -EINVAL;
err = get_nodes(&nodes, nmask, maxnode); err = get_nodes(&nodes, nmask, maxnode);
if (err) if (err)
...@@ -1201,7 +1206,7 @@ static unsigned interleave_nodes(struct mempolicy *policy) ...@@ -1201,7 +1206,7 @@ static unsigned interleave_nodes(struct mempolicy *policy)
*/ */
unsigned slab_node(struct mempolicy *policy) unsigned slab_node(struct mempolicy *policy)
{ {
int pol = policy ? policy->policy : MPOL_DEFAULT; unsigned short pol = policy ? policy->policy : MPOL_DEFAULT;
switch (pol) { switch (pol) {
case MPOL_INTERLEAVE: case MPOL_INTERLEAVE:
...@@ -1635,7 +1640,7 @@ static int shared_policy_replace(struct shared_policy *sp, unsigned long start, ...@@ -1635,7 +1640,7 @@ static int shared_policy_replace(struct shared_policy *sp, unsigned long start,
return 0; return 0;
} }
void mpol_shared_policy_init(struct shared_policy *info, int policy, void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
nodemask_t *policy_nodes) nodemask_t *policy_nodes)
{ {
info->root = RB_ROOT; info->root = RB_ROOT;
...@@ -1830,7 +1835,7 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol) ...@@ -1830,7 +1835,7 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
char *p = buffer; char *p = buffer;
int l; int l;
nodemask_t nodes; nodemask_t nodes;
int mode = pol ? pol->policy : MPOL_DEFAULT; unsigned short mode = pol ? pol->policy : MPOL_DEFAULT;
switch (mode) { switch (mode) {
case MPOL_DEFAULT: case MPOL_DEFAULT:
......
...@@ -1079,7 +1079,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) ...@@ -1079,7 +1079,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes) static int shmem_parse_mpol(char *value, unsigned short *policy,
nodemask_t *policy_nodes)
{ {
char *nodelist = strchr(value, ':'); char *nodelist = strchr(value, ':');
int err = 1; int err = 1;
...@@ -1128,7 +1129,7 @@ static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes) ...@@ -1128,7 +1129,7 @@ static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes)
return err; return err;
} }
static void shmem_show_mpol(struct seq_file *seq, int policy, static void shmem_show_mpol(struct seq_file *seq, unsigned short policy,
const nodemask_t policy_nodes) const nodemask_t policy_nodes)
{ {
char *policy_string; char *policy_string;
...@@ -1197,13 +1198,13 @@ static struct page *shmem_alloc_page(gfp_t gfp, ...@@ -1197,13 +1198,13 @@ static struct page *shmem_alloc_page(gfp_t gfp,
} }
#else /* !CONFIG_NUMA */ #else /* !CONFIG_NUMA */
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
static inline int shmem_parse_mpol(char *value, int *policy, static inline int shmem_parse_mpol(char *value, unsigned short *policy,
nodemask_t *policy_nodes) nodemask_t *policy_nodes)
{ {
return 1; return 1;
} }
static inline void shmem_show_mpol(struct seq_file *seq, int policy, static inline void shmem_show_mpol(struct seq_file *seq, unsigned short policy,
const nodemask_t policy_nodes) const nodemask_t policy_nodes)
{ {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment