Source
3
3
*
4
4
* Common interface for making balloon pages movable by compaction.
5
5
*
6
6
* Copyright (C) 2012, Red Hat, Inc. Rafael Aquini <aquini@redhat.com>
7
7
*/
8
8
#include <linux/mm.h>
9
9
#include <linux/slab.h>
10
10
#include <linux/export.h>
11
11
#include <linux/balloon_compaction.h>
12
12
13
+
/*
14
+
* balloon_page_alloc - allocates a new page for insertion into the balloon
15
+
* page list.
16
+
*
17
+
* Driver must call it to properly allocate a new enlisted balloon page.
18
+
* Driver must call balloon_page_enqueue before definitively removing it from
19
+
* the guest system. This function returns the page address for the recently
20
+
* allocated page or NULL in the case we fail to allocate a new page this turn.
21
+
*/
22
+
struct page *balloon_page_alloc(void)
23
+
{
24
+
struct page *page = alloc_page(balloon_mapping_gfp_mask() |
25
+
__GFP_NOMEMALLOC | __GFP_NORETRY);
26
+
return page;
27
+
}
28
+
EXPORT_SYMBOL_GPL(balloon_page_alloc);
29
+
13
30
/*
14
31
* balloon_page_enqueue - allocates a new page and inserts it into the balloon
15
32
* page list.
16
33
* @b_dev_info: balloon device descriptor where we will insert a new page to
34
+
* @page: new page to enqueue - allocated using balloon_page_alloc.
17
35
*
18
-
* Driver must call it to properly allocate a new enlisted balloon page
36
+
* Driver must call it to properly enqueue a new allocated balloon page
19
37
* before definitively removing it from the guest system.
20
38
* This function returns the page address for the recently enqueued page or
21
39
* NULL in the case we fail to allocate a new page this turn.
22
40
*/
23
-
struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info)
41
+
void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
42
+
struct page *page)
24
43
{
25
44
unsigned long flags;
26
-
struct page *page = alloc_page(balloon_mapping_gfp_mask() |
27
-
__GFP_NOMEMALLOC | __GFP_NORETRY);
28
-
if (!page)
29
-
return NULL;
30
45
31
46
/*
32
47
* Block others from accessing the 'page' when we get around to
33
48
* establishing additional references. We should be the only one
34
49
* holding a reference to the 'page' at this point.
35
50
*/
36
51
BUG_ON(!trylock_page(page));
37
52
spin_lock_irqsave(&b_dev_info->pages_lock, flags);
38
53
balloon_page_insert(b_dev_info, page);
39
54
__count_vm_event(BALLOON_INFLATE);
40
55
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
41
56
unlock_page(page);
42
-
return page;
43
57
}
44
58
EXPORT_SYMBOL_GPL(balloon_page_enqueue);
45
59
46
60
/*
47
61
* balloon_page_dequeue - removes a page from balloon's page list and returns
48
62
* the its address to allow the driver release the page.
49
63
* @b_dev_info: balloon device decriptor where we will grab a page from.
50
64
*
51
65
* Driver must call it to properly de-allocate a previous enlisted balloon page
52
66
* before definetively releasing it back to the guest system.