From: Wei Huang <wei@redhat.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, Wei Huang <wei@redhat.com>,
drjones@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH 1/1] virtio-mmio: return the max queue num of virtio-mmio with initial value
Date: Thu, 16 Jul 2015 14:38:13 -0400 [thread overview]
Message-ID: <1437071893-19457-1-git-send-email-wei@redhat.com> (raw)
Recently we found that virtio-console devices consumes lots AArch64 guest
memory, roughly 1GB with 8 devices. After debugging, it turns out that lots
of factors contribute to this problem: i) guest PAGE_SIZE=64KB, ii)
virtio-mmio based devices, and iii) virtio-console device. Here is the
detailed analysis:
1. First, during initialization, virtio-mmio driver in guest pokes vq
size by reading VIRTIO_MMIO_QUEUE_NUM_MAX (see virtio_mmio.c file).
2. QEMU returns VIRTQUEUE_MAX_SIZE (1024) to guest VM; And virtio-mmio uses
it as the default vq size.
3. virtio-console driver allocates vring buffers based on this value (see
add_inbuf() function of virtio_console.c file). Because PAGE_SIZE=64KB,
~64MB is allocated for each virtio-console vq.
This patch addresses the problem by returning the iniatlized vring size
when VM queries QEMU about VIRTIO_MMIO_QUEUE_NUM_MAX. This is similar to
virtio-pci's approach. By doing this, the vq memory consumption is reduced
substantially.
Signed-off-by: Wei Huang <wei@redhat.com>
---
hw/virtio/virtio-mmio.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 10123f3..27840fe 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -93,6 +93,7 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
{
VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+ uint64_t queue_num;
DPRINTF("virtio_mmio_read offset 0x%x\n", (int)offset);
@@ -149,10 +150,8 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
}
return proxy->host_features;
case VIRTIO_MMIO_QUEUENUMMAX:
- if (!virtio_queue_get_num(vdev, vdev->queue_sel)) {
- return 0;
- }
- return VIRTQUEUE_MAX_SIZE;
+ queue_num = virtio_queue_get_num(vdev, vdev->queue_sel);
+ return queue_num;
case VIRTIO_MMIO_QUEUEPFN:
return virtio_queue_get_addr(vdev, vdev->queue_sel)
>> proxy->guest_page_shift;
--
1.8.3.1
next reply other threads:[~2015-07-16 18:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-16 18:38 Wei Huang [this message]
2015-07-20 11:07 ` [Qemu-devel] [PATCH 1/1] virtio-mmio: return the max queue num of virtio-mmio with initial value Peter Maydell
2015-07-20 15:38 ` Wei Huang
2015-07-21 11:22 ` Andrew Jones
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=1437071893-19457-1-git-send-email-wei@redhat.com \
--to=wei@redhat.com \
--cc=amit.shah@redhat.com \
--cc=drjones@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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).