aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2008-04-28 05:12:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-28 11:58:19 -0400
commita3b51e0142d1be156ac697eaadadd6cfbb7ba32b (patch)
treeda9e527316f112c09f0bc16553c64e3c87125c82 /mm
parent1b27d05b6e21249d2338be26dfcbe8f8d8ff8a5b (diff)
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: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/mempolicy.c29
-rw-r--r--mm/shmem.c9
2 files changed, 22 insertions, 16 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index acb5ee3587c3..1311dc4a3888 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -114,7 +114,7 @@ static void mpol_rebind_policy(struct mempolicy *pol,
114 const nodemask_t *newmask); 114 const nodemask_t *newmask);
115 115
116/* Do sanity checking on a policy */ 116/* Do sanity checking on a policy */
117static int mpol_check_policy(int mode, nodemask_t *nodes) 117static int mpol_check_policy(unsigned short mode, nodemask_t *nodes)
118{ 118{
119 int was_empty, is_empty; 119 int was_empty, is_empty;
120 120
@@ -159,6 +159,8 @@ static int mpol_check_policy(int mode, nodemask_t *nodes)
159 if (!was_empty && is_empty) 159 if (!was_empty && is_empty)
160 return -EINVAL; 160 return -EINVAL;
161 break; 161 break;
162 default:
163 BUG();
162 } 164 }
163 return 0; 165 return 0;
164} 166}
@@ -185,7 +187,7 @@ static int is_valid_nodemask(nodemask_t *nodemask)
185} 187}
186 188
187/* Create a new policy */ 189/* Create a new policy */
188static struct mempolicy *mpol_new(int mode, nodemask_t *nodes) 190static struct mempolicy *mpol_new(unsigned short mode, nodemask_t *nodes)
189{ 191{
190 struct mempolicy *policy; 192 struct mempolicy *policy;
191 193
@@ -218,6 +220,8 @@ static struct mempolicy *mpol_new(int mode, nodemask_t *nodes)
218 } 220 }
219 policy->v.nodes = *nodes; 221 policy->v.nodes = *nodes;
220 break; 222 break;
223 default:
224 BUG();
221 } 225 }
222 policy->policy = mode; 226 policy->policy = mode;
223 policy->cpuset_mems_allowed = cpuset_mems_allowed(current); 227 policy->cpuset_mems_allowed = cpuset_mems_allowed(current);
@@ -462,7 +466,7 @@ static void mpol_set_task_struct_flag(void)
462} 466}
463 467
464/* Set the process memory policy */ 468/* Set the process memory policy */
465static long do_set_mempolicy(int mode, nodemask_t *nodes) 469static long do_set_mempolicy(unsigned short mode, nodemask_t *nodes)
466{ 470{
467 struct mempolicy *new; 471 struct mempolicy *new;
468 472
@@ -759,7 +763,7 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
759#endif 763#endif
760 764
761static long do_mbind(unsigned long start, unsigned long len, 765static long do_mbind(unsigned long start, unsigned long len,
762 unsigned long mode, nodemask_t *nmask, 766 unsigned short mode, nodemask_t *nmask,
763 unsigned long flags) 767 unsigned long flags)
764{ 768{
765 struct vm_area_struct *vma; 769 struct vm_area_struct *vma;
@@ -769,9 +773,8 @@ static long do_mbind(unsigned long start, unsigned long len,
769 int err; 773 int err;
770 LIST_HEAD(pagelist); 774 LIST_HEAD(pagelist);
771 775
772 if ((flags & ~(unsigned long)(MPOL_MF_STRICT | 776 if (flags & ~(unsigned long)(MPOL_MF_STRICT |
773 MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) 777 MPOL_MF_MOVE | MPOL_MF_MOVE_ALL))
774 || mode > MPOL_MAX)
775 return -EINVAL; 778 return -EINVAL;
776 if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE)) 779 if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
777 return -EPERM; 780 return -EPERM;
@@ -804,7 +807,7 @@ static long do_mbind(unsigned long start, unsigned long len,
804 if (!new) 807 if (!new)
805 flags |= MPOL_MF_DISCONTIG_OK; 808 flags |= MPOL_MF_DISCONTIG_OK;
806 809
807 pr_debug("mbind %lx-%lx mode:%ld nodes:%lx\n",start,start+len, 810 pr_debug("mbind %lx-%lx mode:%d nodes:%lx\n", start, start + len,
808 mode, nmask ? nodes_addr(*nmask)[0] : -1); 811 mode, nmask ? nodes_addr(*nmask)[0] : -1);
809 812
810 down_write(&mm->mmap_sem); 813 down_write(&mm->mmap_sem);
@@ -905,6 +908,8 @@ asmlinkage long sys_mbind(unsigned long start, unsigned long len,
905 nodemask_t nodes; 908 nodemask_t nodes;
906 int err; 909 int err;
907 910
911 if (mode >= MPOL_MAX)
912 return -EINVAL;
908 err = get_nodes(&nodes, nmask, maxnode); 913 err = get_nodes(&nodes, nmask, maxnode);
909 if (err) 914 if (err)
910 return err; 915 return err;
@@ -918,7 +923,7 @@ asmlinkage long sys_set_mempolicy(int mode, unsigned long __user *nmask,
918 int err; 923 int err;
919 nodemask_t nodes; 924 nodemask_t nodes;
920 925
921 if (mode < 0 || mode > MPOL_MAX) 926 if (mode < 0 || mode >= MPOL_MAX)
922 return -EINVAL; 927 return -EINVAL;
923 err = get_nodes(&nodes, nmask, maxnode); 928 err = get_nodes(&nodes, nmask, maxnode);
924 if (err) 929 if (err)
@@ -1201,7 +1206,7 @@ static unsigned interleave_nodes(struct mempolicy *policy)
1201 */ 1206 */
1202unsigned slab_node(struct mempolicy *policy) 1207unsigned slab_node(struct mempolicy *policy)
1203{ 1208{
1204 int pol = policy ? policy->policy : MPOL_DEFAULT; 1209 unsigned short pol = policy ? policy->policy : MPOL_DEFAULT;
1205 1210
1206 switch (pol) { 1211 switch (pol) {
1207 case MPOL_INTERLEAVE: 1212 case MPOL_INTERLEAVE:
@@ -1635,7 +1640,7 @@ restart:
1635 return 0; 1640 return 0;
1636} 1641}
1637 1642
1638void mpol_shared_policy_init(struct shared_policy *info, int policy, 1643void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
1639 nodemask_t *policy_nodes) 1644 nodemask_t *policy_nodes)
1640{ 1645{
1641 info->root = RB_ROOT; 1646 info->root = RB_ROOT;
@@ -1830,7 +1835,7 @@ static inline int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
1830 char *p = buffer; 1835 char *p = buffer;
1831 int l; 1836 int l;
1832 nodemask_t nodes; 1837 nodemask_t nodes;
1833 int mode = pol ? pol->policy : MPOL_DEFAULT; 1838 unsigned short mode = pol ? pol->policy : MPOL_DEFAULT;
1834 1839
1835 switch (mode) { 1840 switch (mode) {
1836 case MPOL_DEFAULT: 1841 case MPOL_DEFAULT:
diff --git a/mm/shmem.c b/mm/shmem.c
index f514dd392cd9..d8ef7ba831a5 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1079,7 +1079,8 @@ redirty:
1079 1079
1080#ifdef CONFIG_NUMA 1080#ifdef CONFIG_NUMA
1081#ifdef CONFIG_TMPFS 1081#ifdef CONFIG_TMPFS
1082static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes) 1082static int shmem_parse_mpol(char *value, unsigned short *policy,
1083 nodemask_t *policy_nodes)
1083{ 1084{
1084 char *nodelist = strchr(value, ':'); 1085 char *nodelist = strchr(value, ':');
1085 int err = 1; 1086 int err = 1;
@@ -1128,7 +1129,7 @@ out:
1128 return err; 1129 return err;
1129} 1130}
1130 1131
1131static void shmem_show_mpol(struct seq_file *seq, int policy, 1132static void shmem_show_mpol(struct seq_file *seq, unsigned short policy,
1132 const nodemask_t policy_nodes) 1133 const nodemask_t policy_nodes)
1133{ 1134{
1134 char *policy_string; 1135 char *policy_string;
@@ -1197,13 +1198,13 @@ static struct page *shmem_alloc_page(gfp_t gfp,
1197} 1198}
1198#else /* !CONFIG_NUMA */ 1199#else /* !CONFIG_NUMA */
1199#ifdef CONFIG_TMPFS 1200#ifdef CONFIG_TMPFS
1200static inline int shmem_parse_mpol(char *value, int *policy, 1201static inline int shmem_parse_mpol(char *value, unsigned short *policy,
1201 nodemask_t *policy_nodes) 1202 nodemask_t *policy_nodes)
1202{ 1203{
1203 return 1; 1204 return 1;
1204} 1205}
1205 1206
1206static inline void shmem_show_mpol(struct seq_file *seq, int policy, 1207static inline void shmem_show_mpol(struct seq_file *seq, unsigned short policy,
1207 const nodemask_t policy_nodes) 1208 const nodemask_t policy_nodes)
1208{ 1209{
1209} 1210}