From: Ye Xiaolong <xiaolong.ye@intel.com>
To: Marvin Liu <yong.liu@intel.com>
Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v2 2/2] vhost: cache gpa to hpa translation
Date: Thu, 2 Apr 2020 10:57:54 +0800 [thread overview]
Message-ID: <20200402025754.GB46004@intel.com> (raw)
In-Reply-To: <20200401145011.67357-2-yong.liu@intel.com>
On 04/01, Marvin Liu wrote:
>If Tx zero copy enabled, gpa to hpa mapping table is updated one by
>one. This will harm performance when guest memory backend using 2M
>hugepages. Now add cached mapping table which will sorted by using
>sequence. Address translation will first check cached mapping table,
>then check unsorted mapping table if no match found.
>
>Signed-off-by: Marvin Liu <yong.liu@intel.com>
>
>diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
>index 2087d1400..5cb0e83dd 100644
>--- a/lib/librte_vhost/vhost.h
>+++ b/lib/librte_vhost/vhost.h
>@@ -368,7 +368,9 @@ struct virtio_net {
> struct vhost_device_ops const *notify_ops;
>
> uint32_t nr_guest_pages;
>+ uint32_t nr_cached_guest_pages;
> uint32_t max_guest_pages;
>+ struct guest_page *cached_guest_pages;
> struct guest_page *guest_pages;
>
> int slave_req_fd;
>@@ -553,12 +555,25 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
> {
> uint32_t i;
> struct guest_page *page;
>+ uint32_t cached_pages = dev->nr_cached_guest_pages;
>+
>+ for (i = 0; i < cached_pages; i++) {
>+ page = &dev->cached_guest_pages[i];
>+ if (gpa >= page->guest_phys_addr &&
>+ gpa + size < page->guest_phys_addr + page->size) {
>+ return gpa - page->guest_phys_addr +
>+ page->host_phys_addr;
>+ }
>+ }
>
> for (i = 0; i < dev->nr_guest_pages; i++) {
> page = &dev->guest_pages[i];
>
> if (gpa >= page->guest_phys_addr &&
> gpa + size < page->guest_phys_addr + page->size) {
>+ rte_memcpy(&dev->cached_guest_pages[cached_pages],
>+ page, sizeof(struct guest_page));
>+ dev->nr_cached_guest_pages++;
> return gpa - page->guest_phys_addr +
> page->host_phys_addr;
> }
>diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
>index 79fcb9d19..1bae1fddc 100644
>--- a/lib/librte_vhost/vhost_user.c
>+++ b/lib/librte_vhost/vhost_user.c
>@@ -192,7 +192,9 @@ vhost_backend_cleanup(struct virtio_net *dev)
> }
>
> rte_free(dev->guest_pages);
>+ rte_free(dev->cached_guest_pages);
> dev->guest_pages = NULL;
>+ dev->cached_guest_pages = NULL;
>
> if (dev->log_addr) {
> munmap((void *)(uintptr_t)dev->log_addr, dev->log_size);
>@@ -898,7 +900,7 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,
> uint64_t host_phys_addr, uint64_t size)
> {
> struct guest_page *page, *last_page;
>- struct guest_page *old_pages;
>+ struct guest_page *old_pages, *old_cached_pages;
>
> if (dev->nr_guest_pages == dev->max_guest_pages) {
> dev->max_guest_pages *= 2;
>@@ -906,9 +908,19 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,
> dev->guest_pages = rte_realloc(dev->guest_pages,
> dev->max_guest_pages * sizeof(*page),
> RTE_CACHE_LINE_SIZE);
>- if (dev->guest_pages == NULL) {
>+ old_cached_pages = dev->cached_guest_pages;
>+ dev->cached_guest_pages = rte_realloc(dev->cached_guest_pages,
>+ dev->max_guest_pages *
>+ sizeof(*page),
>+ RTE_CACHE_LINE_SIZE);
>+ dev->nr_cached_guest_pages = 0;
>+ if (dev->guest_pages == NULL ||
>+ dev->cached_guest_pages == NULL) {
> VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n");
> rte_free(old_pages);
>+ rte_free(old_cached_pages);
>+ dev->guest_pages = NULL;
>+ dev->cached_guest_pages = NULL;
> return -1;
> }
> }
>@@ -1078,6 +1090,20 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
> }
> }
>
>+ if (dev->cached_guest_pages == NULL) {
>+ dev->cached_guest_pages = rte_zmalloc(NULL,
>+ dev->max_guest_pages *
>+ sizeof(struct guest_page),
>+ RTE_CACHE_LINE_SIZE);
>+ if (dev->cached_guest_pages == NULL) {
>+ VHOST_LOG_CONFIG(ERR,
>+ "(%d) failed to allocate memory "
>+ "for dev->cached_guest_pages\n",
>+ dev->vid);
>+ return RTE_VHOST_MSG_RESULT_ERR;
>+ }
>+ }
>+
> dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) +
> sizeof(struct rte_vhost_mem_region) * memory->nregions, 0);
> if (dev->mem == NULL) {
>--
>2.17.1
>
Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
next prev parent reply other threads:[~2020-04-02 3:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 15:33 [dpdk-dev] [PATCH] vhost: cache guest/vhost physical address mapping Marvin Liu
2020-03-16 13:48 ` Ye Xiaolong
2020-03-17 1:01 ` Liu, Yong
2020-04-01 14:50 ` [dpdk-dev] [PATCH v2 1/2] vhost: utilize dpdk dynamic memory allocator Marvin Liu
2020-04-01 10:08 ` Gavin Hu
2020-04-01 14:50 ` [dpdk-dev] [PATCH v2 2/2] vhost: cache gpa to hpa translation Marvin Liu
2020-04-01 10:07 ` Gavin Hu
2020-04-01 13:01 ` Liu, Yong
2020-04-02 3:04 ` Gavin Hu
2020-04-02 4:45 ` Liu, Yong
2020-04-03 8:22 ` Ma, LihongX
2020-04-02 2:57 ` Ye Xiaolong [this message]
2020-04-27 8:45 ` Maxime Coquelin
2020-04-28 0:44 ` Liu, Yong
2020-04-02 2:57 ` [dpdk-dev] [PATCH v2 1/2] vhost: utilize dpdk dynamic memory allocator Ye Xiaolong
2020-04-03 8:22 ` Ma, LihongX
2020-04-15 11:15 ` Maxime Coquelin
2020-04-28 9:13 ` [dpdk-dev] [PATCH v3 " Marvin Liu
2020-04-28 9:13 ` [dpdk-dev] [PATCH v3 2/2] vhost: binary search address mapping table Marvin Liu
2020-04-28 15:28 ` Maxime Coquelin
2020-04-28 15:38 ` Liu, Yong
2020-04-28 12:51 ` [dpdk-dev] [PATCH v3 1/2] vhost: utilize dpdk dynamic memory allocator Maxime Coquelin
2020-04-29 1:00 ` [dpdk-dev] [PATCH v4 1/2] net/virtio: add support Virtio link speed feature Marvin Liu
2020-04-29 1:00 ` [dpdk-dev] [PATCH v4 1/2] vhost: utilize dpdk dynamic memory allocator Marvin Liu
2020-04-29 1:00 ` [dpdk-dev] [PATCH v4 2/2] vhost: binary search address mapping table Marvin Liu
2020-04-29 1:01 ` [dpdk-dev] [PATCH v4 2/2] vhost: utilize dpdk dynamic memory allocator Marvin Liu
2020-04-29 1:06 ` Liu, Yong
2020-04-29 17:47 ` Maxime Coquelin
2020-04-29 1:04 ` [dpdk-dev] [PATCH v4 1/2] " Marvin Liu
2020-04-29 1:04 ` [dpdk-dev] [PATCH v4 2/2] vhost: binary search address mapping table Marvin Liu
2020-04-29 11:50 ` Maxime Coquelin
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=20200402025754.GB46004@intel.com \
--to=xiaolong.ye@intel.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=yong.liu@intel.com \
--cc=zhihong.wang@intel.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 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).