]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/mempolicy.h
mempolicy: rename struct mempolicy 'policy' member to 'mode'
[net-next-2.6.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
028fec41
DR
11/*
12 * Both the MPOL_* mempolicy mode and the MPOL_F_* optional mode flags are
13 * passed by the user to either set_mempolicy() or mbind() in an 'int' actual.
14 * The MPOL_MODE_FLAGS macro determines the legal set of optional mode flags.
15 */
16
1da177e4 17/* Policies */
a3b51e01
DR
18enum {
19 MPOL_DEFAULT,
20 MPOL_PREFERRED,
21 MPOL_BIND,
22 MPOL_INTERLEAVE,
23 MPOL_MAX, /* always last member of enum */
24};
1da177e4 25
028fec41 26/* Flags for set_mempolicy */
f5b087b5 27#define MPOL_F_STATIC_NODES (1 << 15)
4c50bc01 28#define MPOL_F_RELATIVE_NODES (1 << 14)
f5b087b5 29
028fec41
DR
30/*
31 * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to
32 * either set_mempolicy() or mbind().
33 */
4c50bc01 34#define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES)
028fec41
DR
35
36/* Flags for get_mempolicy */
1da177e4
LT
37#define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
38#define MPOL_F_ADDR (1<<1) /* look up vma using address */
754af6f5 39#define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
1da177e4
LT
40
41/* Flags for mbind */
42#define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
dc9aa5b9
CL
43#define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
44#define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
45#define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
1da177e4
LT
46
47#ifdef __KERNEL__
48
1da177e4 49#include <linux/mmzone.h>
1da177e4
LT
50#include <linux/slab.h>
51#include <linux/rbtree.h>
52#include <linux/spinlock.h>
dfcd3c0d 53#include <linux/nodemask.h>
1da177e4 54
45b35a5c 55struct mm_struct;
1da177e4
LT
56
57#ifdef CONFIG_NUMA
58
59/*
60 * Describe a memory policy.
61 *
62 * A mempolicy can be either associated with a process or with a VMA.
63 * For VMA related allocations the VMA policy is preferred, otherwise
64 * the process policy is used. Interrupts ignore the memory policy
65 * of the current process.
66 *
67 * Locking policy for interlave:
68 * In process context there is no locking because only the process accesses
69 * its own state. All vma manipulation is somewhat protected by a down_read on
b8072f09 70 * mmap_sem.
1da177e4
LT
71 *
72 * Freeing policy:
19770b32 73 * Mempolicy objects are reference counted. A mempolicy will be freed when
f0be3d32 74 * mpol_put() decrements the reference count to zero.
1da177e4 75 *
846a16bf
LS
76 * Duplicating policy objects:
77 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
19770b32 78 * to the new storage. The reference count of the new object is initialized
846a16bf 79 * to 1, representing the caller of mpol_dup().
1da177e4
LT
80 */
81struct mempolicy {
82 atomic_t refcnt;
45c4745a 83 unsigned short mode; /* See MPOL_* above */
028fec41 84 unsigned short flags; /* See set_mempolicy() MPOL_F_* above */
1da177e4 85 union {
1da177e4 86 short preferred_node; /* preferred */
19770b32 87 nodemask_t nodes; /* interleave/bind */
1da177e4
LT
88 /* undefined for default */
89 } v;
f5b087b5
DR
90 union {
91 nodemask_t cpuset_mems_allowed; /* relative to these nodes */
92 nodemask_t user_nodemask; /* nodemask passed by user */
93 } w;
1da177e4
LT
94};
95
96/*
97 * Support for managing mempolicy data objects (clone, copy, destroy)
98 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
99 */
100
f0be3d32
LS
101extern void __mpol_put(struct mempolicy *pol);
102static inline void mpol_put(struct mempolicy *pol)
1da177e4
LT
103{
104 if (pol)
f0be3d32 105 __mpol_put(pol);
1da177e4
LT
106}
107
846a16bf
LS
108extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
109static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
1da177e4
LT
110{
111 if (pol)
846a16bf 112 pol = __mpol_dup(pol);
1da177e4
LT
113 return pol;
114}
115
116#define vma_policy(vma) ((vma)->vm_policy)
117#define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
118
119static inline void mpol_get(struct mempolicy *pol)
120{
121 if (pol)
122 atomic_inc(&pol->refcnt);
123}
124
125extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
126static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
127{
128 if (a == b)
129 return 1;
130 return __mpol_equal(a, b);
131}
1da177e4 132
1da177e4
LT
133/*
134 * Tree of shared policies for a shared memory region.
135 * Maintain the policies in a pseudo mm that contains vmas. The vmas
136 * carry the policy. As a special twist the pseudo mm is indexed in pages, not
137 * bytes, so that we can work with shared memory segments bigger than
138 * unsigned long.
139 */
140
141struct sp_node {
142 struct rb_node nd;
143 unsigned long start, end;
144 struct mempolicy *policy;
145};
146
147struct shared_policy {
148 struct rb_root root;
149 spinlock_t lock;
150};
151
45c4745a 152void mpol_shared_policy_init(struct shared_policy *info, unsigned short mode,
028fec41 153 unsigned short flags, nodemask_t *nodes);
1da177e4
LT
154int mpol_set_shared_policy(struct shared_policy *info,
155 struct vm_area_struct *vma,
156 struct mempolicy *new);
157void mpol_free_shared_policy(struct shared_policy *p);
158struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
159 unsigned long idx);
160
161extern void numa_default_policy(void);
162extern void numa_policy_init(void);
74cb2155
PJ
163extern void mpol_rebind_task(struct task_struct *tsk,
164 const nodemask_t *new);
4225399a 165extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
c61afb18 166extern void mpol_fix_fork_child_flag(struct task_struct *p);
4225399a 167
5da7ca86 168extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
19770b32
MG
169 unsigned long addr, gfp_t gfp_flags,
170 struct mempolicy **mpol, nodemask_t **nodemask);
dc85da15 171extern unsigned slab_node(struct mempolicy *policy);
1da177e4 172
2f6726e5 173extern enum zone_type policy_zone;
4be38e35 174
2f6726e5 175static inline void check_highest_zone(enum zone_type k)
4be38e35 176{
b377fd39 177 if (k > policy_zone && k != ZONE_MOVABLE)
4be38e35
CL
178 policy_zone = k;
179}
180
39743889
CL
181int do_migrate_pages(struct mm_struct *mm,
182 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
183
1da177e4
LT
184#else
185
186struct mempolicy {};
187
188static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
189{
190 return 1;
191}
1da177e4 192
f0be3d32 193static inline void mpol_put(struct mempolicy *p)
1da177e4
LT
194{
195}
196
197static inline void mpol_get(struct mempolicy *pol)
198{
199}
200
846a16bf 201static inline struct mempolicy *mpol_dup(struct mempolicy *old)
1da177e4
LT
202{
203 return NULL;
204}
205
1da177e4
LT
206struct shared_policy {};
207
208static inline int mpol_set_shared_policy(struct shared_policy *info,
209 struct vm_area_struct *vma,
210 struct mempolicy *new)
211{
212 return -EINVAL;
213}
214
7339ff83 215static inline void mpol_shared_policy_init(struct shared_policy *info,
45c4745a 216 unsigned short mode, unsigned short flags, nodemask_t *nodes)
1da177e4
LT
217{
218}
219
220static inline void mpol_free_shared_policy(struct shared_policy *p)
221{
222}
223
224static inline struct mempolicy *
225mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
226{
227 return NULL;
228}
229
230#define vma_policy(vma) NULL
231#define vma_set_policy(vma, pol) do {} while(0)
232
233static inline void numa_policy_init(void)
234{
235}
236
237static inline void numa_default_policy(void)
238{
239}
240
74cb2155 241static inline void mpol_rebind_task(struct task_struct *tsk,
68860ec1
PJ
242 const nodemask_t *new)
243{
244}
245
4225399a
PJ
246static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
247{
248}
249
c61afb18
PJ
250static inline void mpol_fix_fork_child_flag(struct task_struct *p)
251{
252}
253
5da7ca86 254static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
19770b32
MG
255 unsigned long addr, gfp_t gfp_flags,
256 struct mempolicy **mpol, nodemask_t **nodemask)
5da7ca86 257{
19770b32
MG
258 *mpol = NULL;
259 *nodemask = NULL;
0e88460d 260 return node_zonelist(0, gfp_flags);
5da7ca86
CL
261}
262
45b07ef3
PJ
263static inline int do_migrate_pages(struct mm_struct *mm,
264 const nodemask_t *from_nodes,
265 const nodemask_t *to_nodes, int flags)
266{
267 return 0;
268}
269
4be38e35
CL
270static inline void check_highest_zone(int k)
271{
272}
1da177e4
LT
273#endif /* CONFIG_NUMA */
274#endif /* __KERNEL__ */
275
276#endif