diff mbox series

vhost: reduce memory footprint when IOMMU is disabled

Message ID 20220916090202.1190834-1-david.marchand@redhat.com (mailing list archive)
State Accepted
Delegated to: Maxime Coquelin
Headers show
Series vhost: reduce memory footprint when IOMMU is disabled | expand

Checks

Context Check Description
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

David Marchand Sept. 16, 2022, 9:02 a.m. UTC
If an application does not request IOMMU support, we can avoid
allocating a IOMMU pool.

This saves 112kB (IOTLB_CACHE_SIZE * sizeof(struct vhost_iotlb_entry))
per vq.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/vhost/iotlb.c  | 20 +++++++++++---------
 lib/vhost/socket.c |  4 +++-
 lib/vhost/vhost.c  |  7 ++++++-
 lib/vhost/vhost.h  |  5 ++++-
 4 files changed, 24 insertions(+), 12 deletions(-)

Comments

Xia, Chenbo Sept. 22, 2022, 1:08 p.m. UTC | #1
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Friday, September 16, 2022 5:02 PM
> To: dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; Xia, Chenbo
> <chenbo.xia@intel.com>
> Subject: [PATCH] vhost: reduce memory footprint when IOMMU is disabled
> 
> If an application does not request IOMMU support, we can avoid
> allocating a IOMMU pool.
> 
> This saves 112kB (IOTLB_CACHE_SIZE * sizeof(struct vhost_iotlb_entry))
> per vq.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/vhost/iotlb.c  | 20 +++++++++++---------
>  lib/vhost/socket.c |  4 +++-
>  lib/vhost/vhost.c  |  7 ++++++-
>  lib/vhost/vhost.h  |  5 ++++-
>  4 files changed, 24 insertions(+), 12 deletions(-)

The compilation issue seems not related to this patch.

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
Xia, Chenbo Sept. 29, 2022, 8:39 a.m. UTC | #2
> -----Original Message-----
> From: Xia, Chenbo <chenbo.xia@intel.com>
> Sent: Thursday, September 22, 2022 9:09 PM
> To: David Marchand <david.marchand@redhat.com>; dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: RE: [PATCH] vhost: reduce memory footprint when IOMMU is disabled
> 
> > -----Original Message-----
> > From: David Marchand <david.marchand@redhat.com>
> > Sent: Friday, September 16, 2022 5:02 PM
> > To: dev@dpdk.org
> > Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; Xia, Chenbo
> > <chenbo.xia@intel.com>
> > Subject: [PATCH] vhost: reduce memory footprint when IOMMU is disabled
> >
> > If an application does not request IOMMU support, we can avoid
> > allocating a IOMMU pool.
> >
> > This saves 112kB (IOTLB_CACHE_SIZE * sizeof(struct vhost_iotlb_entry))
> > per vq.
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
> >  lib/vhost/iotlb.c  | 20 +++++++++++---------
> >  lib/vhost/socket.c |  4 +++-
> >  lib/vhost/vhost.c  |  7 ++++++-
> >  lib/vhost/vhost.h  |  5 ++++-
> >  4 files changed, 24 insertions(+), 12 deletions(-)
> 
> The compilation issue seems not related to this patch.
> 
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

Applied to next-virtio/main, thanks
diff mbox series

Patch

diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c
index 2a78929e78..6a729e8804 100644
--- a/lib/vhost/iotlb.c
+++ b/lib/vhost/iotlb.c
@@ -341,16 +341,18 @@  vhost_user_iotlb_init(struct virtio_net *dev, struct vhost_virtqueue *vq)
 	TAILQ_INIT(&vq->iotlb_list);
 	TAILQ_INIT(&vq->iotlb_pending_list);
 
-	vq->iotlb_pool = rte_calloc_socket("iotlb", IOTLB_CACHE_SIZE,
-		sizeof(struct vhost_iotlb_entry), 0, socket);
-	if (!vq->iotlb_pool) {
-		VHOST_LOG_CONFIG(dev->ifname, ERR,
-			"Failed to create IOTLB cache pool for vq %"PRIu32"\n",
-			vq->index);
-		return -1;
+	if (dev->flags & VIRTIO_DEV_SUPPORT_IOMMU) {
+		vq->iotlb_pool = rte_calloc_socket("iotlb", IOTLB_CACHE_SIZE,
+			sizeof(struct vhost_iotlb_entry), 0, socket);
+		if (!vq->iotlb_pool) {
+			VHOST_LOG_CONFIG(dev->ifname, ERR,
+				"Failed to create IOTLB cache pool for vq %"PRIu32"\n",
+				vq->index);
+			return -1;
+		}
+		for (i = 0; i < IOTLB_CACHE_SIZE; i++)
+			vhost_user_iotlb_pool_put(vq, &vq->iotlb_pool[i]);
 	}
-	for (i = 0; i < IOTLB_CACHE_SIZE; i++)
-		vhost_user_iotlb_pool_put(vq, &vq->iotlb_pool[i]);
 
 	vq->iotlb_cache_nr = 0;
 
diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index a8df2d484a..608ae577fd 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -228,7 +228,8 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	vhost_set_ifname(vid, vsocket->path, size);
 
 	vhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net,
-		vsocket->net_compliant_ol_flags, vsocket->stats_enabled);
+		vsocket->net_compliant_ol_flags, vsocket->stats_enabled,
+		vsocket->iommu_support);
 
 	vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
 
@@ -905,6 +906,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY;
 	vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;
 	vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE;
+	vsocket->iommu_support = flags & RTE_VHOST_USER_IOMMU_SUPPORT;
 
 	if (vsocket->async_copy &&
 		(flags & (RTE_VHOST_USER_IOMMU_SUPPORT |
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index aa671f47a3..9e5e69f72d 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -771,7 +771,8 @@  vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)
 }
 
 void
-vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats_enabled)
+vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats_enabled,
+	bool support_iommu)
 {
 	struct virtio_net *dev = get_device(vid);
 
@@ -790,6 +791,10 @@  vhost_setup_virtio_net(int vid, bool enable, bool compliant_ol_flags, bool stats
 		dev->flags |= VIRTIO_DEV_STATS_ENABLED;
 	else
 		dev->flags &= ~VIRTIO_DEV_STATS_ENABLED;
+	if (support_iommu)
+		dev->flags |= VIRTIO_DEV_SUPPORT_IOMMU;
+	else
+		dev->flags &= ~VIRTIO_DEV_SUPPORT_IOMMU;
 }
 
 void
diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
index 782d916ae0..3da6f217fd 100644
--- a/lib/vhost/vhost.h
+++ b/lib/vhost/vhost.h
@@ -37,6 +37,8 @@ 
 #define VIRTIO_DEV_LEGACY_OL_FLAGS ((uint32_t)1 << 5)
 /*  Used to indicate the application has requested statistics collection */
 #define VIRTIO_DEV_STATS_ENABLED ((uint32_t)1 << 6)
+/*  Used to indicate the application has requested iommu support */
+#define VIRTIO_DEV_SUPPORT_IOMMU ((uint32_t)1 << 7)
 
 /* Backend value set by guest. */
 #define VIRTIO_DEV_STOPPED -1
@@ -803,7 +805,8 @@  int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);
 void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev);
 
 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
-void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled);
+void vhost_setup_virtio_net(int vid, bool enable, bool legacy_ol_flags, bool stats_enabled,
+	bool support_iommu);
 void vhost_enable_extbuf(int vid);
 void vhost_enable_linearbuf(int vid);
 int vhost_enable_guest_notification(struct virtio_net *dev,