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/spinlock.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 spinlock_t lock;
29#ifdef CONFIG_KSM
30 atomic_t ksm_refcount;
31#endif
32
33
34
35
36
37
38
39
40 struct list_head head;
41};
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56struct anon_vma_chain {
57 struct vm_area_struct *vma;
58 struct anon_vma *anon_vma;
59 struct list_head same_vma;
60 struct list_head same_anon_vma;
61};
62
63#ifdef CONFIG_MMU
64#ifdef CONFIG_KSM
65static inline void ksm_refcount_init(struct anon_vma *anon_vma)
66{
67 atomic_set(&anon_vma->ksm_refcount, 0);
68}
69
70static inline int ksm_refcount(struct anon_vma *anon_vma)
71{
72 return atomic_read(&anon_vma->ksm_refcount);
73}
74#else
75static inline void ksm_refcount_init(struct anon_vma *anon_vma)
76{
77}
78
79static inline int ksm_refcount(struct anon_vma *anon_vma)
80{
81 return 0;
82}
83#endif
84
85static inline struct anon_vma *page_anon_vma(struct page *page)
86{
87 if (((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) !=
88 PAGE_MAPPING_ANON)
89 return NULL;
90 return page_rmapping(page);
91}
92
93static inline void anon_vma_lock(struct vm_area_struct *vma)
94{
95 struct anon_vma *anon_vma = vma->anon_vma;
96 if (anon_vma)
97 spin_lock(&anon_vma->lock);
98}
99
100static inline void anon_vma_unlock(struct vm_area_struct *vma)
101{
102 struct anon_vma *anon_vma = vma->anon_vma;
103 if (anon_vma)
104 spin_unlock(&anon_vma->lock);
105}
106
107
108
109
110void anon_vma_init(void);
111int anon_vma_prepare(struct vm_area_struct *);
112void unlink_anon_vmas(struct vm_area_struct *);
113int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
114int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
115void __anon_vma_link(struct vm_area_struct *);
116void anon_vma_free(struct anon_vma *);
117
118static inline void anon_vma_merge(struct vm_area_struct *vma,
119 struct vm_area_struct *next)
120{
121 VM_BUG_ON(vma->anon_vma != next->anon_vma);
122 unlink_anon_vmas(next);
123}
124
125
126
127
128void page_move_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
129void page_add_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
130void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, unsigned long);
131void page_add_file_rmap(struct page *);
132void page_remove_rmap(struct page *);
133
134static inline void page_dup_rmap(struct page *page)
135{
136 atomic_inc(&page->_mapcount);
137}
138
139
140
141
142int page_referenced(struct page *, int is_locked,
143 struct mem_cgroup *cnt, unsigned long *vm_flags);
144int page_referenced_one(struct page *, struct vm_area_struct *,
145 unsigned long address, unsigned int *mapcount, unsigned long *vm_flags);
146
147enum ttu_flags {
148 TTU_UNMAP = 0,
149 TTU_MIGRATION = 1,
150 TTU_MUNLOCK = 2,
151 TTU_ACTION_MASK = 0xff,
152
153 TTU_IGNORE_MLOCK = (1 << 8),
154 TTU_IGNORE_ACCESS = (1 << 9),
155 TTU_IGNORE_HWPOISON = (1 << 10),
156};
157#define TTU_ACTION(x) ((x) & TTU_ACTION_MASK)
158
159int try_to_unmap(struct page *, enum ttu_flags flags);
160int try_to_unmap_one(struct page *, struct vm_area_struct *,
161 unsigned long address, enum ttu_flags flags);
162
163
164
165
166pte_t *page_check_address(struct page *, struct mm_struct *,
167 unsigned long, spinlock_t **, int);
168
169
170
171
172unsigned long page_address_in_vma(struct page *, struct vm_area_struct *);
173
174
175
176
177
178
179
180int page_mkclean(struct page *);
181
182
183
184
185
186int try_to_munlock(struct page *);
187
188
189
190
191struct anon_vma *page_lock_anon_vma(struct page *page);
192void page_unlock_anon_vma(struct anon_vma *anon_vma);
193int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma);
194
195
196
197
198int rmap_walk(struct page *page, int (*rmap_one)(struct page *,
199 struct vm_area_struct *, unsigned long, void *), void *arg);
200
201#else
202
203#define anon_vma_init() do {} while (0)
204#define anon_vma_prepare(vma) (0)
205#define anon_vma_link(vma) do {} while (0)
206
207static inline int page_referenced(struct page *page, int is_locked,
208 struct mem_cgroup *cnt,
209 unsigned long *vm_flags)
210{
211 *vm_flags = 0;
212 return 0;
213}
214
215#define try_to_unmap(page, refs) SWAP_FAIL
216
217static inline int page_mkclean(struct page *page)
218{
219 return 0;
220}
221
222
223#endif
224
225
226
227
228#define SWAP_SUCCESS 0
229#define SWAP_AGAIN 1
230#define SWAP_FAIL 2
231#define SWAP_MLOCK 3
232
233#endif
234