From: teawater <teawaterz@linux.alibaba.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Hui Zhu <teawater@gmail.com>,
david@redhat.com, jasowang@redhat.com, akpm@linux-foundation.org,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org
Subject: Re: [virtio-dev] [RFC for qemu v4 2/2] virtio_balloon: Add dcvq to deflate continuous pages
Date: Thu, 16 Jul 2020 15:32:30 +0800 [thread overview]
Message-ID: <4F64B592-03CF-46F5-B761-78B4EBA5028E@linux.alibaba.com> (raw)
In-Reply-To: <20200716023910-mutt-send-email-mst@kernel.org>
> 2020年7月16日 14:39,Michael S. Tsirkin <mst@redhat.com> 写道:
>
> On Thu, Jul 16, 2020 at 10:41:55AM +0800, Hui Zhu wrote:
>> This commit adds a vq dcvq to deflate continuous pages.
>> When VIRTIO_BALLOON_F_CONT_PAGES is set, try to get continuous pages
>> from icvq and use madvise MADV_WILLNEED with the pages.
>>
>> Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
>
> This is arguably something to benchmark. Does guest benefit
> from MADV_WILLNEED or loose performance?
MADV_WILLNEED will call madvise_willneed in the host kernel.
madvise_willneed will schedule all required I/O operations (swap in or vfs_fadvise POSIX_FADV_WILLNEED) of the address.
But the pages of the balloon are released by MADV_DONTNEED.
So I think MADV_WILLNEED will not affect the performance of the guest in the most of situations.
Best,
Hui
>
>> ---
>> hw/virtio/virtio-balloon.c | 14 +++++++++-----
>> include/hw/virtio/virtio-balloon.h | 2 +-
>> 2 files changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
>> index d36a5c8..165adf7 100644
>> --- a/hw/virtio/virtio-balloon.c
>> +++ b/hw/virtio/virtio-balloon.c
>> @@ -138,7 +138,8 @@ static void balloon_inflate_page(VirtIOBalloon *balloon,
>> }
>>
>> static void balloon_deflate_page(VirtIOBalloon *balloon,
>> - MemoryRegion *mr, hwaddr mr_offset)
>> + MemoryRegion *mr, hwaddr mr_offset,
>> + size_t size)
>> {
>> void *addr = memory_region_get_ram_ptr(mr) + mr_offset;
>> ram_addr_t rb_offset;
>> @@ -153,10 +154,11 @@ static void balloon_deflate_page(VirtIOBalloon *balloon,
>> rb_page_size = qemu_ram_pagesize(rb);
>>
>> host_addr = (void *)((uintptr_t)addr & ~(rb_page_size - 1));
>> + size &= ~(rb_page_size - 1);
>>
>> /* When a page is deflated, we hint the whole host page it lives
>> * on, since we can't do anything smaller */
>> - ret = qemu_madvise(host_addr, rb_page_size, QEMU_MADV_WILLNEED);
>> + ret = qemu_madvise(host_addr, size, QEMU_MADV_WILLNEED);
>> if (ret != 0) {
>> warn_report("Couldn't MADV_WILLNEED on balloon deflate: %s",
>> strerror(errno));
>> @@ -354,7 +356,7 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
>> pa = (hwaddr) p << VIRTIO_BALLOON_PFN_SHIFT;
>> offset += 4;
>>
>> - if (vq == s->icvq) {
>> + if (vq == s->icvq || vq == s->dcvq) {
>> uint32_t psize_ptr;
>> if (iov_to_buf(elem->out_sg, elem->out_num, offset, &psize_ptr, 4) != 4) {
>> break;
>> @@ -383,8 +385,9 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
>> balloon_inflate_page(s, section.mr,
>> section.offset_within_region,
>> psize, &pbp);
>> - } else if (vq == s->dvq) {
>> - balloon_deflate_page(s, section.mr, section.offset_within_region);
>> + } else if (vq == s->dvq || vq == s->dcvq) {
>> + balloon_deflate_page(s, section.mr, section.offset_within_region,
>> + psize);
>> } else {
>> g_assert_not_reached();
>> }
>> @@ -838,6 +841,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
>>
>> if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_CONT_PAGES)) {
>> s->icvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
>> + s->dcvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
>> }
>>
>> reset_stats(s);
>> diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
>> index 6a2514d..848a7fb 100644
>> --- a/include/hw/virtio/virtio-balloon.h
>> +++ b/include/hw/virtio/virtio-balloon.h
>> @@ -42,7 +42,7 @@ enum virtio_balloon_free_page_report_status {
>>
>> typedef struct VirtIOBalloon {
>> VirtIODevice parent_obj;
>> - VirtQueue *ivq, *dvq, *svq, *free_page_vq, *icvq;
>> + VirtQueue *ivq, *dvq, *svq, *free_page_vq, *icvq, *dcvq;
>> uint32_t free_page_report_status;
>> uint32_t num_pages;
>> uint32_t actual;
>> --
>> 2.7.4
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
> For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
next prev parent reply other threads:[~2020-07-16 7:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 2:41 [RFC for Linux v4 0/2] virtio_balloon: Add VIRTIO_BALLOON_F_CONT_PAGES to report continuous pages Hui Zhu
2020-07-16 2:41 ` [RFC for Linux v4 1/2] virtio_balloon: Add VIRTIO_BALLOON_F_CONT_PAGES and inflate_cont_vq Hui Zhu
2020-07-16 6:43 ` Michael S. Tsirkin
2020-07-16 8:25 ` teawater
2020-07-16 2:41 ` [RFC for Linux v4 2/2] virtio_balloon: Add deflate_cont_vq to deflate continuous pages Hui Zhu
2020-07-16 2:41 ` [RFC for qemu v4 0/2] virtio-balloon: Add option cont-pages to set VIRTIO_BALLOON_F_CONT_PAGES Hui Zhu
2020-07-16 2:41 ` [RFC for qemu v4 1/2] virtio_balloon: Add cont-pages and icvq Hui Zhu
2020-07-16 2:41 ` [RFC for qemu v4 2/2] virtio_balloon: Add dcvq to deflate continuous pages Hui Zhu
2020-07-16 6:39 ` Michael S. Tsirkin
2020-07-16 7:32 ` teawater [this message]
2020-07-16 6:38 ` [RFC for Linux v4 0/2] virtio_balloon: Add VIRTIO_BALLOON_F_CONT_PAGES to report " Michael S. Tsirkin
2020-07-16 7:01 ` [virtio-dev] " teawater
2020-07-16 10:45 ` Michael S. Tsirkin
2020-07-17 3:52 ` teawater
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=4F64B592-03CF-46F5-B761-78B4EBA5028E@linux.alibaba.com \
--to=teawaterz@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=teawater@gmail.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux-foundation.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;
as well as URLs for NNTP newsgroup(s).