From: Li Feng <fengli@smartx.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org (open list:All patches CC here)
Cc: lifeng1519@gmail.com, Li Feng <fengli@smartx.com>
Subject: [PATCH] vhost: reduce the set_mem_table call frenquency
Date: Tue, 23 Aug 2022 13:38:20 +0800 [thread overview]
Message-ID: <20220823053820.35499-1-fengli@smartx.com> (raw)
If the vhost memory layout doesn't change, don't need to call the vhost
backend.
The set_mem_table is time consuming when sending to vhost-user backend.
On aarch64, the edk2 uefi firmware will write the pflash which will
trigger the vhost_commit hundreds of times.
Signed-off-by: Li Feng <fengli@smartx.com>
---
hw/virtio/vhost.c | 14 ++++++++++++++
include/hw/virtio/vhost.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index f758f177bb..848d2f20d6 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -523,6 +523,11 @@ static void vhost_commit(MemoryListener *listener)
/* Rebuild the regions list from the new sections list */
regions_size = offsetof(struct vhost_memory, regions) +
dev->n_mem_sections * sizeof dev->mem->regions[0];
+ if (dev->mem && dev->started) {
+ g_free(dev->old_mem);
+ dev->old_mem = dev->mem;
+ dev->mem = NULL;
+ }
dev->mem = g_realloc(dev->mem, regions_size);
dev->mem->nregions = dev->n_mem_sections;
used_memslots = dev->mem->nregions;
@@ -542,6 +547,12 @@ static void vhost_commit(MemoryListener *listener)
goto out;
}
+ if (dev->old_mem && dev->regions_size == regions_size &&
+ memcmp(dev->mem, dev->old_mem, dev->regions_size) == 0) {
+ goto out;
+ }
+
+ dev->regions_size = regions_size;
for (i = 0; i < dev->mem->nregions; i++) {
if (vhost_verify_ring_mappings(dev,
(void *)(uintptr_t)dev->mem->regions[i].userspace_addr,
@@ -1445,6 +1456,8 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));
hdev->n_mem_sections = 0;
hdev->mem_sections = NULL;
+ hdev->old_mem = NULL;
+ hdev->regions_size = 0;
hdev->log = NULL;
hdev->log_size = 0;
hdev->log_enabled = false;
@@ -1491,6 +1504,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
}
g_free(hdev->mem);
g_free(hdev->mem_sections);
+ g_free(hdev->old_mem);
if (hdev->vhost_ops) {
hdev->vhost_ops->vhost_backend_cleanup(hdev);
}
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index a346f23d13..b1d7287099 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -73,6 +73,8 @@ struct vhost_dev {
MemoryListener memory_listener;
MemoryListener iommu_listener;
struct vhost_memory *mem;
+ struct vhost_memory *old_mem;
+ int regions_size;
int n_mem_sections;
MemoryRegionSection *mem_sections;
int n_tmp_sections;
--
2.37.2
next reply other threads:[~2022-08-23 5:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 5:38 Li Feng [this message]
2022-08-23 7:12 ` [PATCH] vhost: reduce the set_mem_table call frenquency Li Feng
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=20220823053820.35499-1-fengli@smartx.com \
--to=fengli@smartx.com \
--cc=lifeng1519@gmail.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).