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