Improve virtio performance for 9k mtu
Subsystems (4)
v5 cover Improve virtio performance for 9k mtu
This small series contains two patches that improves virtio netdevice performance for 9K mtu when GRO/ guest TSO is disabled.
Gavin Li (2):
virtio-net: introduce and use helper function for guest gso support
checks
virtio-net: use mtu size as buffer length for big packets
drivers/net/virtio_net.c | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-)
Signature · 6 lines
2.31.1 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
PATCH v5 1/2 virtio-net: introduce and use helper function for guest gso support checks
Probe routine is already several hundred lines.
Use helper function for guest gso support check.
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Remove unnecessary () in return clausev1->v2
- Add new patch
--- drivers/net/virtio_net.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +9 -4
@@ -3682,6 +3682,14 @@ static int virtnet_validate(struct virtio_device *vdev)return 0 ; } +static bool virtnet_check_guest_gso (const struct virtnet_info *vi) +{ +return virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_TSO4 ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_TSO6 ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_ECN ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;
@@ -3777,10 +3785,7 @@ static int virtnet_probe(struct virtio_device *vdev)spin_lock_init (&vi->refill_lock);/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_TSO4 ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_TSO6 ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_ECN ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_UFO )) +if (virtnet_check_guest_gso (vi)) vi->big_packets = true;if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF ))
Signature · 6 lines
2.31.1 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
PATCH v5 2/2 virtio-net: use mtu size as buffer length for big packets
In reply to Gavin LiCurrently add_recvbuf_big() allocates MAX_SKB_FRAGS segments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.
Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during set_guest_offloads() phase, RQs have to be destroyed and recreated, which requires almost driver reload.
If VIRTIO_NET_F_CTRL_GUEST_OFFLOADS has been negotiated, then it should always treat them as GSO enabled.
Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.
Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After
1500 22.5 22.4 9000 12.8 25.9
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Rename big_packets_sg_num with big_packets_num_skbfrags v2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimization v1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, set sg_num for big packets and use it directly
- Recalculate sg_num for big packets in virtnet_set_guest_offloads
- Replace the round up algorithm with DIV_ROUND_UP
--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)
drivers/net/virtio_net.c +24 -13
@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;
@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)
@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);
@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu) +{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;
@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;
@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; } +virtnet_set_big_packets_fields (vi, mtu); +if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;
Signature · 6 lines
2.31.1 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi Michael, Dave/Jakob, Can you please review these two patches? If they are OK, should it be merged through virtio tree or netdev tree?
Quoted 22 lines · Gavin Li
External email: Use caution opening links or attachments
This small series contains two patches that improves virtio netdevice performance for 9K mtu when GRO/ guest TSO is disabled.
Gavin Li (2):
virtio-net: introduce and use helper function for guest gso support
checks
virtio-net: use mtu size as buffer length for big packetsdrivers/net/virtio_net.c | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-)--
2.31.1---------------------------------------------------------------------
To unsubscribe, e-mail:[email protected] For additional commands, e-mail:[email protected]
Re: [virtio-dev] [PATCH v5 1/2] virtio-net: introduce and use helper function for guest gso support checks
In reply to Gavin LiQuoted 8 lines · Gavin Li
Probe routine is already several hundred lines. Use helper function for guest gso support check.
Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>
Quoted 32 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Remove unnecessary () in return clausev1->v2
- Add new patch--- drivers/net/virtio_net.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/net/virtio_net.c +8
-0@@ -3682,6 +3682,14 @@ static int virtnet_validate(struct virtio_device *vdev)return 0 ; } +static bool virtnet_check_guest_gso (const struct virtnet_info *vi) +{ +return virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_TSO4 ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_TSO6 ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_ECN ) || +virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;@@ -3777,10 +3785,7 @@ static int virtnet_probe(struct virtio_device *vdev)spin_lock_init (&vi->refill_lock);
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3791
Quoted 10 lines
drivers/net/virtio_net.c +1
-4/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_TSO4 ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_TSO6 ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_ECN ) || -virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_UFO )) +if (virtnet_check_guest_gso (vi)) vi->big_packets = true;if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF ))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [virtio-dev] [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Gavin LiQuoted 18 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.
Quoted 6 lines
If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.
Nit: Actually, it's not the assumption but the behavior of the codes itself. Since we don't try to change guest offloading in probe so it's ok to check GSO via negotiated features?
Thanks
Quoted 118 lines
Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After1500 22.5 22.4 9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +22
-10@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu) +{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; -
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3875
Quoted 10 lines
drivers/net/virtio_net.c +2
-3-/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; } +virtnet_set_big_packets_fields (vi, mtu); +if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Hi Dave/Jakub, Michael,
Sorry for the previous email formatting.
Should this 2-patch series merge through virtio tree or netdev tree?
Quoted 14 lines · Gavin Li
External email: Use caution opening links or attachments
This small series contains two patches that improves virtio netdevice performance for 9K mtu when GRO/ guest TSO is disabled.
Gavin Li (2):
virtio-net: introduce and use helper function for guest gso support
checks
virtio-net: use mtu size as buffer length for big packetsdrivers/net/virtio_net.c | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-)
Quoted 8 lines
--
2.31.1---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [virtio-dev] [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Jason WangQuoted 25 lines · Jason Wang
External email: Use caution opening links or attachments
Quoted 21 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.
Quoted 8 lines
Quoted 3 lines
Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Nit: Actually, it's not the assumption but the behavior of the codes itself. Since we don't try to change guest offloading in probe so it's ok to check GSO via negotiated features?
ACK
Should be
Quoted 137 lines
Thanks
Quoted 133 lines
Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After
1500 22.5 22.4
9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP
---
drivers/net/virtio_net.c| 37 ++++++++++++++++++++++++-------------1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +5
-3@@ -225,6 +225,9 @@ struct virtnet_info { /* I like... big packets and I cannot lie! */ bool big_packets; + /* number of sg entries allocated for big packets */ + unsigned int big_packets_num_skbfrags; + /* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, char *p; int i, err, offset; - sg_init_table(rq->sg, MAX_SKB_FRAGS + 2); + sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); - /* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ - for (i = MAX_SKB_FRAGS + 1; i > 1; --i) { + /* page in rq->sg[vi->big_packets_num_skbfrags + 1] is listtail */
+ for (i =vi->big_packets_num_skbfrags+ 1; i > 1; --i) { first =get_a_page(rq, gfp);
if (!first) {
if (list)drivers/net/virtio_net.c +1
-1@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, /* chain first in list head */ first->private = (unsigned long)list; - err = virtqueue_add_inbuf(rq->vq, rq->sg, MAX_SKB_FRAGS + 2, + err = virtqueue_add_inbuf(rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err < 0)
give_pages(rq, first);drivers/net/virtio_net.c +15
-1@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi) virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu) +{ + bool guest_gso = virtnet_check_guest_gso(vi); + + /* If device can receive ANY guest GSO packets, regardless of mtu, + * allocate packets of maximum size, otherwise limit it to only + * mtu size worth only. + */ + if (mtu > ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} + static int virtnet_probe(struct virtio_device *vdev) { int i, err = -ENOMEM; struct net_device *dev; struct virtnet_info *vi; u16 max_queue_pairs; - int mtu; + int mtu = 0;/* Find if host supports multiqueue/rss
virtio_netdevice */max_queue_pairs= 1;drivers/net/virtio_net.c +0
-1@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev) INIT_WORK(&vi->config_work, virtnet_config_changed_work); spin_lock_init(&vi->refill_lock); - /* If we can receive ANY GSO packets, we must allocate largeones. */
- if (virtnet_check_guest_gso(vi))
-vi->big_packets= true;
-
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))vi->mergeable_rx_bufs= true;drivers/net/virtio_net.c +0
-4@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - - /* TODO: size buffers correctly in this case. */ - if (dev->mtu > ETH_DATA_LEN) - vi->big_packets = true; }
Quoted 6 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3874
Quoted 5 lines
drivers/net/virtio_net.c +2
-0+ virtnet_set_big_packets_fields(vi, mtu); + if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [virtio-dev] [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 39 lines · Gavin Li
External email: Use caution opening links or attachments
Quoted 34 lines · Jason Wang
External email: Use caution opening links or attachments
Quoted 19 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes
less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.Quoted 6 lines
If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Nit: Actually, it's not the assumption but the behavior of the codes itself. Since we don't try to change guest offloading in probe so it's ok to check GSO via negotiated features?
Above commit log description is incorrect.
It got here from an intermediate patch.
Actually, GSO always takes the priority. If it is offered, driver will always post 64K worth of buffers. When it is not offered, mtu is honored.
Let me repost v6 with above corrected commit log.
Thanks
Quoted 146 lines
Quoted 139 lines
Thanks
Quoted 135 lines
Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After
1500 22.5 22.4
9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP
---
drivers/net/virtio_net.c| 37 ++++++++++++++++++++++++-------------1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +3
-0@@ -225,6 +225,9 @@ struct virtnet_info { /* I like... big packets and I cannot lie! */ bool big_packets; + /* number of sg entries allocated for big packets */ + unsigned int big_packets_num_skbfrags; + /* Host will merge rx buffers for big packets (shake it! shakeit!) */
boolmergeable_rx_bufs;drivers/net/virtio_net.c +2
-3@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, char *p; int i, err, offset; - sg_init_table(rq->sg, MAX_SKB_FRAGS + 2); + sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); - /* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ - for (i = MAX_SKB_FRAGS + 1; i > 1; --i) { + /* page in rq->sg[vi->big_packets_num_skbfrags + 1] is listtail */
+ for (i =vi->big_packets_num_skbfrags+ 1; i > 1; --i) { first =get_a_page(rq, gfp);
if (!first) {
if (list)drivers/net/virtio_net.c +1
-1@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, /* chain first in list head */ first->private = (unsigned long)list; - err = virtqueue_add_inbuf(rq->vq, rq->sg, MAX_SKB_FRAGS + 2, + err = virtqueue_add_inbuf(rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err < 0)
give_pages(rq, first);drivers/net/virtio_net.c +15
-1@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi) virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu) +{ + bool guest_gso = virtnet_check_guest_gso(vi); + + /* If device can receive ANY guest GSO packets, regardless of mtu, + * allocate packets of maximum size, otherwise limit it to only + * mtu size worth only. + */ + if (mtu > ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} + static int virtnet_probe(struct virtio_device *vdev) { int i, err = -ENOMEM; struct net_device *dev; struct virtnet_info *vi; u16 max_queue_pairs; - int mtu; + int mtu = 0;/* Find if host supports multiqueue/rss
virtio_netdevice */max_queue_pairs= 1;drivers/net/virtio_net.c +0
-1@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev) INIT_WORK(&vi->config_work, virtnet_config_changed_work); spin_lock_init(&vi->refill_lock); - /* If we can receive ANY GSO packets, we must allocate largeones. */
- if (virtnet_check_guest_gso(vi))
-vi->big_packets= true;
-
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))vi->mergeable_rx_bufs= true;drivers/net/virtio_net.c +0
-4@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - - /* TODO: size buffers correctly in this case. */ - if (dev->mtu > ETH_DATA_LEN) - vi->big_packets = true; }Quoted 6 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3874
Quoted 5 lines
drivers/net/virtio_net.c +2
-0+ virtnet_set_big_packets_fields(vi, mtu); + if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;
Quoted 4 lines
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Gavin LiQuoted 31 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After
Quoted 8 lines
1500 22.5 22.4 9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>
Which configurations were tested?
Did you test devices without VIRTIO_NET_F_MTU ?
Quoted 59 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +7
-4@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);
drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3696
Quoted 4 lines
drivers/net/virtio_net.c +1
-0@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu)
I'd rename this to just virtnet_set_big_packets.
Quoted 37 lines
drivers/net/virtio_net.c +14
-5+{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev)
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 10 lines
drivers/net/virtio_net.c +2
-4dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; } +virtnet_set_big_packets_fields (vi, mtu); +
If VIRTIO_NET_F_MTU is off, then mtu is uninitialized. You should move it to within if () above to fix.
Quoted 5 lines
drivers/net/virtio_net.c +0
-0if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;Signature · 1 line
2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 38 lines · Michael S. Tsirkin
External email: Use caution opening links or attachments
Quoted 34 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After1500 22.5 22.4 9000 12.8 25.9
Quoted 7 lines
Quoted 5 lines
Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>Which configurations were tested?
I tested it with DPDK vDPA + qemu vhost. Do you mean the feature set of the VM?
Quoted 1 line
Did you test devices without
VIRTIO_NET_F_MTU?
No. It will need code changes.
Quoted 63 lines
Quoted 63 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +7
-4@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); }
Quoted 3 lines
drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3696
Quoted 1 line
drivers/net/virtio_net.c +1
-0+static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu)I'd rename this to just
virtnet_set_big_packets.
ACK
Quoted 47 lines
Quoted 47 lines
drivers/net/virtio_net.c +14
-9+{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; }
Quoted 4 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 2 lines
drivers/net/virtio_net.c +2
-0+virtnet_set_big_packets_fields (vi, mtu); +If
VIRTIO_NET_F_MTUis off, then mtu is uninitialized. You should move it to within if () above to fix.
mtu was initialized to 0 at the beginning of probe if VIRTIO_NET_F_MTU is off.
In this case, big_packets_num_skbfrags will be set according to guest gso.
If guest gso is supported, it will be set to MAX_SKB_FRAGS else zero---- do you
think this is a bug to be fixed?
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 5 lines · Gavin Li
Quoted 3 lines · Michael S. Tsirkin
External email: Use caution opening links or attachments
Quoted 8 lines
Quoted 8 lines · Gavin Li
Quoted 7 lines
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.
actually how does this waste space? Is this because your device does not have INDIRECT?
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After1500 22.5 22.4 9000 12.8 25.9
is this buffer space?
just the overhead of allocating/freeing the buffers? of using INDIRECT?
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>Which configurations were tested?
I tested it with DPDK vDPA + qemu vhost. Do you mean the feature set of the VM?
yes
Quoted 2 lines
Quoted 1 line
Did you test devices without
VIRTIO_NET_F_MTU?No. It will need code changes.
Testing to make sure nothing broke should not require changes.
Quoted 121 lines
Quoted 63 lines
Quoted 63 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +7
-4@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); }Quoted 3 lines
drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3696
Quoted 1 line
drivers/net/virtio_net.c +1
-0+static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu)I'd rename this to just
virtnet_set_big_packets.ACK
Quoted 47 lines
Quoted 47 lines
drivers/net/virtio_net.c +14
-9+{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; }Quoted 4 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 2 lines
drivers/net/virtio_net.c +2
-0+virtnet_set_big_packets_fields (vi, mtu); +If
VIRTIO_NET_F_MTUis off, then mtu is uninitialized. You should move it to within if () above to fix.mtu was initialized to 0 at the beginning of probe if
VIRTIO_NET_F_MTUis off.
Quoted 6 lines
In this case,
big_packets_num_skbfragswill be set according to guest gso.If guest gso is supported, it will be set to
MAX_SKB_FRAGSelse zero---- do youthink this is a bug to be fixed?
yes I think with no mtu this should behave as it did historically.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 14 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 5:27 AMQuoted 8 lines · Gavin Li
Quoted 6 lines · Michael S. Tsirkin
External email: Use caution opening links or attachments
Quoted 2 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on thedevice.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors.
Each descriptor points to a page of 4K.
These descriptors are chained as 4K * 16.
So total packets that can be serviced are 256/16 = 16. So effective queue depth = 16.
So, when GSO is off, for 9K mtu, packet buffer needed = 3 pages. (12k). So, 13 descriptors (= 13 x 4K =52K) per packet buffer is wasted.
After this improvement, these 13 descriptors are available, increasing the effective queue depth = 256/3 = 85.
[..]
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
MTU(Bytes)/Bandwidth (Gbit/s)
Before After1500 22.5 22.4 9000 12.8 25.9is this buffer space?
Above performance numbers are showing improvement in bandwidth. In Gbps/sec.
Quoted 2 lines
just the overhead of allocating/freeing the buffers? of using INDIRECT?
The effective queue depth is so small, device cannot receive all the packets at given bw-delay product.
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Which configurations were tested?
I tested it with DPDK vDPA + qemu vhost. Do you mean the feature set of the VM?
The configuration of interest is mtu, not the backend. Which is different mtu as shown in above perf numbers.
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Did you test devices without
VIRTIO_NET_F_MTU?No. It will need code changes.
No. It doesn't need any code changes. This is misleading/vague.
This patch doesn't have any relation to a device which doesn't offer VIRTIO_NET_F_MTU. Just the code restructuring is touching this area, that may require some existing tests. I assume virtio tree will have some automation tests for such a device?
Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +0
-4@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; }Quoted 4 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 2 lines
drivers/net/virtio_net.c +2
-0+virtnet_set_big_packets_fields (vi, mtu); +If
VIRTIO_NET_F_MTUis off, then mtu is uninitialized. You should move it to within if () above to fix.mtu was initialized to 0 at the beginning of probe if
VIRTIO_NET_F_MTUis off.In this case,
big_packets_num_skbfragswill be set according to guest gso.
Quoted 8 lines
Quoted 4 lines
If guest gso is supported, it will be set to
MAX_SKB_FRAGSelse zero---- do youthink this is a bug to be fixed?
yes I think with no mtu this should behave as it did historically.
Michael is right.
It should behave as today. There is no new bug introduced by this patch. dev->mtu and dev->max_mtu is set only when VIRTIO_NET_F_MTU is offered with/without this patch.
Please have mtu related fix/change in different patch.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 20 lines · Parav Pandit
Quoted 20 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 5:27 AMQuoted 8 lines · Gavin Li
Quoted 6 lines · Michael S. Tsirkin
External email: Use caution opening links or attachments
Quoted 2 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on thedevice.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors.
Each descriptor points to a page of 4K.
These descriptors are chained as 4K * 16.
So without indirect then? with indirect each descriptor can point to 16 entries.
Quoted 31 lines
So total packets that can be serviced are 256/16 = 16. So effective queue depth = 16.
So, when GSO is off, for 9K mtu, packet buffer needed = 3 pages. (12k). So, 13 descriptors (= 13 x 4K =52K) per packet buffer is wasted.
After this improvement, these 13 descriptors are available, increasing the effective queue depth = 256/3 = 85.
[..]
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
MTU(Bytes)/Bandwidth (Gbit/s)
Before After1500 22.5 22.4 9000 12.8 25.9is this buffer space?
Above performance numbers are showing improvement in bandwidth. In Gbps/sec.
Quoted 2 lines
just the overhead of allocating/freeing the buffers? of using INDIRECT?
The effective queue depth is so small, device cannot receive all the packets at given bw-delay product.
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Which configurations were tested?
I tested it with DPDK vDPA + qemu vhost. Do you mean the feature set of the VM?
The configuration of interest is mtu, not the backend. Which is different mtu as shown in above perf numbers.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Did you test devices without
VIRTIO_NET_F_MTU?No. It will need code changes.
No. It doesn't need any code changes. This is misleading/vague.
This patch doesn't have any relation to a device which doesn't offer
VIRTIO_NET_F_MTU. Just the code restructuring is touching this area, that may require some existing tests. I assume virtio tree will have some automation tests for such a device?
I have some automated tests but I also expect developer to do testing.
Quoted 27 lines
Quoted 27 lines
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/virtio_net.c +0
-4@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true; }Quoted 4 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 2 lines
drivers/net/virtio_net.c +2
-0+virtnet_set_big_packets_fields (vi, mtu); +If
VIRTIO_NET_F_MTUis off, then mtu is uninitialized. You should move it to within if () above to fix.mtu was initialized to 0 at the beginning of probe if
VIRTIO_NET_F_MTUis off.In this case,
big_packets_num_skbfragswill be set according to guest gso.If guest gso is supported, it will be set to
MAX_SKB_FRAGSelse zero---- do youthink this is a bug to be fixed?
Quoted 14 lines
Quoted 2 lines
yes I think with no mtu this should behave as it did historically.
Michael is right.
It should behave as today. There is no new bug introduced by this patch.dev->mtuanddev->max_mtuis set only whenVIRTIO_NET_F_MTUis offered with/without this patch.Please have mtu related fix/change in different patch.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM
[..]
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.So without indirect then? with indirect each descriptor can point to 16 entries.
With indirect, can it post 256 * 16 size buffers even though vq depth is 256 entries? I recall that total number of descriptors with direct/indirect descriptors is limited to vq depth. Was there some recent clarification occurred in the spec to clarify this?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 12 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM[..]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.
Quoted 8 lines
Quoted 3 lines
So without indirect then? with indirect each descriptor can point to 16 entries.
With indirect, can it post 256 * 16 size buffers even though vq depth is 256 entries? I recall that total number of descriptors with direct/indirect descriptors is limited to vq depth.
Was there some recent clarification occurred in the spec to clarify this?
This would make INDIRECT completely pointless. So I don't think we ever had such a limitation.
The only thing that comes to mind is this:
A driver MUST NOT create a descriptor chain longer than the Queue Size of the device.
but this limits individual chain length not the total length of all chains.
We have an open bug that we forgot to include this requirement in the packed ring documentation.
Signature · 6 lines
MST --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 33 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:40 AMQuoted 12 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM[..]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.Quoted 4 lines
Quoted 3 lines
So without indirect then? with indirect each descriptor can point to 16 entries.
With indirect, can it post 256 * 16 size buffers even though vq depth is 256
entries?
Quoted 1 line
I recall that total number of descriptors with direct/indirect descriptors is
limited to vq depth.
Quoted 1 line
Was there some recent clarification occurred in the spec to clarify this?
This would make INDIRECT completely pointless. So I don't think we ever had such a limitation.
The only thing that comes to mind is this:
Quoted 6 lines
A driver MUST NOT create a descriptor chain longer than the Queue
Size of
the device.but this limits individual chain length not the total length of all chains.
Right.
I double checked in virtqueue_add_split() which doesn't count table entries towards desc count of VQ for indirect case.
With indirect descriptors without this patch the situation is even worse with memory usage. Driver will allocate 64K * 256 = 16MB buffer per VQ, while needed (and used) buffer is only 2.3 Mbytes.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 37 lines · Parav Pandit
Quoted 37 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:40 AMQuoted 12 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM[..]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.Quoted 4 lines
Quoted 3 lines
So without indirect then? with indirect each descriptor can point to 16 entries.
With indirect, can it post 256 * 16 size buffers even though vq depth is 256
entries?
Quoted 1 line
I recall that total number of descriptors with direct/indirect descriptors is
limited to vq depth.
Quoted 1 line
Was there some recent clarification occurred in the spec to clarify this?
This would make INDIRECT completely pointless. So I don't think we ever had such a limitation.
The only thing that comes to mind is this:A driver MUST NOT create a descriptor chain longer than the Queue
Size of
the device.
Quoted 7 lines
Quoted 2 lines
but this limits individual chain length not the total length of all chains.
Right.
I double checked invirtqueue_add_split()which doesn't count table entries towards desc count of VQ for indirect case.With indirect descriptors without this patch the situation is even worse with memory usage. Driver will allocate 64K * 256 = 16MB buffer per VQ, while needed (and used) buffer is only 2.3 Mbytes.
Yes. So just so we understand the reason for the performance improvement is this because of memory usage? Or is this because device does not have INDIRECT?
Thanks,
Signature · 1 line
MST
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 50 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 2:16 PMQuoted 36 lines · Parav Pandit
Quoted 36 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:40 AMQuoted 12 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM[..]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.Quoted 6 lines
Quoted 4 lines
So without indirect then? with indirect each descriptor can point to
16 entries.With indirect, can it post 256 * 16 size buffers even though vq depth is 256
entries?
Quoted 2 lines
I recall that total number of descriptors with direct/indirect descriptors is
limited to vq depth.
Quoted 1 line
Was there some recent clarification occurred in the spec to clarify this?
This would make INDIRECT completely pointless. So I don't think we ever had such a limitation.
The only thing that comes to mind is this:Quoted 8 lines
Quoted 6 lines
A driver MUST NOT create a descriptor chain longer than the Queue
Size of
the device.but this limits individual chain length not the total length of all chains.
Right.
I double checked invirtqueue_add_split()which doesn't count tableentries towards desc count of VQ for indirect case.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
With indirect descriptors without this patch the situation is even worse
with memory usage.
Quoted 1 line
Driver will allocate 64K * 256 = 16MB buffer per VQ, while needed (and
used) buffer is only 2.3 Mbytes.
Yes. So just so we understand the reason for the performance improvement is this because of memory usage? Or is this because device does not have INDIRECT?
Because of shallow queue of 16 entries deep.
With driver turn around time to repost buffers, device is idle without any RQ buffers. With this improvement, device has 85 buffers instead of 16 to receive packets.
Enabling indirect in device can help at cost of 7x higher memory per VQ in the guest VM.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 52 lines · Parav Pandit
Quoted 52 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 2:16 PMQuoted 36 lines · Parav Pandit
Quoted 36 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:40 AMQuoted 12 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 10:30 AM[..]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
actually how does this waste space? Is this because your device does not have INDIRECT?
VQ is 256 entries deep.
Driver posted total of 256 descriptors. Each descriptor points to a page of 4K. These descriptors are chained as 4K * 16.Quoted 6 lines
Quoted 4 lines
So without indirect then? with indirect each descriptor can point to
16 entries.With indirect, can it post 256 * 16 size buffers even though vq depth is 256
entries?
Quoted 2 lines
I recall that total number of descriptors with direct/indirect descriptors is
limited to vq depth.
Quoted 1 line
Was there some recent clarification occurred in the spec to clarify this?
This would make INDIRECT completely pointless. So I don't think we ever had such a limitation.
The only thing that comes to mind is this:Quoted 8 lines
Quoted 6 lines
A driver MUST NOT create a descriptor chain longer than the Queue
Size of
the device.but this limits individual chain length not the total length of all chains.
Right.
I double checked invirtqueue_add_split()which doesn't count tableentries towards desc count of VQ for indirect case.
Quoted 2 lines
With indirect descriptors without this patch the situation is even worse
with memory usage.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Driver will allocate 64K * 256 = 16MB buffer per VQ, while needed (and
used) buffer is only 2.3 Mbytes.
Yes. So just so we understand the reason for the performance improvement is this because of memory usage? Or is this because device does not have INDIRECT?
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
does the device not support indirect?
because with indirect you get 256 entries, with 16 s/g each.
Quoted 4 lines
With driver turn around time to repost buffers, device is idle without any RQ buffers. With this improvement, device has 85 buffers instead of 16 to receive packets.
Enabling indirect in device can help at cost of 7x higher memory per VQ in the guest VM.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 7 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
Quoted 2 lines
does the device not support indirect?
Yes, indirect feature bit is disabled on the device.
Quoted 2 lines
because with indirect you get 256 entries, with 16 s/g each.
Sure. I explained below that indirect comes with 7x memory cost that is not desired. (Ignored the table memory allocation cost and extra latency).
Hence don't want to enable indirect in this scenario.
This optimization also works with indirect with smaller indirect table.
Quoted 8 lines
Quoted 2 lines
With driver turn around time to repost buffers, device is idle without any
RQ buffers.
Quoted 1 line
With this improvement, device has 85 buffers instead of 16 to receive
packets.
Quoted 2 lines
Enabling indirect in device can help at cost of 7x higher memory per VQ in
the guest VM.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 6 lines · Parav Pandit
Quoted 6 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 1 line
Because of shallow queue of 16 entries deep.
Quoted 8 lines
Quoted 1 line
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
Quoted 2 lines
does the device not support indirect?
Yes, indirect feature bit is disabled on the device.
OK that explains it.
Quoted 4 lines
Quoted 2 lines
because with indirect you get 256 entries, with 16 s/g each.
Sure. I explained below that indirect comes with 7x memory cost that is not desired. (Ignored the table memory allocation cost and extra latency).
Oh sure, it's a waste. I wonder what effect does the patch have on bandwidth with indirect enabled though.
Quoted 11 lines
Hence don't want to enable indirect in this scenario.
This optimization also works with indirect with smaller indirect table.Quoted 8 lines
Quoted 2 lines
With driver turn around time to repost buffers, device is idle without any
RQ buffers.
Quoted 1 line
With this improvement, device has 85 buffers instead of 16 to receive
packets.
Quoted 2 lines
Enabling indirect in device can help at cost of 7x higher memory per VQ in
the guest VM.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 18 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:24 PMQuoted 11 lines · Parav Pandit
Quoted 7 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
[1]
https://lore.kernel.org/netdev/PH0PR12MB54812EC7F4711C1EA4CAA119DC
419@
Quoted 7 lines
Quoted 5 lines
PH0PR12MB5481.namprd12.prod.outlook.com/
Quoted 2 lines
does the device not support indirect?
Yes, indirect feature bit is disabled on the device.
OK that explains it.
So can we proceed with v6 to contain
(a) updated commit message and
(b) function name change you suggested to drop _fields suffix?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 22 lines · Parav Pandit
Quoted 22 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:24 PMQuoted 11 lines · Parav Pandit
Quoted 7 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
[1]
https://lore.kernel.org/netdev/PH0PR12MB54812EC7F4711C1EA4CAA119DC
419@Quoted 4 lines
PH0PR12MB5481.namprd12.prod.outlook.com/
Quoted 2 lines
does the device not support indirect?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Yes, indirect feature bit is disabled on the device.
OK that explains it.
So can we proceed with v6 to contain
(a) updated commit message and
(b) function name change you suggested to drop_fieldssuffix?
(c) replace mtu = 0 with sensibly not calling the function when mtu is unknown.
And I'd like commit log to include results of perf testing
- with indirect feature on
- with mtu feature off
just to make sure nothing breaks.
Signature · 6 lines
MST --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 31 lines · Michael S. Tsirkin
Quoted 22 lines · Parav Pandit
Quoted 22 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:24 PMQuoted 11 lines · Parav Pandit
Quoted 7 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
[1]
https://lore.kernel.org/netdev/PH0PR12MB54812EC7F4711C1EA4CAA119DC
419@Quoted 4 lines
PH0PR12MB5481.namprd12.prod.outlook.com/
Quoted 2 lines
does the device not support indirect?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Yes, indirect feature bit is disabled on the device.
OK that explains it.
So can we proceed with v6 to contain
(a) updated commit message and
(b) function name change you suggested to drop_fieldssuffix?
Quoted 8 lines
(c) replace mtu = 0 with sensibly not calling the function when mtu is unknown.
And I'd like commit log to include results of perf testing
- with indirect feature on
- with mtu feature off
just to make sure nothing breaks.
and if possible a larger ring. 1k?
Quoted 2 lines
Signature · 1 line
MST
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Michael S. TsirkinQuoted 36 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:36 PMQuoted 9 lines · Parav Pandit
Quoted 9 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:24 PMQuoted 4 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
[1]
https://lore.kernel.org/netdev/PH0PR12MB54812EC7F4711C1EA4CAA119DC
Quoted 5 lines
Quoted 5 lines
419@
Quoted 4 lines
PH0PR12MB5481.namprd12.prod.outlook.com/
Quoted 2 lines
does the device not support indirect?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Yes, indirect feature bit is disabled on the device.
OK that explains it.
So can we proceed with v6 to contain
(a) updated commit message and
(b) function name change you suggested to drop_fieldssuffix?
Quoted 7 lines
(c) replace mtu = 0 with sensibly not calling the function when mtu is unknown.
And I'd like commit log to include results of perf testing
- with indirect feature on
Which device do you suggest using for this test?
Quoted 1 line
- with mtu feature off
Why is this needed when it is not touching the area of mtu being not offered?
Quoted 1 line
just to make sure nothing breaks.
Not sure why you demand this.
Can you please share the link to other patches that ensured that nothing breaks, for example I didn't see a similar "test ask" in v14 series [1]? What is so special about current patch of interest vs [1] that requires this special testing details in commit log, and it is not required in [1] or past patches? Do you have link to the tests done with synchronization tests by commit [2]?
This will help to define test matrix for developers and internal regression and similar report in all subsequent patches like [1].
[1] https://lore.kernel.org/bpf/[email protected]/
[2] 6213f07cb54
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Michael S. TsirkinQuoted 5 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:38 PMand if possible a larger ring. 1k?
What do you expect to see here for which test report should be added to commit log? What is special about 1k vs 512, 128 and 2k? is 1K default for some configuration?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Michael S. TsirkinQuoted 6 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:36 PM(c) replace mtu = 0 with sensibly not calling the function when mtu is unknown.
Even when mtu is zero, virtnet_set_big_packets() must be called to act on the gso bits. Currently handling by virtnet_set_big_packets() seems more simpler taking care of mtu and gso both.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [virtio-dev] RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Parav PanditQuoted 4 lines · Parav Pandit
Quoted 2 lines
And I'd like commit log to include results of perf testing
- with indirect feature onWhich device do you suggest using for this test?
You may use software vhost-net backend with and without fix to compare. Since this driver fix effectively lowers down the buffer size for the indirect=on case as well, it's a natural request to make sure no perf degradation is seen on devices with indirect descriptor enabled. I don't expect degradation though and think this patch should improve efficiency with less memory foot print.
Cheers,
-Siwei
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [virtio-dev] RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 5 lines
From: Si-Wei Liu <[email protected]>
Sent: Wednesday, September 7, 2022 5:40 PM
Quoted 8 lines
Quoted 4 lines · Parav Pandit
Quoted 2 lines
And I'd like commit log to include results of perf testing
- with indirect feature onWhich device do you suggest using for this test?
You may use software vhost-net backend with and without fix to compare. Since this driver fix effectively lowers down the buffer size for the indirect=on case as well,
Do you have sample example for this?
Quoted 5 lines
it's a natural request to make sure no perf
degradation is seen on devices with indirect descriptor enabled. I don't expect degradation though and think this patch should improve efficiency with less memory foot print.
Any specific reason to discount test for the packed vq here because the change applies to packed vq too?
It is counter intuitive to see degradation with smaller size buffers.
But sure, code reviews can miss things that can bring regression for which it should be tested.
I am not against the test itself. It is good thing to do more test coverage.
What is puzzling me is, I fail to see test results not available in previous commits and cover letters, which is making this patch special for test coverage. Or a new trend begins with this specific patch onwards?
For example, I don’t see a test results in commit [1], [2], [3] to indicate that no degradation is seen which heavily touches the lock in core data path.
So want to know test reporting guidelines in the commit logs for this and other patches.
[1] commit 5a2f966d0f
[2] commit a7766ef18b33
[3] commit 22bc63c58e876
Re: [virtio-dev] RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 5 lines · Parav Pandit
Quoted 5 lines
From: Si-Wei Liu <[email protected]>
Sent: Wednesday, September 7, 2022 5:40 PMOn 9/7/2022 12:51 PM, Parav Pandit wrote:
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And I'd like commit log to include results of perf testing
- with indirect feature onWhich device do you suggest using for this test?
You may use software vhost-net backend with and without fix to compare. Since this driver fix effectively lowers down the buffer size for the indirect=on case as well,
Do you have sample example for this?
ip link add link ens300f1 name macvtap1 address $mac type macvtap mode bridge ifindex1=cat /sys/class/net/macvtap1/ifindex
qemu-system-x86_64 \
...
-netdev type=tap,id=hnet1,vhost=on,fd=25,vhostfd=27 \
-device virtio-net-pci,netdev=hnet1,id=vnet1,mac=$mac,host_mtu=9000,mrg_rxbuf=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,guest_ufo=off,indirect_desc=on \
25<>/dev/tap${ifindex1} 27<>/dev/vhost-net
indirect_desc=on is not actually required as it's on by default if not specified.
-Siwei
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Jakub Kicinski
maintainerQuoted 4 lines · On Wed, 7 Sep 2022 10:57:01 +0800 Gavin Li wrote:
Hi Dave/Jakub, Michael,
Sorry for the previous email formatting.
Should this 2-patch series merge through virtio tree or netdev tree?
netdev seems appropriate, sorry for the delay
Quoted 9 lines · Jakub Kicinski
External email: Use caution opening links or attachments
Quoted 4 lines · On Wed, 7 Sep 2022 10:57:01 +0800 Gavin Li wrote:
Hi Dave/Jakub, Michael,
Sorry for the previous email formatting.
Should this 2-patch series merge through virtio tree or netdev tree?netdev seems appropriate, sorry for the delay
v6 is posted at linkhttps://lore.kernel.org/netdev/[email protected]/
Would you please review it?
Quoted 9 lines · Jakub Kicinski
External email: Use caution opening links or attachments
Quoted 4 lines · On Wed, 7 Sep 2022 10:57:01 +0800 Gavin Li wrote:
Hi Dave/Jakub, Michael,
Sorry for the previous email formatting.
Should this 2-patch series merge through virtio tree or netdev tree?netdev seems appropriate, sorry for the delay
Sorry for the non-text format issue of last mail.
v6 is posted at link https://lore.kernel.org/netdev/[email protected]/
Would you please review it?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Jakub Kicinski
maintainerQuoted 5 lines · On Tue, 20 Sep 2022 21:45:55 +0800 Gavin Li wrote:
Sorry for the non-text format issue of last mail.
v6 is posted at link
https://lore.kernel.org/netdev/[email protected]/
Would you please review it?
I presume you put me on To: "just because", but FWIW the patches LGTM. Maybe repost them, perhaps they fell off Michael's and Jason's radar due to LPC?
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Parav PanditQuoted 36 lines · Parav Pandit
Quoted 36 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:36 PMQuoted 9 lines · Parav Pandit
Quoted 9 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:24 PMQuoted 4 lines · Parav Pandit
Quoted 3 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, September 7, 2022 3:12 PMQuoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Because of shallow queue of 16 entries deep.
but why is the queue just 16 entries?
I explained the calculation in [1] about 16 entries.
[1]
https://lore.kernel.org/netdev/PH0PR12MB54812EC7F4711C1EA4CAA119DC
Quoted 12 lines
Quoted 8 lines
419@
Quoted 5 lines
PH0PR12MB5481.namprd12.prod.outlook.com/
Quoted 2 lines
does the device not support indirect?
Yes, indirect feature bit is disabled on the device.
OK that explains it.
So can we proceed with v6 to contain
(a) updated commit message and
(b) function name change you suggested to drop_fieldssuffix?
Quoted 8 lines
Quoted 7 lines
(c) replace mtu = 0 with sensibly not calling the function when mtu is unknown.
And I'd like commit log to include results of perf testing
- with indirect feature onWhich device do you suggest using for this test?
AFAIK most devices support INDIRECT, e.g. don't nvidia cards do this?
Quoted 2 lines
Quoted 1 line
- with mtu feature off
Why is this needed when it is not touching the area of mtu being not offered?
I don't really like it that instead of checking the MTU feature bit everywhere the patch sets mtu variable to 0. Because of this it wasn't all that obvious that the patch did not affect !MTU performance (the code does change).
Rereading it afresh I think it's ok. But explicit check for !MTU would be better imho making it obvious we do not need to test !MTU.
Signature · 6 lines
MST --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Gavin LiQuoted 31 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Below is the iperf TCP test results over a Mellanox NIC, using vDPA for 1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.
MTU(Bytes)/Bandwidth (Gbit/s)
Before After
Quoted 8 lines
1500 22.5 22.4 9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>
OK I think the logic is correct, it's just a bit harder to read than necessary. Small improvement suggestions:
Quoted 26 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c +0
-0
drivers/net/virtio_net.c struct virtnet_info { · line 233
Quoted 9 lines
drivers/net/virtio_net.c +3
-0@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;
big_packets_num_skbfrags -> big_packet_num_skbfrags
Quoted 40 lines
drivers/net/virtio_net.c +17
-4@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(const struct virtnet_info *vi)virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi,const int mtu) +{ +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?MAX_SKB_FRAGS :DIV_ROUND_UP (mtu,PAGE_SIZE ); + } +}
drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3717
Quoted 10 lines
drivers/net/virtio_net.c +2
-1+static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;
I think it's better to drop this and instead just put the code where we already know the config. So:
Quoted 14 lines
drivers/net/virtio_net.c +0
-4/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device *vdev)INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */ -if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3859
Quoted 7 lines
drivers/net/virtio_net.c +0
-4@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device *vdev) dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true;
/* Size buffers to fit mtu. */
if (mtu > ETH_DATA_LEN) {
vi->big_packets = true;
vi->big_packets_num_skbfrags = DIV_ROUND_UP(mtu, PAGE_SIZE);
}drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 4 lines
drivers/net/virtio_net.c +2
-0} +virtnet_set_big_packets_fields (vi, mtu); +
and here:
/* If device can receive guest GSO packets, allocate buffers for
* packets of maximum size, regardless of mtu.
*/
if (virtnet_check_guest_gso(vi)) {
vi->big_packets = true;
vi->big_packets_num_skbfrags = MAX_SKB_FRAGS;
}Quoted 5 lines
drivers/net/virtio_net.c +0
-0if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len;Signature · 1 line
2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 163 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Thursday, September 22, 2022 5:35 AMQuoted 32 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Below is the iperf TCP test results over a Mellanox NIC, using vDPA for
1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.MTU(Bytes)/Bandwidth (Gbit/s)
Before AfterQuoted 8 lines
1500 22.5 22.4 9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>OK I think the logic is correct, it's just a bit harder to read than necessary. Small improvement suggestions:
Quoted 26 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0
-0
f831a0290998..dbffd5f56fb8100644drivers/net/virtio_net.c struct virtnet_info { · line 233
Quoted 9 lines
drivers/net/virtio_net.c +3
-0@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;
big_packets_num_skbfrags->big_packet_num_skbfragsdrivers/net/virtio_net.c static int add_recvbuf_big(struct virtnet_info
Quoted 1 line
drivers/net/virtio_net.c +0
-0@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info*vi, struct
receive_queue*rq,drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const
Quoted 25 lines
drivers/net/virtio_net.c +5
-4char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, +vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(conststruct
virtnet_info*vi)drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi)
Quoted 13 lines
drivers/net/virtio_net.c +11
-0virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi, +const int mtu) { +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?
MAX_SKB_FRAGS:DIV_ROUND_UP(mtu, PAGE_SIZE);drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3717
Quoted 11 lines
drivers/net/virtio_net.c +4
-1+ } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;I think it's better to drop this and instead just put the code where we already know the config. So:
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device
Quoted 3 lines
drivers/net/virtio_net.c +0
-0/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device*vdev)
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)
Quoted 4 lines
drivers/net/virtio_net.c +0
-1INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device
Quoted 7 lines
drivers/net/virtio_net.c +0
-3-if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device*vdev)
Quoted 1 line
Quoted 14 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3859
Quoted 6 lines
drivers/net/virtio_net.c +0
-4dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true;/* Size buffers to fit mtu. */ if (mtu > ETH_DATA_LEN) { vi->big_packets = true; vi->big_packets_num_skbfrags = DIV_ROUND_UP(mtu, PAGE_SIZE); }
How doing things twice is better i.e. when mtu is > ETH_DATA_LEN and gso is offered? It calculates big_packets variable twice.
It also easier to read the code at single place where big_packets decision is taken.
Quoted 6 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 4 lines
drivers/net/virtio_net.c +2
-0} +virtnet_set_big_packets_fields (vi, mtu); +and here:
Quoted 15 lines
/* If device can receive guest GSO packets, allocate buffers for * packets of maximum size, regardless of mtu. */ if (virtnet_check_guest_gso(vi)) { vi->big_packets = true; vi->big_packets_num_skbfrags = MAX_SKB_FRAGS; }Quoted 5 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Michael S. TsirkinQuoted 10 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Thursday, September 22, 2022 5:27 AMQuoted 4 lines
Quoted 3 lines
And I'd like commit log to include results of perf testing
- with indirect feature onWhich device do you suggest using for this test?
AFAIK most devices support INDIRECT, e.g. don't nvidia cards do this?
The device of interest didn't have INDIRECT support.
But the question is no more relevant as Gavin supplied the numbers with INDIRECT in commit log of v6.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Michael S. Tsirkin
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Parav PanditQuoted 177 lines · Parav Pandit
Quoted 163 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Thursday, September 22, 2022 5:35 AMQuoted 32 lines · Gavin Li
Currently
add_recvbuf_big()allocatesMAX_SKB_FRAGSsegments for big packets even when GUEST_* offloads are not present on the device. However, if guest GSO is not supported, it would be sufficient to allocate segments to cover just up the MTU size and no further. Allocating the maximum amount of segments results in a large waste of buffer space in the queue, which limits the number of packets that can be buffered and can result in reduced performance.Therefore, if guest GSO is not supported, use the MTU to calculate the optimal amount of segments required.
When guest offload is enabled at runtime, RQ already has packets of bytes less than 64K. So when packet of 64KB arrives, all the packets of such size will be dropped. and RQ is now not usable.
So this means that during
set_guest_offloads()phase, RQs have to be destroyed and recreated, which requires almost driver reload.If
VIRTIO_NET_F_CTRL_GUEST_OFFLOADShas been negotiated, then it should always treat them as GSO enabled.Accordingly, for now the assumption is that if guest GSO has been negotiated then it has been enabled, even if it's actually been disabled at runtime through
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.Below is the iperf TCP test results over a Mellanox NIC, using vDPA for
1 VQ, queue size 1024, before and after the change, with the iperf server running over the virtio-net interface.MTU(Bytes)/Bandwidth (Gbit/s)
Before AfterQuoted 8 lines
1500 22.5 22.4 9000 12.8 25.9Signed-off-by Gavin Li <[email protected]>Reviewed-by Gavi Teitz <[email protected]>Reviewed-by Parav Pandit <[email protected]>Reviewed-by Xuan Zhuo <[email protected]>Reviewed-by Si-Wei Liu <[email protected]>OK I think the logic is correct, it's just a bit harder to read than necessary. Small improvement suggestions:
Quoted 26 lines
---
changelog:v4->v5
- Addressed comments from Michael S. Tsirkin
- Improve commit messagev3->v4
- Addressed comments from Si-Wei
- Renamebig_packets_sg_numwithbig_packets_num_skbfragsv2->v3
- Addressed comments from Si-Wei
- Simplify the condition check to enable the optimizationv1->v2
- Addressed comments from Jason, Michael, Si-Wei.
- Remove the flag of guest GSO support, setsg_numfor big packets and use it directly
- Recalculatesg_numfor big packets invirtnet_set_guest_offloads
- Replace the round up algorithm withDIV_ROUND_UP--- drivers/net/virtio_net.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-)drivers/net/virtio_net.c index renamed from drivers/net/virtio_net.c +0
-0
f831a0290998..dbffd5f56fb8100644drivers/net/virtio_net.c struct virtnet_info { · line 233
Quoted 9 lines
drivers/net/virtio_net.c +3
-0@@ -225,6 +225,9 @@ struct virtnet_info {/* I like... big packets and I cannot lie! */ bool big_packets; +/* number of sg entries allocated for big packets */ +unsigned int big_packets_num_skbfrags; +/* Host will merge rx buffers for big packets (shake it! shake it!) */ bool mergeable_rx_bufs;
big_packets_num_skbfrags->big_packet_num_skbfragsdrivers/net/virtio_net.c static int add_recvbuf_big(struct virtnet_info
Quoted 1 line
drivers/net/virtio_net.c +0
-0@@ -1331,10 +1334,10 @@ static int add_recvbuf_big(struct virtnet_info*vi, struct
receive_queue*rq,drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const
Quoted 25 lines
drivers/net/virtio_net.c +5
-4char *p;int i, err, offset; -sg_init_table (rq->sg,MAX_SKB_FRAGS +2 ); +sg_init_table (rq->sg, vi->big_packets_num_skbfrags +2 ); -/* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */ -for (i =MAX_SKB_FRAGS +1 ; i >1 ; --i) { +/* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ +for (i = vi->big_packets_num_skbfrags +1 ; i >1 ; --i) { first =get_a_page (rq, gfp);if (!first) {if (list)@@ -1365,7 +1368,7 @@ static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq,/* chain first in list head */ first->private = (unsigned long )list; - err =virtqueue_add_inbuf (rq->vq, rq->sg,MAX_SKB_FRAGS +2 , + err =virtqueue_add_inbuf (rq->vq, rq->sg, +vi->big_packets_num_skbfrags +2 , first, gfp);if (err <0 )give_pages (rq, first);@@ -3690,13 +3693,27 @@ static bool virtnet_check_guest_gso(conststruct
virtnet_info*vi)drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi)
Quoted 13 lines
drivers/net/virtio_net.c +11
-0virtio_has_feature (vi->vdev,VIRTIO_NET_F_GUEST_UFO ); } +static void virtnet_set_big_packets_fields (struct virtnet_info *vi, +const int mtu) { +bool guest_gso =virtnet_check_guest_gso (vi); + +/* If device can receive ANY guest GSO packets, regardless of mtu, +* allocate packets of maximum size, otherwise limit it to only +* mtu size worth only. +*/ +if (mtu >ETH_DATA_LEN || guest_gso) { + vi->big_packets = true; + vi->big_packets_num_skbfrags = guest_gso ?
MAX_SKB_FRAGS:DIV_ROUND_UP(mtu, PAGE_SIZE);drivers/net/virtio_net.c static bool virtnet_check_guest_gso(const struct virtnet_info *vi) · line 3717
Quoted 11 lines
drivers/net/virtio_net.c +4
-1+ } +} +static int virtnet_probe (struct virtio_device *vdev) {int i, err = -ENOMEM ;struct net_device *dev;struct virtnet_info *vi;u16 max_queue_pairs; -int mtu; +int mtu =0 ;I think it's better to drop this and instead just put the code where we already know the config. So:
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device
Quoted 3 lines
drivers/net/virtio_net.c +0
-0/* Find if host supports multiqueue/rss virtio_net device */ max_queue_pairs =1 ;@@ -3784,10 +3801,6 @@ static int virtnet_probe(struct virtio_device*vdev)
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev)
Quoted 4 lines
drivers/net/virtio_net.c +0
-1INIT_WORK (&vi->config_work, virtnet_config_changed_work);spin_lock_init (&vi->refill_lock); -/* If we can receive ANY GSO packets, we must allocate large ones. */
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device
Quoted 7 lines
drivers/net/virtio_net.c +0
-3-if (virtnet_check_guest_gso (vi)) - vi->big_packets = true; -if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF )) vi->mergeable_rx_bufs = true;@@ -3853,12 +3866,10 @@ static int virtnet_probe(struct virtio_device*vdev)
Quoted 1 line
Quoted 14 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3859
Quoted 6 lines
drivers/net/virtio_net.c +0
-4dev->mtu = mtu; dev->max_mtu = mtu; - -/* TODO: size buffers correctly in this case. */ -if (dev->mtu >ETH_DATA_LEN ) - vi->big_packets = true;/* Size buffers to fit mtu. */ if (mtu > ETH_DATA_LEN) { vi->big_packets = true; vi->big_packets_num_skbfrags = DIV_ROUND_UP(mtu, PAGE_SIZE); }
Quoted 4 lines
How doing things twice is better i.e. when mtu is >
ETH_DATA_LENand gso is offered? It calculatesbig_packetsvariable twice.It also easier to read the code at single place where
big_packetsdecision is taken.
I guess it depends on what you want to keep in one place. I just wanted to reduce the testing burden on the submitter. What I proposed makes the functional change minimal.
It's nitpicking to be frank. v6 arrived while I was traveling and I didn't notice it. I see Jason acked that so I guess I will just apply as is. Do you ack v6 too?
Quoted 16 lines
Quoted 16 lines
drivers/net/virtio_net.c static int virtnet_probe(struct virtio_device *vdev) · line 3872
Quoted 4 lines
drivers/net/virtio_net.c +2
-0} +virtnet_set_big_packets_fields (vi, mtu); +and here:
/* If device can receive guest GSO packets, allocate buffers for * packets of maximum size, regardless of mtu. */ if (virtnet_check_guest_gso(vi)) { vi->big_packets = true; vi->big_packets_num_skbfrags = MAX_SKB_FRAGS; }
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/virtio_net.c +0
-1if (vi->any_header_sg) dev->needed_headroom = vi->hdr_len; --2.31.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 7 lines
From: Michael S. Tsirkin <[email protected]>
Sent: Thursday, September 22, 2022 6:15 AMIt's nitpicking to be frank. v6 arrived while I was traveling and I didn't notice it. I see Jason acked that so I guess I will just apply as is. Do you ack v6 too?
Yes. I reviewed it. Gavin added reviewed-by.
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Jakub Kicinski
maintainerRe: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
In reply to Michael S. TsirkinQuoted 3 lines · On Thu, 22 Sep 2022 06:14:59 -0400 Michael S. Tsirkin wrote:
It's nitpicking to be frank. v6 arrived while I was traveling and I didn't notice it. I see Jason acked that so I guess I will just apply as is.
Oh, you wanna take it? The split on who takes virtio_net is a touch unclear but if it makes more sense here to go via virtio feel free to slap my ack on the v6.
RE: [PATCH v5 2/2] virtio-net: use mtu size as buffer length for big packets
Quoted 11 lines
From: Jakub Kicinski <[email protected]>
Sent: Thursday, September 22, 2022 6:05 PMQuoted 3 lines · On Thu, 22 Sep 2022 06:14:59 -0400 Michael S. Tsirkin wrote:
It's nitpicking to be frank. v6 arrived while I was traveling and I didn't notice it. I see Jason acked that so I guess I will just apply as is.
Oh, you wanna take it? The split on who takes
virtio_netis a touch unclear but if it makes more sense here to go via virtio feel free to slap my ack on the v6.
Michael,
Did you get a chance to take this?
I don't see it at https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git/log/?h=linux-next
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]