Commit 195a8c43 authored by Liang Li's avatar Liang Li Committed by Michael S. Tsirkin

virtio-balloon: deflate via a page list

This patch saves the deflated pages to a list, instead of the PFN array.
Accordingly, the balloon_pfn_to_page() function is removed.
Signed-off-by: default avatarLiang Li <liang.z.li@intel.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarWei Wang <wei.w.wang@intel.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent f53d5aa0
...@@ -104,12 +104,6 @@ static u32 page_to_balloon_pfn(struct page *page) ...@@ -104,12 +104,6 @@ static u32 page_to_balloon_pfn(struct page *page)
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE; return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
} }
static struct page *balloon_pfn_to_page(u32 pfn)
{
BUG_ON(pfn % VIRTIO_BALLOON_PAGES_PER_PAGE);
return pfn_to_page(pfn / VIRTIO_BALLOON_PAGES_PER_PAGE);
}
static void balloon_ack(struct virtqueue *vq) static void balloon_ack(struct virtqueue *vq)
{ {
struct virtio_balloon *vb = vq->vdev->priv; struct virtio_balloon *vb = vq->vdev->priv;
...@@ -182,18 +176,16 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num) ...@@ -182,18 +176,16 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
return num_allocated_pages; return num_allocated_pages;
} }
static void release_pages_balloon(struct virtio_balloon *vb) static void release_pages_balloon(struct virtio_balloon *vb,
struct list_head *pages)
{ {
unsigned int i; struct page *page, *next;
struct page *page;
/* Find pfns pointing at start of each page, get pages and free them. */ list_for_each_entry_safe(page, next, pages, lru) {
for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev,
vb->pfns[i]));
if (!virtio_has_feature(vb->vdev, if (!virtio_has_feature(vb->vdev,
VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
adjust_managed_page_count(page, 1); adjust_managed_page_count(page, 1);
list_del(&page->lru);
put_page(page); /* balloon reference */ put_page(page); /* balloon reference */
} }
} }
...@@ -203,6 +195,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) ...@@ -203,6 +195,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
unsigned num_freed_pages; unsigned num_freed_pages;
struct page *page; struct page *page;
struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info; struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info;
LIST_HEAD(pages);
/* We can only do one array worth at a time. */ /* We can only do one array worth at a time. */
num = min(num, ARRAY_SIZE(vb->pfns)); num = min(num, ARRAY_SIZE(vb->pfns));
...@@ -216,6 +209,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) ...@@ -216,6 +209,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
if (!page) if (!page)
break; break;
set_page_pfns(vb, vb->pfns + vb->num_pfns, page); set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
list_add(&page->lru, &pages);
vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE; vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
} }
...@@ -227,7 +221,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num) ...@@ -227,7 +221,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
*/ */
if (vb->num_pfns != 0) if (vb->num_pfns != 0)
tell_host(vb, vb->deflate_vq); tell_host(vb, vb->deflate_vq);
release_pages_balloon(vb); release_pages_balloon(vb, &pages);
mutex_unlock(&vb->balloon_lock); mutex_unlock(&vb->balloon_lock);
return num_freed_pages; return num_freed_pages;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment