From: Daniel De Graaf <dgdegra@tycho.nsa.gov>
To: Ian.Campbell@eu.citrix.com
Cc: Daniel De Graaf <dgdegra@tycho.nsa.gov>,
xen-devel@lists.xensource.com, konrad.wilk@oracle.com
Subject: [PATCH 2/3 v4] xen-balloon: Add interface to retrieve ballooned pages
Date: Tue, 8 Mar 2011 14:49:56 -0500 [thread overview]
Message-ID: <1299613797-2933-1-git-send-email-dgdegra@tycho.nsa.gov> (raw)
In-Reply-To: <1299604312.17339.542.camel@zakaz.uk.xensource.com>
Pages that have been ballooned are useful for other Xen drivers doing
grant table actions, because these pages have valid struct page/PFNs but
have no valid MFN so are available for remapping.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
drivers/xen/balloon.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++--
include/xen/balloon.h | 3 ++
2 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index b0a7a92..d187fce 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -116,14 +116,17 @@ static void balloon_append(struct page *page)
}
/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
-static struct page *balloon_retrieve(void)
+static struct page *balloon_retrieve(bool prefer_highmem)
{
struct page *page;
if (list_empty(&ballooned_pages))
return NULL;
- page = list_entry(ballooned_pages.next, struct page, lru);
+ if (prefer_highmem)
+ page = list_entry(ballooned_pages.prev, struct page, lru);
+ else
+ page = list_entry(ballooned_pages.next, struct page, lru);
list_del(&page->lru);
if (PageHighMem(page)) {
@@ -198,7 +201,7 @@ static int increase_reservation(unsigned long nr_pages)
goto out;
for (i = 0; i < rc; i++) {
- page = balloon_retrieve();
+ page = balloon_retrieve(0);
BUG_ON(page == NULL);
pfn = page_to_pfn(page);
@@ -328,6 +331,62 @@ void balloon_set_new_target(unsigned long target)
}
EXPORT_SYMBOL_GPL(balloon_set_new_target);
+/**
+ * alloc_xenballooned_pages - get pages that have been ballooned out
+ * @nr_pages: Number of pages to get
+ * @pages: pages returned
+ * @return 0 on success, error otherwise
+ */
+int alloc_xenballooned_pages(int nr_pages, struct page** pages)
+{
+ int pgno = 0;
+ struct page* page;
+ mutex_lock(&balloon_mutex);
+ while (pgno < nr_pages) {
+ page = balloon_retrieve(1);
+ if (page) {
+ pages[pgno++] = page;
+ } else {
+ if (decrease_reservation(nr_pages - pgno))
+ goto out_undo;
+ }
+ }
+ mutex_unlock(&balloon_mutex);
+ return 0;
+ out_undo:
+ while (pgno)
+ balloon_append(pages[--pgno]);
+ /* Free the memory back to the kernel soon */
+ schedule_work(&balloon_worker);
+ mutex_unlock(&balloon_mutex);
+ return -ENOMEM;
+}
+EXPORT_SYMBOL(alloc_xenballooned_pages);
+
+/**
+ * free_xenballooned_pages - return pages retrieved with get_ballooned_pages
+ * @nr_pages: Number of pages
+ * @pages: pages to return
+ */
+void free_xenballooned_pages(int nr_pages, struct page** pages)
+{
+ int i;
+
+ mutex_lock(&balloon_mutex);
+
+ for (i = 0; i < nr_pages; i++) {
+ if (pages[i])
+ balloon_append(pages[i]);
+ }
+
+ /* The balloon may be too large now. Shrink it if needed. */
+ if (current_target() != balloon_stats.current_pages)
+ schedule_work(&balloon_worker);
+
+ mutex_unlock(&balloon_mutex);
+}
+EXPORT_SYMBOL(free_xenballooned_pages);
+
static int __init balloon_init(void)
{
unsigned long pfn, nr_pages, extra_pfn_end;
diff --git a/include/xen/balloon.h b/include/xen/balloon.h
index b2b7c21..72a6927 100644
--- a/include/xen/balloon.h
+++ b/include/xen/balloon.h
@@ -19,3 +19,6 @@ struct balloon_stats {
extern struct balloon_stats balloon_stats;
void balloon_set_new_target(unsigned long target);
+
+int alloc_xenballooned_pages(int nr_pages, struct page** pages);
+void free_xenballooned_pages(int nr_pages, struct page** pages);
--
1.7.3.4
next prev parent reply other threads:[~2011-03-08 19:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-07 18:06 [PATCH] Use ballooned pages for gntdev Daniel De Graaf
2011-03-07 18:06 ` [PATCH 1/3] xen-balloon: Move core balloon functionality out of module Daniel De Graaf
2011-03-08 10:18 ` Ian Campbell
2011-03-07 18:06 ` [PATCH 2/3] xen-balloon: Add interface to retrieve ballooned pages Daniel De Graaf
2011-03-08 10:13 ` Ian Campbell
2011-03-08 16:24 ` Daniel De Graaf
2011-03-09 21:03 ` Konrad Rzeszutek Wilk
2011-03-09 21:22 ` Daniel De Graaf
2011-03-09 21:59 ` Konrad Rzeszutek Wilk
2011-03-07 18:06 ` [PATCH 3/3] xen-gntdev: Use ballooned pages for grant mappings Daniel De Graaf
2011-03-08 10:18 ` Ian Campbell
2011-03-08 16:24 ` [PATCH 2/3 v2] xen-balloon: Add interface to retrieve ballooned pages Daniel De Graaf
2011-03-08 16:36 ` Ian Campbell
2011-03-08 16:55 ` [PATCH 2/3 v3] " Daniel De Graaf
2011-03-08 17:11 ` Ian Campbell
2011-03-08 19:49 ` Daniel De Graaf [this message]
2011-03-09 10:30 ` [PATCH 2/3 v4] " Ian Campbell
2011-03-08 19:49 ` [PATCH 3/3 v4] xen-gntdev: Use ballooned pages for grant mappings Daniel De Graaf
2011-03-08 16:24 ` [PATCH 3/3 v2] " Daniel De Graaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299613797-2933-1-git-send-email-dgdegra@tycho.nsa.gov \
--to=dgdegra@tycho.nsa.gov \
--cc=Ian.Campbell@eu.citrix.com \
--cc=konrad.wilk@oracle.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).