From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Huangweidong (C)" <weidong.huang@huawei.com>,
"gleb@redhat.com" <gleb@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"avi.kivity@gmail.com" <avi.kivity@gmail.com>,
"Herongguang (Stephen)" <herongguang.he@huawei.com>
Subject: Re: [Qemu-devel] [RFC] vhost: Can we change synchronize_rcu to call_rcu in vhost_set_memory() in vhost kernel module?
Date: Mon, 12 May 2014 13:30:52 +0300 [thread overview]
Message-ID: <20140512103052.GB15294@redhat.com> (raw)
In-Reply-To: <53709B0C.4030808@redhat.com>
On Mon, May 12, 2014 at 11:57:32AM +0200, Paolo Bonzini wrote:
> Il 12/05/2014 11:28, Gonglei (Arei) ha scritto:
> >From previous discussion:
> >https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg04925.html
> >we know that you are going to replace RCU in KVM_SET_GSI_ROUTING with SRCU. Though
> >SRCU is quite better than originally RCU, in our test case this cannot satisfy our needs. Our VMs
> >work in telecom scenario, VMs report CPU and memory usage to balance node each second, and
> >balance node dispatch works to different VMs according to VM load. Since this balance needs
> >high accuracy, IRQ affinity settings in VM also need high accuracy, so we balance IRQ affinity in
> >every 0.5s. So for telecom scenario, KVM_SET_GSI_ROUTING IOCTL needs much optimization.
> >And in live migration case, VHOST_SET_MEM_TABLE needs attention.
> >
> >We tried to change synchronize_rcu() to call_rcu() with rate limit, but rate limit is not easy to
> >configure. Do you have better ideas to achieve this? Thanks.
>
> Perhaps we can check for cases where only the address is changing,
> and poke at an existing struct kvm_kernel_irq_routing_entry without
> doing any RCU synchronization?
>
> As long as kvm_set_msi_irq only reads address_lo once, it should work.
>
> VHOST_SET_MEM_TABLE is a different problem. What happens in
> userspace that leads to calling that ioctl? Can we remove it
> altogether, or delay it to after the destination has started
> running?
>
> Paolo
vhost does everything under a VQ lock.
I think RCU for VHOST_SET_MEM_TABLE can be replaced with
taking and freeing the VQ lock.
Does the below solve the problem for you
(warning: untested, sorry, busy with other bugs right now)?
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 78987e4..df2e3eb 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -593,6 +593,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
{
struct vhost_memory mem, *newmem, *oldmem;
unsigned long size = offsetof(struct vhost_memory, regions);
+ int i;
if (copy_from_user(&mem, m, size))
return -EFAULT;
@@ -619,7 +620,14 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
oldmem = rcu_dereference_protected(d->memory,
lockdep_is_held(&d->mutex));
rcu_assign_pointer(d->memory, newmem);
- synchronize_rcu();
+
+ /* All memory accesses are done under some VQ mutex.
+ * So below is a faster equivalent of synchronize_rcu()
+ */
+ for (i = 0; i < dev->nvqs; ++i) {
+ mutex_lock(d->vqs[idx]->mutex);
+ mutex_unlock(d->vqs[idx]->mutex);
+ }
kfree(oldmem);
return 0;
}
next prev parent reply other threads:[~2014-05-12 10:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-09 1:57 [Qemu-devel] [RFC] vhost: Can we change synchronize_rcu to call_rcu in vhost_set_memory() in vhost kernel module? Gonglei (Arei)
2014-05-09 8:14 ` Paolo Bonzini
2014-05-09 9:04 ` Gonglei (Arei)
2014-05-09 9:53 ` Paolo Bonzini
2014-05-12 9:28 ` Gonglei (Arei)
2014-05-12 9:57 ` Paolo Bonzini
2014-05-12 10:08 ` Michael S. Tsirkin
2014-05-12 10:14 ` Paolo Bonzini
2014-05-12 10:18 ` Michael S. Tsirkin
2014-05-12 10:25 ` Paolo Bonzini
2014-05-12 11:07 ` Michael S. Tsirkin
2014-05-12 11:46 ` Paolo Bonzini
2014-05-12 12:12 ` Michael S. Tsirkin
2014-05-12 12:46 ` Paolo Bonzini
2014-05-12 12:53 ` Michael S. Tsirkin
2014-05-12 13:02 ` Paolo Bonzini
2014-05-12 10:30 ` Michael S. Tsirkin [this message]
2014-05-13 7:03 ` Gonglei (Arei)
2014-05-13 8:21 ` Michael S. Tsirkin
2014-05-13 7:01 ` Gonglei (Arei)
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=20140512103052.GB15294@redhat.com \
--to=mst@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=avi.kivity@gmail.com \
--cc=gleb@redhat.com \
--cc=herongguang.he@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=weidong.huang@huawei.com \
/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 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.