From: Akio Takebe <takebe_akio-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
To: Marcelo Tosatti <marcelo-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>,
Anthony Liguori
<aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [PATCH] kvm balloon guest driver (v2)
Date: Thu, 10 Jan 2008 16:11:51 +0900 [thread overview]
Message-ID: <F1C85358126773takebe_akio@jp.fujitsu.com> (raw)
In-Reply-To: <20080109181445.GA303@dmt>
Hi, Marcelo
>+struct balloon_buf *alloc_balloon_buf(struct virtio_device *vdev, gfp_t
>flags)
>+{
>+ struct balloon_buf *buf;
>+
>+ buf = kzalloc(sizeof(struct balloon_buf), flags);
>+ if (!buf)
>+ dev_printk(KERN_ERR, &vdev->dev, "%s: alloc fail\n", __func__);
>+
>+ return buf;
>+}
>+
[snip..]
>+static int kvm_balloon_inflate(struct virtballoon *v, int32_t npages)
>+{
>+ LIST_HEAD(tmp_list);
>+ struct page *page, *tmp;
>+ struct balloon_buf *buf;
>+ u32 *pfn;
>+ int allocated = 0;
>+ int i, r = -ENOMEM;
>+
>+ buf = alloc_balloon_buf(v->vdev, GFP_KERNEL);
When does balloon driver free the buf?
>+ if (!buf)
>+ return r;
>+
>+ pfn = (u32 *)&buf->data;
>+ *pfn++ = (u32)npages;
>+
>+ for (i = 0; i < npages; i++) {
>+ page = alloc_page(GFP_HIGHUSER | __GFP_NORETRY);
>+ if (!page)
>+ goto out_free;
>+ list_add(&page->lru, &tmp_list);
>+ allocated++;
>+ *pfn = page_to_pfn(page);
>+ pfn++;
>+ }
>+
>+ r = send_balloon_buf(v, CMD_BALLOON_INFLATE, buf);
>+ if (r)
>+ goto out_free;
>+
>+ spin_lock(&v->plist_lock);
>+ list_splice(&tmp_list, &v->balloon_plist);
>+ v->balloon_size += allocated;
>+ totalram_pages -= allocated;
>+ dprintk(&v->vdev->dev, "%s: current balloon size=%d\n", __func__,
>+ v->balloon_size);
>+ spin_unlock(&v->plist_lock);
>+ return allocated;
>+
>+out_free:
>+ list_for_each_entry_safe(page, tmp, &tmp_list, lru) {
>+ list_del(&page->lru);
>+ __free_page(page);
>+ }
>+ return r;
>+}
>+
>+static int kvm_balloon_deflate(struct virtballoon *v, int32_t npages)
>+{
>+ LIST_HEAD(tmp_list);
>+ struct page *page, *tmp;
>+ struct balloon_buf *buf;
>+ u32 *pfn;
>+ int deallocated = 0;
>+ int r = 0;
>+
>+ buf = alloc_balloon_buf(v->vdev, GFP_KERNEL);
ditto.
>+ if (!buf)
>+ return r;
>+
>+ spin_lock(&v->plist_lock);
>+
>+ if (v->balloon_size < npages) {
>+ dev_printk(KERN_INFO, &v->vdev->dev,
>+ "%s: balloon=%d with deflate rq=%d\n",
>+ __func__, v->balloon_size, npages);
>+ npages = v->balloon_size;
>+ if (!npages)
>+ goto out;
>+ }
>+
>+ pfn = (u32 *)&buf->data;
>+ *pfn++ = (u32)-npages;
>+
>+ /*
>+ * Move the balloon pages to tmp list before issuing
>+ * the virtio buffer
>+ */
>+ list_for_each_entry_safe(page, tmp, &v->balloon_plist, lru) {
>+ *pfn++ = page_to_pfn(page);
>+ list_move(&page->lru, &tmp_list);
>+ if (++deallocated == npages)
>+ break;
>+ }
>+
>+ r = send_balloon_buf(v, CMD_BALLOON_DEFLATE, buf);
>+ if (r)
>+ goto out;
>+
>+ list_for_each_entry_safe(page, tmp, &tmp_list, lru)
>+ list_del_init(&page->lru);
>+
>+ v->balloon_size -= npages;
>+ totalram_pages += npages;
>+ dprintk(&v->vdev->dev, "%s: current balloon size=%d\n", __func__,
>+ v->balloon_size);
>+
>+ spin_unlock(&v->plist_lock);
>+ return deallocated;
>+
>+out:
>+ list_splice(&tmp_list, &v->balloon_plist);
>+ spin_unlock(&v->plist_lock);
>+ return r;
>+}
>+
Best Regards,
Akio Takebe
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
next prev parent reply other threads:[~2008-01-10 7:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-09 18:14 [PATCH] kvm balloon guest driver (v2) Marcelo Tosatti
2008-01-10 7:11 ` Akio Takebe [this message]
[not found] ` <F1C85358126773takebe_akio-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2008-01-10 11:29 ` Marcelo Tosatti
2008-01-10 12:27 ` Akio Takebe
[not found] ` <F7C853842F97FDtakebe_akio-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2008-01-10 13:11 ` Dor Laor
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=F1C85358126773takebe_akio@jp.fujitsu.com \
--to=takebe_akio-+cum20s59erqfuhtdcdx3a@public.gmane.org \
--cc=aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=marcelo-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
/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