From: Cornelia Huck <cornelia.huck@de.ibm.com> To: Liang Li <liang.z.li@intel.com> Cc: mst@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, amit.shah@redhat.com, pbonzini@redhat.com, akpm@linux-foundation.org, dgilbert@redhat.com Subject: Re: [PATCH RFC kernel] balloon: speed up inflating/deflating process Date: Fri, 20 May 2016 12:32:43 +0200 [thread overview] Message-ID: <20160520123243.59b91c00.cornelia.huck@de.ibm.com> (raw) In-Reply-To: <1463738386-30868-1-git-send-email-liang.z.li@intel.com> On Fri, 20 May 2016 17:59:46 +0800 Liang Li <liang.z.li@intel.com> wrote: > The implementation of the current virtio-balloon is not very efficient, > Bellow is test result of time spends on inflating the balloon to 3GB of > a 4GB idle guest: > > a. allocating pages (6.5%, 103ms) > b. sending PFNs to host (68.3%, 787ms) > c. address translation (6.1%, 96ms) > d. madvise (19%, 300ms) > > It takes about 1577ms for the whole inflating process to complete. The > test shows that the bottle neck is the stage b and stage d. > > If using a bitmap to send the page info instead of the PFNs, we can > reduce the overhead spends on stage b quite a lot. Furthermore, it's > possible to do the address translation and do the madvise with a bulk > of pages, instead of the current page per page way, so the overhead of > stage c and stage d can also be reduced a lot. > > This patch is the kernel side implementation which is intended to speed > up the inflating & deflating process by adding a new feature to the > virtio-balloon device. And now, inflating the balloon to 3GB of a 4GB > idle guest only takes 175ms, it's about 9 times as fast as before. > > TODO: optimize stage a by allocating/freeing a chunk of pages instead > of a single page at a time. Not commenting on the approach, but... > > Signed-off-by: Liang Li <liang.z.li@intel.com> > --- > drivers/virtio/virtio_balloon.c | 199 ++++++++++++++++++++++++++++++++++-- > include/uapi/linux/virtio_balloon.h | 1 + > mm/page_alloc.c | 6 ++ > 3 files changed, 198 insertions(+), 8 deletions(-) > > static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) > { > - struct scatterlist sg; > unsigned int len; > > - sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); > + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_PAGE_BITMAP)) { > + u32 page_shift = PAGE_SHIFT; > + unsigned long start_pfn, end_pfn, flags = 0, bmap_len; > + struct scatterlist sg[5]; > + > + start_pfn = rounddown(vb->start_pfn, BITS_PER_LONG); > + end_pfn = roundup(vb->end_pfn, BITS_PER_LONG); > + bmap_len = (end_pfn - start_pfn) / BITS_PER_LONG * sizeof(long); > + > + sg_init_table(sg, 5); > + sg_set_buf(&sg[0], &flags, sizeof(flags)); > + sg_set_buf(&sg[1], &start_pfn, sizeof(start_pfn)); > + sg_set_buf(&sg[2], &page_shift, sizeof(page_shift)); > + sg_set_buf(&sg[3], &bmap_len, sizeof(bmap_len)); > + sg_set_buf(&sg[4], vb->page_bitmap + > + (start_pfn / BITS_PER_LONG), bmap_len); > + virtqueue_add_outbuf(vq, sg, 5, vb, GFP_KERNEL); > + ...you need to take care of the endianness of the data you put on the queue, otherwise virtio-1 on big endian won't work. (There's just been a patch for that problem.)
WARNING: multiple messages have this Message-ID (diff)
From: Cornelia Huck <cornelia.huck@de.ibm.com> To: Liang Li <liang.z.li@intel.com> Cc: mst@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, amit.shah@redhat.com, pbonzini@redhat.com, akpm@linux-foundation.org, dgilbert@redhat.com Subject: Re: [Qemu-devel] [PATCH RFC kernel] balloon: speed up inflating/deflating process Date: Fri, 20 May 2016 12:32:43 +0200 [thread overview] Message-ID: <20160520123243.59b91c00.cornelia.huck@de.ibm.com> (raw) In-Reply-To: <1463738386-30868-1-git-send-email-liang.z.li@intel.com> On Fri, 20 May 2016 17:59:46 +0800 Liang Li <liang.z.li@intel.com> wrote: > The implementation of the current virtio-balloon is not very efficient, > Bellow is test result of time spends on inflating the balloon to 3GB of > a 4GB idle guest: > > a. allocating pages (6.5%, 103ms) > b. sending PFNs to host (68.3%, 787ms) > c. address translation (6.1%, 96ms) > d. madvise (19%, 300ms) > > It takes about 1577ms for the whole inflating process to complete. The > test shows that the bottle neck is the stage b and stage d. > > If using a bitmap to send the page info instead of the PFNs, we can > reduce the overhead spends on stage b quite a lot. Furthermore, it's > possible to do the address translation and do the madvise with a bulk > of pages, instead of the current page per page way, so the overhead of > stage c and stage d can also be reduced a lot. > > This patch is the kernel side implementation which is intended to speed > up the inflating & deflating process by adding a new feature to the > virtio-balloon device. And now, inflating the balloon to 3GB of a 4GB > idle guest only takes 175ms, it's about 9 times as fast as before. > > TODO: optimize stage a by allocating/freeing a chunk of pages instead > of a single page at a time. Not commenting on the approach, but... > > Signed-off-by: Liang Li <liang.z.li@intel.com> > --- > drivers/virtio/virtio_balloon.c | 199 ++++++++++++++++++++++++++++++++++-- > include/uapi/linux/virtio_balloon.h | 1 + > mm/page_alloc.c | 6 ++ > 3 files changed, 198 insertions(+), 8 deletions(-) > > static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) > { > - struct scatterlist sg; > unsigned int len; > > - sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); > + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_PAGE_BITMAP)) { > + u32 page_shift = PAGE_SHIFT; > + unsigned long start_pfn, end_pfn, flags = 0, bmap_len; > + struct scatterlist sg[5]; > + > + start_pfn = rounddown(vb->start_pfn, BITS_PER_LONG); > + end_pfn = roundup(vb->end_pfn, BITS_PER_LONG); > + bmap_len = (end_pfn - start_pfn) / BITS_PER_LONG * sizeof(long); > + > + sg_init_table(sg, 5); > + sg_set_buf(&sg[0], &flags, sizeof(flags)); > + sg_set_buf(&sg[1], &start_pfn, sizeof(start_pfn)); > + sg_set_buf(&sg[2], &page_shift, sizeof(page_shift)); > + sg_set_buf(&sg[3], &bmap_len, sizeof(bmap_len)); > + sg_set_buf(&sg[4], vb->page_bitmap + > + (start_pfn / BITS_PER_LONG), bmap_len); > + virtqueue_add_outbuf(vq, sg, 5, vb, GFP_KERNEL); > + ...you need to take care of the endianness of the data you put on the queue, otherwise virtio-1 on big endian won't work. (There's just been a patch for that problem.)
next prev parent reply other threads:[~2016-05-20 11:26 UTC|newest] Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-05-20 9:59 [PATCH RFC kernel] balloon: speed up inflating/deflating process Liang Li 2016-05-20 9:59 ` [Qemu-devel] " Liang Li 2016-05-20 10:32 ` Cornelia Huck 2016-05-20 10:32 ` Cornelia Huck [this message] 2016-05-20 10:32 ` [Qemu-devel] " Cornelia Huck 2016-05-24 7:48 ` Li, Liang Z 2016-05-24 7:48 ` Li, Liang Z 2016-05-24 7:48 ` [Qemu-devel] " Li, Liang Z 2016-05-24 7:48 ` Li, Liang Z 2016-05-20 11:19 ` Paolo Bonzini 2016-05-20 11:19 ` [Qemu-devel] " Paolo Bonzini 2016-05-20 11:19 ` Paolo Bonzini 2016-05-24 7:51 ` Li, Liang Z 2016-05-24 7:51 ` [Qemu-devel] " Li, Liang Z 2016-05-24 7:51 ` Li, Liang Z 2016-05-24 7:51 ` Li, Liang Z 2016-05-20 12:00 ` Michael S. Tsirkin 2016-05-20 12:00 ` Michael S. Tsirkin 2016-05-20 12:00 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-24 9:51 ` Li, Liang Z 2016-05-24 9:51 ` [Qemu-devel] " Li, Liang Z 2016-05-24 9:51 ` Li, Liang Z 2016-05-24 9:55 ` Li, Liang Z 2016-05-24 9:55 ` [Qemu-devel] " Li, Liang Z 2016-05-24 9:55 ` Li, Liang Z 2016-05-24 10:08 ` Michael S. Tsirkin 2016-05-24 10:08 ` Michael S. Tsirkin 2016-05-24 10:08 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-24 10:08 ` Michael S. Tsirkin 2016-05-24 10:38 ` Li, Liang Z 2016-05-24 10:38 ` [Qemu-devel] " Li, Liang Z 2016-05-24 10:38 ` Li, Liang Z 2016-05-24 11:11 ` Michael S. Tsirkin 2016-05-24 11:11 ` Michael S. Tsirkin 2016-05-24 11:11 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-24 11:11 ` Michael S. Tsirkin 2016-05-24 14:36 ` Li, Liang Z 2016-05-24 14:36 ` Li, Liang Z 2016-05-24 14:36 ` [Qemu-devel] " Li, Liang Z 2016-05-24 14:36 ` Li, Liang Z 2016-05-24 15:12 ` Michael S. Tsirkin 2016-05-24 15:12 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-24 15:12 ` Michael S. Tsirkin 2016-05-25 0:52 ` Li, Liang Z 2016-05-25 0:52 ` Li, Liang Z 2016-05-25 0:52 ` [Qemu-devel] " Li, Liang Z 2016-05-25 0:52 ` Li, Liang Z 2016-05-25 1:00 ` Li, Liang Z 2016-05-25 1:00 ` [Qemu-devel] " Li, Liang Z 2016-05-25 1:00 ` Li, Liang Z 2016-05-25 8:35 ` Michael S. Tsirkin 2016-05-25 8:35 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-25 8:35 ` Michael S. Tsirkin 2016-05-25 8:35 ` Michael S. Tsirkin 2016-05-24 15:12 ` Michael S. Tsirkin 2016-05-25 8:48 ` Li, Liang Z 2016-05-25 8:48 ` [Qemu-devel] " Li, Liang Z 2016-05-25 8:48 ` Li, Liang Z 2016-05-25 8:57 ` Michael S. Tsirkin 2016-05-25 8:57 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-25 8:57 ` Michael S. Tsirkin 2016-05-25 9:28 ` Li, Liang Z 2016-05-25 9:28 ` [Qemu-devel] " Li, Liang Z 2016-05-25 9:28 ` Li, Liang Z 2016-05-25 9:40 ` Michael S. Tsirkin 2016-05-25 9:40 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-25 9:40 ` Michael S. Tsirkin 2016-05-25 10:10 ` Li, Liang Z 2016-05-25 10:10 ` [Qemu-devel] " Li, Liang Z 2016-05-25 10:10 ` Li, Liang Z 2016-05-25 10:37 ` Michael S. Tsirkin 2016-05-25 10:37 ` [Qemu-devel] " Michael S. Tsirkin 2016-05-25 10:37 ` Michael S. Tsirkin 2016-05-25 14:29 ` Li, Liang Z 2016-05-25 14:29 ` [Qemu-devel] " Li, Liang Z 2016-05-25 14:29 ` Li, Liang Z 2016-05-25 14:29 ` Li, Liang Z 2016-05-25 10:37 ` Michael S. Tsirkin 2016-05-20 9:59 Liang Li
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=20160520123243.59b91c00.cornelia.huck@de.ibm.com \ --to=cornelia.huck@de.ibm.com \ --cc=akpm@linux-foundation.org \ --cc=amit.shah@redhat.com \ --cc=dgilbert@redhat.com \ --cc=kvm@vger.kernel.org \ --cc=liang.z.li@intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=mst@redhat.com \ --cc=pbonzini@redhat.com \ --cc=qemu-devel@nongnu.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.