1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#ifndef _LINUX_BALLOON_COMPACTION_H
38#define _LINUX_BALLOON_COMPACTION_H
39#include <linux/pagemap.h>
40#include <linux/page-flags.h>
41#include <linux/migrate.h>
42#include <linux/gfp.h>
43#include <linux/err.h>
44#include <linux/fs.h>
45#include <linux/list.h>
46
47
48
49
50
51
52
53
54struct balloon_dev_info {
55 unsigned long isolated_pages;
56 spinlock_t pages_lock;
57 struct list_head pages;
58 int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
59 struct page *page, enum migrate_mode mode);
60 struct inode *inode;
61};
62
63extern struct page *balloon_page_alloc(void);
64extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
65 struct page *page);
66extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
67extern size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
68 struct list_head *pages);
69extern size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
70 struct list_head *pages, size_t n_req_pages);
71
72static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
73{
74 balloon->isolated_pages = 0;
75 spin_lock_init(&balloon->pages_lock);
76 INIT_LIST_HEAD(&balloon->pages);
77 balloon->migratepage = NULL;
78 balloon->inode = NULL;
79}
80
81#ifdef CONFIG_BALLOON_COMPACTION
82extern const struct address_space_operations balloon_aops;
83extern bool balloon_page_isolate(struct page *page,
84 isolate_mode_t mode);
85extern void balloon_page_putback(struct page *page);
86extern int balloon_page_migrate(struct address_space *mapping,
87 struct page *newpage,
88 struct page *page, enum migrate_mode mode);
89
90
91
92
93
94
95
96
97
98
99static inline void balloon_page_insert(struct balloon_dev_info *balloon,
100 struct page *page)
101{
102 __SetPageOffline(page);
103 __SetPageMovable(page, balloon->inode->i_mapping);
104 set_page_private(page, (unsigned long)balloon);
105 list_add(&page->lru, &balloon->pages);
106}
107
108
109
110
111
112
113
114
115
116static inline void balloon_page_delete(struct page *page)
117{
118 __ClearPageOffline(page);
119 __ClearPageMovable(page);
120 set_page_private(page, 0);
121
122
123
124
125 if (!PageIsolated(page))
126 list_del(&page->lru);
127}
128
129
130
131
132
133static inline struct balloon_dev_info *balloon_page_device(struct page *page)
134{
135 return (struct balloon_dev_info *)page_private(page);
136}
137
138static inline gfp_t balloon_mapping_gfp_mask(void)
139{
140 return GFP_HIGHUSER_MOVABLE;
141}
142
143#else
144
145static inline void balloon_page_insert(struct balloon_dev_info *balloon,
146 struct page *page)
147{
148 __SetPageOffline(page);
149 list_add(&page->lru, &balloon->pages);
150}
151
152static inline void balloon_page_delete(struct page *page)
153{
154 __ClearPageOffline(page);
155 list_del(&page->lru);
156}
157
158static inline bool balloon_page_isolate(struct page *page)
159{
160 return false;
161}
162
163static inline void balloon_page_putback(struct page *page)
164{
165 return;
166}
167
168static inline int balloon_page_migrate(struct page *newpage,
169 struct page *page, enum migrate_mode mode)
170{
171 return 0;
172}
173
174static inline gfp_t balloon_mapping_gfp_mask(void)
175{
176 return GFP_HIGHUSER;
177}
178
179#endif
180
181
182
183
184
185
186
187
188static inline void balloon_page_push(struct list_head *pages, struct page *page)
189{
190 list_add(&page->lru, pages);
191}
192
193
194
195
196
197
198
199
200static inline struct page *balloon_page_pop(struct list_head *pages)
201{
202 struct page *page = list_first_entry_or_null(pages, struct page, lru);
203
204 if (!page)
205 return NULL;
206
207 list_del(&page->lru);
208 return page;
209}
210#endif
211