From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3031EA0562; Thu, 2 Apr 2020 05:02:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1839B1BE96; Thu, 2 Apr 2020 05:02:08 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 488601BE91 for ; Thu, 2 Apr 2020 05:02:06 +0200 (CEST) IronPort-SDR: u6L6RgEKEuUzo8GNdRMV3CWEDyPyfBxfyk68w3Hk/p1J+N55XlXmaLI8/HIvwafkPXqOMAJCbT YGUOOu2QCaOg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2020 20:02:05 -0700 IronPort-SDR: UMOyNpdB75b9Dgrci7PFWlLEVG/Tp+CfWSTlHG5BC7XzPp9bH+aPodw4xztlDo4pTHqLCWZOZk g5NYgQKCYgnQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,334,1580803200"; d="scan'208";a="450778733" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.117.17]) by fmsmga006.fm.intel.com with ESMTP; 01 Apr 2020 20:01:23 -0700 Date: Thu, 2 Apr 2020 10:57:54 +0800 From: Ye Xiaolong To: Marvin Liu Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org Message-ID: <20200402025754.GB46004@intel.com> References: <20200316153353.112897-1-yong.liu@intel.com> <20200401145011.67357-1-yong.liu@intel.com> <20200401145011.67357-2-yong.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200401145011.67357-2-yong.liu@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH v2 2/2] vhost: cache gpa to hpa translation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 > >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