From: "Michael S. Tsirkin" <mst@redhat.com> To: linux-kernel@vger.kernel.org Cc: David Miller <davem@davemloft.net>, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PULL 2/2] vhost: replace rcu with mutex Date: Tue, 3 Jun 2014 00:30:18 +0300 [thread overview] Message-ID: <1401744482-17764-3-git-send-email-mst@redhat.com> (raw) In-Reply-To: <1401744482-17764-1-git-send-email-mst@redhat.com> All memory accesses are done under some VQ mutex. So lock/unlock all VQs is a faster equivalent of synchronize_rcu() for memory access changes. Some guests cause a lot of these changes, so it's helpful to make them faster. Reported-by: "Gonglei (Arei)" <arei.gonglei@huawei.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> --- drivers/vhost/vhost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 78987e4..1c05e60 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 < d->nvqs; ++i) { + mutex_lock(&d->vqs[i]->mutex); + mutex_unlock(&d->vqs[i]->mutex); + } kfree(oldmem); return 0; } -- MST
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com> To: linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, David Miller <davem@davemloft.net>, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PULL 2/2] vhost: replace rcu with mutex Date: Tue, 3 Jun 2014 00:30:18 +0300 [thread overview] Message-ID: <1401744482-17764-3-git-send-email-mst@redhat.com> (raw) In-Reply-To: <1401744482-17764-1-git-send-email-mst@redhat.com> All memory accesses are done under some VQ mutex. So lock/unlock all VQs is a faster equivalent of synchronize_rcu() for memory access changes. Some guests cause a lot of these changes, so it's helpful to make them faster. Reported-by: "Gonglei (Arei)" <arei.gonglei@huawei.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> --- drivers/vhost/vhost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 78987e4..1c05e60 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 < d->nvqs; ++i) { + mutex_lock(&d->vqs[i]->mutex); + mutex_unlock(&d->vqs[i]->mutex); + } kfree(oldmem); return 0; } -- MST
next prev parent reply other threads:[~2014-06-02 21:29 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-06-02 21:30 [PULL 0/2] vhost enhancements for 3.16 Michael S. Tsirkin 2014-06-02 21:30 ` Michael S. Tsirkin 2014-06-02 21:30 ` [PULL 1/2] vhost-net: extend device allocation to vmalloc Michael S. Tsirkin 2014-06-02 21:30 ` Michael S. Tsirkin 2014-06-02 21:30 ` Michael S. Tsirkin [this message] 2014-06-02 21:30 ` [PULL 2/2] vhost: replace rcu with mutex Michael S. Tsirkin 2014-06-02 21:58 ` Eric Dumazet 2014-06-02 21:58 ` Eric Dumazet 2014-06-03 12:48 ` Paolo Bonzini 2014-06-03 12:48 ` Paolo Bonzini 2014-06-03 13:35 ` Vlad Yasevich 2014-06-03 13:35 ` Vlad Yasevich 2014-06-03 13:55 ` Paolo Bonzini 2014-06-03 13:55 ` Paolo Bonzini 2014-06-03 13:57 ` Eric Dumazet 2014-06-03 13:57 ` Eric Dumazet 2014-06-03 14:20 ` Paolo Bonzini 2014-06-03 14:20 ` Paolo Bonzini 2014-06-04 19:51 ` Michael S. Tsirkin 2014-06-04 19:51 ` Michael S. Tsirkin 2014-06-05 10:45 ` Michael S. Tsirkin 2014-06-05 10:45 ` Michael S. Tsirkin 2014-06-04 18:12 ` Michael S. Tsirkin 2014-06-04 18:12 ` Michael S. Tsirkin
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=1401744482-17764-3-git-send-email-mst@redhat.com \ --to=mst@redhat.com \ --cc=davem@davemloft.net \ --cc=kvm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=netdev@vger.kernel.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.