aboutsummaryrefslogtreecommitdiffstats
path: root/mm/balloon_compaction.c
diff options
context:
space:
mode:
authorKonstantin Khlebnikov <k.khlebnikov@samsung.com>2014-10-09 18:29:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:26:01 -0400
commit9d1ba8056474a208ed9efb7e58cd014795d9f818 (patch)
tree0a463b12b5ed28e666570b6b15051af1b5d93934 /mm/balloon_compaction.c
parentd6d86c0a7f8ddc5b38cf089222cb1d9540762dc2 (diff)
mm/balloon_compaction: remove balloon mapping and flag AS_BALLOON_MAP
Now ballooned pages are detected using PageBalloon(). Fake mapping is no longer required. This patch links ballooned pages to balloon device using field page->private instead of page->mapping. Also this patch embeds balloon_dev_info directly into struct virtio_balloon. Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com> Cc: Rafael Aquini <aquini@redhat.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/balloon_compaction.c')
-rw-r--r--mm/balloon_compaction.c95
1 files changed, 6 insertions, 89 deletions
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 52abeeb3cb9d..3afdabdbc0a4 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -11,32 +11,6 @@
11#include <linux/balloon_compaction.h> 11#include <linux/balloon_compaction.h>
12 12
13/* 13/*
14 * balloon_devinfo_alloc - allocates a balloon device information descriptor.
15 * @balloon_dev_descriptor: pointer to reference the balloon device which
16 * this struct balloon_dev_info will be servicing.
17 *
18 * Driver must call it to properly allocate and initialize an instance of
19 * struct balloon_dev_info which will be used to reference a balloon device
20 * as well as to keep track of the balloon device page list.
21 */
22struct balloon_dev_info *balloon_devinfo_alloc(void *balloon_dev_descriptor)
23{
24 struct balloon_dev_info *b_dev_info;
25 b_dev_info = kmalloc(sizeof(*b_dev_info), GFP_KERNEL);
26 if (!b_dev_info)
27 return ERR_PTR(-ENOMEM);
28
29 b_dev_info->balloon_device = balloon_dev_descriptor;
30 b_dev_info->mapping = NULL;
31 b_dev_info->isolated_pages = 0;
32 spin_lock_init(&b_dev_info->pages_lock);
33 INIT_LIST_HEAD(&b_dev_info->pages);
34
35 return b_dev_info;
36}
37EXPORT_SYMBOL_GPL(balloon_devinfo_alloc);
38
39/*
40 * balloon_page_enqueue - allocates a new page and inserts it into the balloon 14 * balloon_page_enqueue - allocates a new page and inserts it into the balloon
41 * page list. 15 * page list.
42 * @b_dev_info: balloon device decriptor where we will insert a new page to 16 * @b_dev_info: balloon device decriptor where we will insert a new page to
@@ -61,7 +35,7 @@ struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info)
61 */ 35 */
62 BUG_ON(!trylock_page(page)); 36 BUG_ON(!trylock_page(page));
63 spin_lock_irqsave(&b_dev_info->pages_lock, flags); 37 spin_lock_irqsave(&b_dev_info->pages_lock, flags);
64 balloon_page_insert(page, b_dev_info->mapping, &b_dev_info->pages); 38 balloon_page_insert(b_dev_info, page);
65 spin_unlock_irqrestore(&b_dev_info->pages_lock, flags); 39 spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
66 unlock_page(page); 40 unlock_page(page);
67 return page; 41 return page;
@@ -127,60 +101,10 @@ struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
127EXPORT_SYMBOL_GPL(balloon_page_dequeue); 101EXPORT_SYMBOL_GPL(balloon_page_dequeue);
128 102
129#ifdef CONFIG_BALLOON_COMPACTION 103#ifdef CONFIG_BALLOON_COMPACTION
130/*
131 * balloon_mapping_alloc - allocates a special ->mapping for ballooned pages.
132 * @b_dev_info: holds the balloon device information descriptor.
133 * @a_ops: balloon_mapping address_space_operations descriptor.
134 *
135 * Driver must call it to properly allocate and initialize an instance of
136 * struct address_space which will be used as the special page->mapping for
137 * balloon device enlisted page instances.
138 */
139struct address_space *balloon_mapping_alloc(struct balloon_dev_info *b_dev_info,
140 const struct address_space_operations *a_ops)
141{
142 struct address_space *mapping;
143
144 mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
145 if (!mapping)
146 return ERR_PTR(-ENOMEM);
147
148 /*
149 * Give a clean 'zeroed' status to all elements of this special
150 * balloon page->mapping struct address_space instance.
151 */
152 address_space_init_once(mapping);
153
154 /*
155 * Set mapping->flags appropriately, to allow balloon pages
156 * ->mapping identification.
157 */
158 mapping_set_balloon(mapping);
159 mapping_set_gfp_mask(mapping, balloon_mapping_gfp_mask());
160
161 /* balloon's page->mapping->a_ops callback descriptor */
162 mapping->a_ops = a_ops;
163
164 /*
165 * Establish a pointer reference back to the balloon device descriptor
166 * this particular page->mapping will be servicing.
167 * This is used by compaction / migration procedures to identify and
168 * access the balloon device pageset while isolating / migrating pages.
169 *
170 * As some balloon drivers can register multiple balloon devices
171 * for a single guest, this also helps compaction / migration to
172 * properly deal with multiple balloon pagesets, when required.
173 */
174 mapping->private_data = b_dev_info;
175 b_dev_info->mapping = mapping;
176
177 return mapping;
178}
179EXPORT_SYMBOL_GPL(balloon_mapping_alloc);
180 104
181static inline void __isolate_balloon_page(struct page *page) 105static inline void __isolate_balloon_page(struct page *page)
182{ 106{
183 struct balloon_dev_info *b_dev_info = page->mapping->private_data; 107 struct balloon_dev_info *b_dev_info = balloon_page_device(page);
184 unsigned long flags; 108 unsigned long flags;
185 109
186 spin_lock_irqsave(&b_dev_info->pages_lock, flags); 110 spin_lock_irqsave(&b_dev_info->pages_lock, flags);
@@ -192,7 +116,7 @@ static inline void __isolate_balloon_page(struct page *page)
192 116
193static inline void __putback_balloon_page(struct page *page) 117static inline void __putback_balloon_page(struct page *page)
194{ 118{
195 struct balloon_dev_info *b_dev_info = page->mapping->private_data; 119 struct balloon_dev_info *b_dev_info = balloon_page_device(page);
196 unsigned long flags; 120 unsigned long flags;
197 121
198 spin_lock_irqsave(&b_dev_info->pages_lock, flags); 122 spin_lock_irqsave(&b_dev_info->pages_lock, flags);
@@ -202,12 +126,6 @@ static inline void __putback_balloon_page(struct page *page)
202 spin_unlock_irqrestore(&b_dev_info->pages_lock, flags); 126 spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
203} 127}
204 128
205static inline int __migrate_balloon_page(struct address_space *mapping,
206 struct page *newpage, struct page *page, enum migrate_mode mode)
207{
208 return page->mapping->a_ops->migratepage(mapping, newpage, page, mode);
209}
210
211/* __isolate_lru_page() counterpart for a ballooned page */ 129/* __isolate_lru_page() counterpart for a ballooned page */
212bool balloon_page_isolate(struct page *page) 130bool balloon_page_isolate(struct page *page)
213{ 131{
@@ -274,7 +192,7 @@ void balloon_page_putback(struct page *page)
274int balloon_page_migrate(struct page *newpage, 192int balloon_page_migrate(struct page *newpage,
275 struct page *page, enum migrate_mode mode) 193 struct page *page, enum migrate_mode mode)
276{ 194{
277 struct address_space *mapping; 195 struct balloon_dev_info *balloon = balloon_page_device(page);
278 int rc = -EAGAIN; 196 int rc = -EAGAIN;
279 197
280 /* 198 /*
@@ -290,9 +208,8 @@ int balloon_page_migrate(struct page *newpage,
290 return rc; 208 return rc;
291 } 209 }
292 210
293 mapping = page->mapping; 211 if (balloon && balloon->migratepage)
294 if (mapping) 212 rc = balloon->migratepage(balloon, newpage, page, mode);
295 rc = __migrate_balloon_page(mapping, newpage, page, mode);
296 213
297 unlock_page(newpage); 214 unlock_page(newpage);
298 return rc; 215 return rc;