vhost: reduce memory footprint when IOMMU is disabled
PATCH 1/1 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.
--- 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(-)
lib/vhost/iotlb.c +11 -9
@@ -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 ;
lib/vhost/socket.c +3 -1
@@ -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 |
lib/vhost/vhost.c +6 -1
@@ -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
lib/vhost/vhost.h +4 -1
@@ -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,
Signature · 1 line
2.37.3
Quoted 14 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, September 16, 2022 5:02 PM
To: [email protected]
Cc: Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH] vhost: reduce memory footprint when IOMMU is disabledIf 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.
Quoted 7 lines
Signed-off-by David Marchand <[email protected]>--- 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.
Xia, Chenbo
AppliedQuoted 29 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Thursday, September 22, 2022 9:09 PM
To: David Marchand <[email protected]>; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: RE: [PATCH] vhost: reduce memory footprint when IOMMU is disabledQuoted 14 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, September 16, 2022 5:02 PM
To: [email protected]
Cc: Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH] vhost: reduce memory footprint when IOMMU is disabledIf 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.Quoted 7 lines
Signed-off-by David Marchand <[email protected]>--- 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(-)
Quoted 3 lines
The compilation issue seems not related to this patch.
Reviewed-by Chenbo Xia <[email protected]>
Applied to next-virtio/main, thanks