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 9A691A0559; Mon, 16 Mar 2020 14:51:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C6442BF9; Mon, 16 Mar 2020 14:51:08 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 4A8E825D9 for ; Mon, 16 Mar 2020 14:51:07 +0100 (CET) IronPort-SDR: i4Z8gdN+GxiH63tTuAa9RP06UU+y9NuDZxX4F5yQP/9jXwZoZeHwE+4XP9yGQDivqWRcgfz44Z sbWlYTF202zg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2020 06:51:06 -0700 IronPort-SDR: sYBzuXaKGkZqYili9kZLmhS2vY/ZBPwgHxXPQSl1g2+nH/X0yV9cVmIgUFOmWQOgBIywPX07eE XcktZ8yQJrsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,560,1574150400"; d="scan'208";a="417145196" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.117.17]) by orsmga005.jf.intel.com with ESMTP; 16 Mar 2020 06:51:04 -0700 Date: Mon, 16 Mar 2020 21:48:19 +0800 From: Ye Xiaolong To: Marvin Liu Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com, dev@dpdk.org Message-ID: <20200316134819.GE64357@intel.com> References: <20200316153353.112897-1-yong.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200316153353.112897-1-yong.liu@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH] vhost: cache guest/vhost physical address mapping 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" Hi, Marvin On 03/16, 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, >now performance is back. > >Signed-off-by: Marvin Liu > >diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h >index 2087d1400..de2c09e7e 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; What about naming it nr_cached_guest_pages to make it more self-explanatory as nr_cached is too generic? > uint32_t max_guest_pages; >+ struct guest_page *cached_guest_pages; > struct guest_page *guest_pages; > > int slave_req_fd; >@@ -554,11 +556,23 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size) > uint32_t i; > struct guest_page *page; > >+ for (i = 0; i < dev->nr_cached; 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[dev->nr_cached], >+ page, sizeof(struct guest_page)); >+ dev->nr_cached++; > 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 bd1be0104..573e99066 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) > } > > free(dev->guest_pages); >+ 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); >@@ -905,7 +907,10 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, > old_pages = dev->guest_pages; > dev->guest_pages = realloc(dev->guest_pages, > dev->max_guest_pages * sizeof(*page)); >- if (!dev->guest_pages) { >+ dev->cached_guest_pages = realloc(dev->cached_guest_pages, >+ dev->max_guest_pages * sizeof(*page)); >+ dev->nr_cached = 0; >+ if (!dev->guest_pages || !dev->cached_guest_pages) { Better to compare pointer to NULL according to DPDK's coding style. > VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n"); > free(old_pages); > return -1; >@@ -1075,6 +1080,18 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, > } > } > Do we need initialize dev->nr_cached to 0 explicitly here? >+ if (!dev->cached_guest_pages) { >+ dev->cached_guest_pages = malloc(dev->max_guest_pages * >+ sizeof(struct guest_page)); I'm wondering why use malloc/realloc/free for cached_guest_pages instead of DPDK memory allocator APIs, I can see current code uses malloc/realloc/free for guest_pages, Is there any history reason I don't know? Thanks, Xiaolong >+ 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 >