diff options
author | David Rientjes <rientjes@google.com> | 2008-04-28 05:12:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-28 11:58:19 -0400 |
commit | a3b51e0142d1be156ac697eaadadd6cfbb7ba32b (patch) | |
tree | da9e527316f112c09f0bc16553c64e3c87125c82 | |
parent | 1b27d05b6e21249d2338be26dfcbe8f8d8ff8a5b (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>
-rw-r--r-- | include/linux/mempolicy.h | 19 | ||||
-rw-r--r-- | include/linux/shmem_fs.h | 2 | ||||
-rw-r--r-- | mm/mempolicy.c | 29 | ||||
-rw-r--r-- | mm/shmem.c | 9 |
4 files changed, 33 insertions, 26 deletions
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index b8b3da7a3315..389a06e8ee21 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h | |||
@@ -9,12 +9,13 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | /* Policies */ | 11 | /* Policies */ |
12 | #define MPOL_DEFAULT 0 | 12 | enum { |
13 | #define MPOL_PREFERRED 1 | 13 | MPOL_DEFAULT, |
14 | #define MPOL_BIND 2 | 14 | MPOL_PREFERRED, |
15 | #define MPOL_INTERLEAVE 3 | 15 | MPOL_BIND, |
16 | 16 | MPOL_INTERLEAVE, | |
17 | #define MPOL_MAX MPOL_INTERLEAVE | 17 | MPOL_MAX, /* always last member of enum */ |
18 | }; | ||
18 | 19 | ||
19 | /* Flags for get_mem_policy */ | 20 | /* Flags for get_mem_policy */ |
20 | #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */ | 21 | #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */ |
@@ -64,7 +65,7 @@ struct mm_struct; | |||
64 | */ | 65 | */ |
65 | struct mempolicy { | 66 | struct mempolicy { |
66 | atomic_t refcnt; | 67 | atomic_t refcnt; |
67 | short policy; /* See MPOL_* above */ | 68 | unsigned short policy; /* See MPOL_* above */ |
68 | union { | 69 | union { |
69 | short preferred_node; /* preferred */ | 70 | short preferred_node; /* preferred */ |
70 | nodemask_t nodes; /* interleave/bind */ | 71 | nodemask_t nodes; /* interleave/bind */ |
@@ -134,7 +135,7 @@ struct shared_policy { | |||
134 | spinlock_t lock; | 135 | spinlock_t lock; |
135 | }; | 136 | }; |
136 | 137 | ||
137 | void mpol_shared_policy_init(struct shared_policy *info, int policy, | 138 | void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy, |
138 | nodemask_t *nodes); | 139 | nodemask_t *nodes); |
139 | int mpol_set_shared_policy(struct shared_policy *info, | 140 | int mpol_set_shared_policy(struct shared_policy *info, |
140 | struct vm_area_struct *vma, | 141 | struct vm_area_struct *vma, |
@@ -202,7 +203,7 @@ static inline int mpol_set_shared_policy(struct shared_policy *info, | |||
202 | } | 203 | } |
203 | 204 | ||
204 | static inline void mpol_shared_policy_init(struct shared_policy *info, | 205 | static inline void mpol_shared_policy_init(struct shared_policy *info, |
205 | int policy, nodemask_t *nodes) | 206 | unsigned short policy, nodemask_t *nodes) |
206 | { | 207 | { |
207 | } | 208 | } |
208 | 209 | ||
diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 8d5fb36ea047..639a4070708e 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h | |||
@@ -34,7 +34,7 @@ struct shmem_sb_info { | |||
34 | uid_t uid; /* Mount uid for root directory */ | 34 | uid_t uid; /* Mount uid for root directory */ |
35 | gid_t gid; /* Mount gid for root directory */ | 35 | gid_t gid; /* Mount gid for root directory */ |
36 | mode_t mode; /* Mount mode for root directory */ | 36 | mode_t mode; /* Mount mode for root directory */ |
37 | int policy; /* Default NUMA memory alloc policy */ | 37 | unsigned short policy; /* Default NUMA memory alloc policy */ |
38 | nodemask_t policy_nodes; /* nodemask for preferred and bind */ | 38 | nodemask_t policy_nodes; /* nodemask for preferred and bind */ |
39 | }; | 39 | }; |
40 | 40 | ||
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 */ |
117 | static int mpol_check_policy(int mode, nodemask_t *nodes) | 117 | static 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 */ |
188 | static struct mempolicy *mpol_new(int mode, nodemask_t *nodes) | 190 | static 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 */ |
465 | static long do_set_mempolicy(int mode, nodemask_t *nodes) | 469 | static 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 | ||
761 | static long do_mbind(unsigned long start, unsigned long len, | 765 | static 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 | */ |
1202 | unsigned slab_node(struct mempolicy *policy) | 1207 | unsigned 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 | ||
1638 | void mpol_shared_policy_init(struct shared_policy *info, int policy, | 1643 | void 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 |
1082 | static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes) | 1082 | static 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 | ||
1131 | static void shmem_show_mpol(struct seq_file *seq, int policy, | 1132 | static 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 |
1200 | static inline int shmem_parse_mpol(char *value, int *policy, | 1201 | static 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 | ||
1206 | static inline void shmem_show_mpol(struct seq_file *seq, int policy, | 1207 | static 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 | } |