[PATCH] mm: simplify build_zonelists_node by removing the case statement.
[deliverable/linux.git] / include / linux / mempolicy.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_MEMPOLICY_H
2#define _LINUX_MEMPOLICY_H 1
3
4#include <linux/errno.h>
5
6/*
7 * NUMA memory policies for Linux.
8 * Copyright 2003,2004 Andi Kleen SuSE Labs
9 */
10
11/* Policies */
12#define MPOL_DEFAULT 0
13#define MPOL_PREFERRED 1
14#define MPOL_BIND 2
15#define MPOL_INTERLEAVE 3
16
17#define MPOL_MAX MPOL_INTERLEAVE
18
19/* Flags for get_mem_policy */
20#define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
21#define MPOL_F_ADDR (1<<1) /* look up vma using address */
22
23/* Flags for mbind */
24#define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
25
26#ifdef __KERNEL__
27
28#include <linux/config.h>
29#include <linux/mmzone.h>
1da177e4
LT
30#include <linux/slab.h>
31#include <linux/rbtree.h>
32#include <linux/spinlock.h>
dfcd3c0d 33#include <linux/nodemask.h>
1da177e4
LT
34
35struct vm_area_struct;
36
37#ifdef CONFIG_NUMA
38
39/*
40 * Describe a memory policy.
41 *
42 * A mempolicy can be either associated with a process or with a VMA.
43 * For VMA related allocations the VMA policy is preferred, otherwise
44 * the process policy is used. Interrupts ignore the memory policy
45 * of the current process.
46 *
47 * Locking policy for interlave:
48 * In process context there is no locking because only the process accesses
49 * its own state. All vma manipulation is somewhat protected by a down_read on
b8072f09 50 * mmap_sem.
1da177e4
LT
51 *
52 * Freeing policy:
53 * When policy is MPOL_BIND v.zonelist is kmalloc'ed and must be kfree'd.
54 * All other policies don't have any external state. mpol_free() handles this.
55 *
56 * Copying policy objects:
57 * For MPOL_BIND the zonelist must be always duplicated. mpol_clone() does this.
58 */
59struct mempolicy {
60 atomic_t refcnt;
61 short policy; /* See MPOL_* above */
62 union {
63 struct zonelist *zonelist; /* bind */
64 short preferred_node; /* preferred */
dfcd3c0d 65 nodemask_t nodes; /* interleave */
1da177e4
LT
66 /* undefined for default */
67 } v;
68};
69
70/*
71 * Support for managing mempolicy data objects (clone, copy, destroy)
72 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
73 */
74
75extern void __mpol_free(struct mempolicy *pol);
76static inline void mpol_free(struct mempolicy *pol)
77{
78 if (pol)
79 __mpol_free(pol);
80}
81
82extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
83static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
84{
85 if (pol)
86 pol = __mpol_copy(pol);
87 return pol;
88}
89
90#define vma_policy(vma) ((vma)->vm_policy)
91#define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
92
93static inline void mpol_get(struct mempolicy *pol)
94{
95 if (pol)
96 atomic_inc(&pol->refcnt);
97}
98
99extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
100static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
101{
102 if (a == b)
103 return 1;
104 return __mpol_equal(a, b);
105}
106#define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
107
108/* Could later add inheritance of the process policy here. */
109
110#define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
111
1da177e4
LT
112/*
113 * Tree of shared policies for a shared memory region.
114 * Maintain the policies in a pseudo mm that contains vmas. The vmas
115 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
116 * bytes, so that we can work with shared memory segments bigger than
117 * unsigned long.
118 */
119
120struct sp_node {
121 struct rb_node nd;
122 unsigned long start, end;
123 struct mempolicy *policy;
124};
125
126struct shared_policy {
127 struct rb_root root;
128 spinlock_t lock;
129};
130
131static inline void mpol_shared_policy_init(struct shared_policy *info)
132{
133 info->root = RB_ROOT;
134 spin_lock_init(&info->lock);
135}
136
137int mpol_set_shared_policy(struct shared_policy *info,
138 struct vm_area_struct *vma,
139 struct mempolicy *new);
140void mpol_free_shared_policy(struct shared_policy *p);
141struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
142 unsigned long idx);
143
6e21c8f1
CL
144struct mempolicy *get_vma_policy(struct task_struct *task,
145 struct vm_area_struct *vma, unsigned long addr);
146
1da177e4
LT
147extern void numa_default_policy(void);
148extern void numa_policy_init(void);
68860ec1 149extern void numa_policy_rebind(const nodemask_t *old, const nodemask_t *new);
d42c6997 150extern struct mempolicy default_policy;
5da7ca86
CL
151extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
152 unsigned long addr);
1da177e4
LT
153
154#else
155
156struct mempolicy {};
157
158static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
159{
160 return 1;
161}
162#define vma_mpol_equal(a,b) 1
163
164#define mpol_set_vma_default(vma) do {} while(0)
165
166static inline void mpol_free(struct mempolicy *p)
167{
168}
169
170static inline void mpol_get(struct mempolicy *pol)
171{
172}
173
174static inline struct mempolicy *mpol_copy(struct mempolicy *old)
175{
176 return NULL;
177}
178
1da177e4
LT
179struct shared_policy {};
180
181static inline int mpol_set_shared_policy(struct shared_policy *info,
182 struct vm_area_struct *vma,
183 struct mempolicy *new)
184{
185 return -EINVAL;
186}
187
188static inline void mpol_shared_policy_init(struct shared_policy *info)
189{
190}
191
192static inline void mpol_free_shared_policy(struct shared_policy *p)
193{
194}
195
196static inline struct mempolicy *
197mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
198{
199 return NULL;
200}
201
202#define vma_policy(vma) NULL
203#define vma_set_policy(vma, pol) do {} while(0)
204
205static inline void numa_policy_init(void)
206{
207}
208
209static inline void numa_default_policy(void)
210{
211}
212
68860ec1
PJ
213static inline void numa_policy_rebind(const nodemask_t *old,
214 const nodemask_t *new)
215{
216}
217
5da7ca86
CL
218static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
219 unsigned long addr)
220{
221 return NODE_DATA(0)->node_zonelists + gfp_zone(GFP_HIGHUSER);
222}
223
1da177e4
LT
224#endif /* CONFIG_NUMA */
225#endif /* __KERNEL__ */
226
227#endif
This page took 0.090973 seconds and 5 git commands to generate.