1#ifndef _LINUX_RMAP_H
2#define _LINUX_RMAP_H
3
4
5
6
7#include <linux/list.h>
8#include <linux/slab.h>
9#include <linux/mm.h>
10#include <linux/rwsem.h>
11#include <linux/memcontrol.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27struct anon_vma {
28 struct anon_vma *root;
29 struct rw_semaphore rwsem;
30
31
32
33
34
35
36
37 atomic_t refcount;
38
39
40
41
42
43
44
45 unsigned degree;
46
47 struct anon_vma *parent;
48
49
50
51
52
53
54
55
56
57 struct rb_root rb_root;
58};
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73struct anon_vma_chain {
74 struct vm_area_struct *vma;
75 struct anon_vma *anon_vma;
76 struct list_head same_vma;
77 struct rb_node rb;
78 unsigned long rb_subtree_last;
79#ifdef CONFIG_DEBUG_VM_RB
80 unsigned long cached_vma_start, cached_vma_last;
81#endif
82};
83
84enum ttu_flags {
85 TTU_UNMAP = 1,
86 TTU_MIGRATION = 2,
87 TTU_MUNLOCK = 4,
88
89 TTU_IGNORE_MLOCK = (1 << 8),
90 TTU_IGNORE_ACCESS = (1 << 9),
91 TTU_IGNORE_HWPOISON = (1 << 10),
92};
93
94#ifdef CONFIG_MMU
95static inline void get_anon_vma(struct anon_vma *anon_vma)
96{
97 atomic_inc(&anon_vma->refcount);
98}
99
100void __put_anon_vma(struct anon_vma *anon_vma);
101
102static inline void put_anon_vma(struct anon_vma *anon_vma)
103{
104 if (atomic_dec_and_test(&anon_vma->refcount))
105 __put_anon_vma(anon_vma);
106}
107
108static inline struct anon_vma *page_anon_vma(struct page *page)
109{
110 if (((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) !=
111 PAGE_MAPPING_ANON)
112 return NULL;
113 return page_rmapping(page);
114}
115
116static inline void vma_lock_anon_vma(struct vm_area_struct *vma)
117{
118 struct anon_vma *anon_vma = vma->anon_vma;
119 if (anon_vma)
120 down_write(&anon_vma->root->rwsem);
121}
122
123static inline void vma_unlock_anon_vma(struct vm_area_struct *vma)
124{
125 struct anon_vma *anon_vma = vma->anon_vma;
126 if (anon_vma)
127 up_write(&anon_vma->root->rwsem);
128}
129
130static inline void anon_vma_lock_write(struct anon_vma *anon_vma)
131{
132 down_write(&anon_vma->root->rwsem);
133}
134
135static inline void anon_vma_unlock_write(struct anon_vma *anon_vma)
136{
137 up_write(&anon_vma->root->rwsem);
138}
139
140static inline void anon_vma_lock_read(struct anon_vma *anon_vma)
141{
142 down_read(&anon_vma->root->rwsem);
143}
144
145static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
146{
147 up_read(&anon_vma->root->rwsem);
148}
149
150
151
152
153
154void anon_vma_init(void);
155int anon_vma_prepare(struct vm_area_struct *);
156void unlink_anon_vmas(struct vm_area_struct *);
157int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
158int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
159
160static inline void anon_vma_merge(struct vm_area_struct *vma,
161 struct vm_area_struct *next)
162{
163 VM_BUG_ON_VMA(vma->anon_vma != next->anon_vma, vma);
164 unlink_anon_vmas(next);
165}
166
167struct anon_vma *page_get_anon_vma(struct page *page);
168
169
170
171
172void page_move_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
173void page_add_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
174void do_page_add_anon_rmap(struct page *, struct vm_area_struct *,
175 unsigned long, int);
176void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
177void page_add_file_rmap(struct page *);
178void page_remove_rmap(struct page *);
179
180void hugepage_add_anon_rmap(struct page *, struct vm_area_struct *,
181 unsigned long);
182void hugepage_add_new_anon_rmap(struct page *, struct vm_area_struct *,
183 unsigned long);
184
185static inline void page_dup_rmap(struct page *page)
186{
187 atomic_inc(&page->_mapcount);
188}
189
190
191
192
193int page_referenced(struct page *, int is_locked,
194 struct mem_cgroup *memcg, unsigned long *vm_flags);
195
196#define TTU_ACTION(x) ((x) & TTU_ACTION_MASK)
197
198int try_to_unmap(struct page *, enum ttu_flags flags);
199
200
201
202
203pte_t *__page_check_address(struct page *, struct mm_struct *,
204 unsigned long, spinlock_t **, int);
205
206static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
207 unsigned long address,
208 spinlock_t **ptlp, int sync)
209{
210 pte_t *ptep;
211
212 __cond_lock(*ptlp, ptep = __page_check_address(page, mm, address,
213 ptlp, sync));
214 return ptep;
215}
216
217
218
219
220unsigned long page_address_in_vma(struct page *, struct vm_area_struct *);
221
222
223
224
225
226
227
228int page_mkclean(struct page *);
229
230
231
232
233
234int try_to_munlock(struct page *);
235
236
237
238
239struct anon_vma *page_lock_anon_vma_read(struct page *page);
240void page_unlock_anon_vma_read(struct anon_vma *anon_vma);
241int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma);
242
243
244
245
246
247
248
249
250
251
252
253struct rmap_walk_control {
254 void *arg;
255 int (*rmap_one)(struct page *page, struct vm_area_struct *vma,
256 unsigned long addr, void *arg);
257 int (*done)(struct page *page);
258 int (*file_nonlinear)(struct page *, struct address_space *, void *arg);
259 struct anon_vma *(*anon_lock)(struct page *page);
260 bool (*invalid_vma)(struct vm_area_struct *vma, void *arg);
261};
262
263int rmap_walk(struct page *page, struct rmap_walk_control *rwc);
264
265#else
266
267#define anon_vma_init() do {} while (0)
268#define anon_vma_prepare(vma) (0)
269#define anon_vma_link(vma) do {} while (0)
270
271static inline int page_referenced(struct page *page, int is_locked,
272 struct mem_cgroup *memcg,
273 unsigned long *vm_flags)
274{
275 *vm_flags = 0;
276 return 0;
277}
278
279#define try_to_unmap(page, refs) SWAP_FAIL
280
281static inline int page_mkclean(struct page *page)
282{
283 return 0;
284}
285
286
287#endif
288
289
290
291
292#define SWAP_SUCCESS 0
293#define SWAP_AGAIN 1
294#define SWAP_FAIL 2
295#define SWAP_MLOCK 3
296
297#endif
298