Skip to contentSkip to conversation

vhost: net: switch to use data copy if pending DMAs exceed the limit

PATCH Superseded Jason Wang 3 participants 10 messages Feb 25, 2014 – Feb 27, 2014

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 vhost: net: switch to use data copy if pending DMAs exceed the limit

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

    +-----+        +-----+
    | VM1 |        | VM2 |
    +--+--+        +--+--+
       |              |
    +--+--+        +--+--+
    | tap0|        | tap1|
    +--+--+        +--+--+
       |              |
    pfifo_fast   htb(10Mbit/s)
       |              |
    +--+--------------+---+
    |     bridge          |
    +--+------------------+
       |
    pfifo_fast
       |
    +-----+
    | eth0|(100Mbit/s)
    +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Cc Michael S. Tsirkin <[email protected]>
Cc Qin Chuanyu <[email protected]>
---
 drivers/vhost/net.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/net.c +7 -10
index a0fa5de..3e96e47 100644
@@ -345,7 +345,7 @@ static void handle_tx(struct vhost_net *net)
 		.msg_flags = MSG_DONTWAIT,
 	};
 	size_t len, total_len = 0;
-	int err;
+	int err, num_pends;
 	size_t hdr_size;
 	struct socket *sock;
 	struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -366,13 +366,6 @@ static void handle_tx(struct vhost_net *net)
 		if (zcopy)
 			vhost_zerocopy_signal_used(net, vq);
 
-		/* If more outstanding DMAs, queue the work.
-		 * Handle upend_idx wrap around
-		 */
-		if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
-			      % UIO_MAXIOV == nvq->done_idx))
-			break;
-
 		head = vhost_get_vq_desc(&net->dev, vq, vq->iov,
 					 ARRAY_SIZE(vq->iov),
 					 &out, &in,
@@ -405,9 +398,13 @@ static void handle_tx(struct vhost_net *net)
 			break;
 		}
 
+		num_pends = likely(nvq->upend_idx >= nvq->done_idx) ?
+			    (nvq->upend_idx - nvq->done_idx) :
+			    (nvq->upend_idx + UIO_MAXIOV -
+			     nvq->done_idx);
+
 		zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN
-				   && (nvq->upend_idx + 1) % UIO_MAXIOV !=
-				      nvq->done_idx
+				   && num_pends <= VHOST_MAX_PEND
 				   && vhost_net_tx_select_zcopy(net);
 
 		/* use msg_control to pass vhost zerocopy ubuf info to skb */
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 53 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

    +-----+        +-----+
    | VM1 |        | VM2 |
    +--+--+        +--+--+
       |              |
    +--+--+        +--+--+
    | tap0|        | tap1|
    +--+--+        +--+--+
       |              |
    pfifo_fast   htb(10Mbit/s)
       |              |
    +--+--------------+---+
    |     bridge          |
    +--+------------------+
       |
    pfifo_fast
       |
    +-----+
    | eth0|(100Mbit/s)
    +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Quoted 9 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Cc Michael S. Tsirkin <[email protected]>
Cc Qin Chuanyu <[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Thoughts?

Quoted 49 lines
---
 drivers/vhost/net.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/net.c +7 -10
index a0fa5de..3e96e47 100644
@@ -345,7 +345,7 @@ static void handle_tx(struct vhost_net *net)
 		.msg_flags = MSG_DONTWAIT,
 	};
 	size_t len, total_len = 0;
-	int err;
+	int err, num_pends;
 	size_t hdr_size;
 	struct socket *sock;
 	struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -366,13 +366,6 @@ static void handle_tx(struct vhost_net *net)
 		if (zcopy)
 			vhost_zerocopy_signal_used(net, vq);
 
-		/* If more outstanding DMAs, queue the work.
-		 * Handle upend_idx wrap around
-		 */
-		if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
-			      % UIO_MAXIOV == nvq->done_idx))
-			break;
-
 		head = vhost_get_vq_desc(&net->dev, vq, vq->iov,
 					 ARRAY_SIZE(vq->iov),
 					 &out, &in,
@@ -405,9 +398,13 @@ static void handle_tx(struct vhost_net *net)
 			break;
 		}
 
+		num_pends = likely(nvq->upend_idx >= nvq->done_idx) ?
+			    (nvq->upend_idx - nvq->done_idx) :
+			    (nvq->upend_idx + UIO_MAXIOV -
+			     nvq->done_idx);
+
 		zcopy_used = zcopy && len >= VHOST_GOODCOPY_LEN
-				   && (nvq->upend_idx + 1) % UIO_MAXIOV !=
-				      nvq->done_idx
+				   && num_pends <= VHOST_MAX_PEND
 				   && vhost_net_tx_select_zcopy(net);
 
 		/* use msg_control to pass vhost zerocopy ubuf info to skb */
Signature · 1 line
1.8.3.2
author
#2 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

     +-----+        +-----+
     | VM1 |        | VM2 |
     +--+--+        +--+--+
        |              |
     +--+--+        +--+--+
     | tap0|        | tap1|
     +--+--+        +--+--+
        |              |
     pfifo_fast   htb(10Mbit/s)
        |              |
     +--+--------------+---+
     |     bridge          |
     +--+------------------+
        |
     pfifo_fast
        |
     +-----+
     | eth0|(100Mbit/s)
     +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 8 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Quoted 49 lines
Quoted 49 lines
---
  drivers/vhost/net.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/net.c +7 -10
index a0fa5de..3e96e47 100644
@@ -345,7 +345,7 @@ static void handle_tx(struct vhost_net *net)
  		.msg_flags = MSG_DONTWAIT,
  	};
  	size_t len, total_len = 0;
-	int err;
+	int err, num_pends;
  	size_t hdr_size;
  	struct socket *sock;
  	struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -366,13 +366,6 @@ static void handle_tx(struct vhost_net *net)
  		if (zcopy)
  			vhost_zerocopy_signal_used(net, vq);
 
-		/* If more outstanding DMAs, queue the work.
-		 * Handle upend_idx wrap around
-		 */
-		if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
-			      % UIO_MAXIOV == nvq->done_idx))
-			break;
-
  		head = vhost_get_vq_desc(&net->dev, vq, vq->iov,
  					 ARRAY_SIZE(vq->iov),
  					&out,&in,
@@ -405,9 +398,13 @@ static void handle_tx(struct vhost_net *net)
  			break;
  		}
 
+		num_pends = likely(nvq->upend_idx>= nvq->done_idx) ?
+			    (nvq->upend_idx - nvq->done_idx) :
+			    (nvq->upend_idx + UIO_MAXIOV -
+			     nvq->done_idx);
+
  		zcopy_used = zcopy&&  len>= VHOST_GOODCOPY_LEN
-				&&  (nvq->upend_idx + 1) % UIO_MAXIOV !=
-				      nvq->done_idx
+				&&  num_pends<= VHOST_MAX_PEND
  				&&  vhost_net_tx_select_zcopy(net);
 
  		/* use msg_control to pass vhost zerocopy ubuf info to skb */
Signature · 1 line
1.8.3.2
#3 lore raw
Quoted 90 lines · Jason Wang
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

     +-----+        +-----+
     | VM1 |        | VM2 |
     +--+--+        +--+--+
        |              |
     +--+--+        +--+--+
     | tap0|        | tap1|
     +--+--+        +--+--+
        |              |
     pfifo_fast   htb(10Mbit/s)
        |              |
     +--+--------------+---+
     |     bridge          |
     +--+------------------+
        |
     pfifo_fast
        |
     +-----+
     | eth0|(100Mbit/s)
     +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

The key problem is how to release the memory of zero_copy's skb while been reserved.

Quoted 53 lines
Quoted 46 lines
Quoted 46 lines
---
  drivers/vhost/net.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/net.c +7 -10
index a0fa5de..3e96e47 100644
@@ -345,7 +345,7 @@ static void handle_tx(struct vhost_net *net)
          .msg_flags = MSG_DONTWAIT,
      };
      size_t len, total_len = 0;
-    int err;
+    int err, num_pends;
      size_t hdr_size;
      struct socket *sock;
      struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -366,13 +366,6 @@ static void handle_tx(struct vhost_net *net)
          if (zcopy)
              vhost_zerocopy_signal_used(net, vq);
 
-        /* If more outstanding DMAs, queue the work.
-         * Handle upend_idx wrap around
-         */
-        if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
-                  % UIO_MAXIOV == nvq->done_idx))
-            break;
-
          head = vhost_get_vq_desc(&net->dev, vq, vq->iov,
                       ARRAY_SIZE(vq->iov),
                      &out,&in,
@@ -405,9 +398,13 @@ static void handle_tx(struct vhost_net *net)
              break;
          }
 
+        num_pends = likely(nvq->upend_idx>= nvq->done_idx) ?
+                (nvq->upend_idx - nvq->done_idx) :
+                (nvq->upend_idx + UIO_MAXIOV -
+                 nvq->done_idx);
+
          zcopy_used = zcopy&&  len>= VHOST_GOODCOPY_LEN
-                &&  (nvq->upend_idx + 1) % UIO_MAXIOV !=
-                      nvq->done_idx
+                &&  num_pends<= VHOST_MAX_PEND
                  &&  vhost_net_tx_select_zcopy(net);
 
Quoted 3 lines
Quoted 3 lines
drivers/vhost/net.c +0 -1
          /* use msg_control to pass vhost zerocopy ubuf info to skb */
--

1.8.3.2

.

author
#4 lore raw
Quoted 108 lines · Qin Chuanyu
Quoted 92 lines · Jason Wang
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

     +-----+        +-----+
     | VM1 |        | VM2 |
     +--+--+        +--+--+
        |              |
     +--+--+        +--+--+
     | tap0|        | tap1|
     +--+--+        +--+--+
        |              |
     pfifo_fast   htb(10Mbit/s)
        |              |
     +--+--------------+---+
     |     bridge          |
     +--+------------------+
        |
     pfifo_fast
        |
     +-----+
     | eth0|(100Mbit/s)
     +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is
from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled
somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

Quoted 7 lines

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

There're two issues:

1) if a zerocopy skb won't be freed or frags orphaned in time, vhost_net removal will be blocked since it was waiting for the refcnt of ubuf to zero.
2) whether or not we should free all pending skbs during vhost_net removing.

My proposal is for issue 1. Another idea is not wait for the refcnt to be zero and then we can defer the freeing of vhost_net during the release method of kref_put().

For issue 2, I'm still not sure we should do this or not. Looks like there's a similar issue for the packets sent by tcp_sendpage() was blocked or delayed.

Quoted 2 lines

The key problem is how to release the memory of zero_copy's skb while been reserved.

#5 lore raw
Quoted 117 lines · Jason Wang
Quoted 108 lines · Qin Chuanyu
Quoted 92 lines · Jason Wang
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

    +-----+        +-----+
    | VM1 |        | VM2 |
    +--+--+        +--+--+
       |              |
    +--+--+        +--+--+
    | tap0|        | tap1|
    +--+--+        +--+--+
       |              |
    pfifo_fast   htb(10Mbit/s)
       |              |
    +--+--------------+---+
    |     bridge          |
    +--+------------------+
       |
    pfifo_fast
       |
    +-----+
    | eth0|(100Mbit/s)
    +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is
from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also
throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

Quoted 7 lines

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

Quoted 6 lines

There're two issues:

1) if a zerocopy skb won't be freed or frags orphaned in time, vhost_net removal will be blocked since it was waiting for the refcnt of ubuf to zero.
2) whether or not we should free all pending skbs during vhost_net removing.

all pending *zero copy* skbs.

Quoted 3 lines

My proposal is for issue 1. Another idea is not wait for the refcnt to be zero and then we can defer the freeing of vhost_net during the release method of kref_put().

It's not freeing that's at issue. We must not access guest memory after vhost stop, too.

Quoted 3 lines

For issue 2, I'm still not sure we should do this or not. Looks like there's a similar issue for the packets sent by tcp_sendpage() was blocked or delayed.

What's the issue exactly? How would you trigger it?

Quoted 2 lines
Quoted 2 lines

The key problem is how to release the memory of zero_copy's skb while been reserved.

author
#6 lore raw
Quoted 129 lines · Michael S. Tsirkin
Quoted 117 lines · Jason Wang
Quoted 117 lines · Qin Chuanyu
Quoted 115 lines
Quoted 115 lines · Jason Wang
Quoted 92 lines
Quoted 92 lines · Michael S. Tsirkin
Quoted 60 lines
Quoted 60 lines · Jason Wang
Quoted 59 lines
Quoted 59 lines

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

    +-----+        +-----+
    | VM1 |        | VM2 |
    +--+--+        +--+--+
       |              |
    +--+--+        +--+--+
    | tap0|        | tap1|
    +--+--+        +--+--+
       |              |
    pfifo_fast   htb(10Mbit/s)
       |              |
    +--+--------------+---+
    |     bridge          |
    +--+------------------+
       |
    pfifo_fast
       |
    +-----+
    | eth0|(100Mbit/s)
    +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is
from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also
throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>
Quoted 6 lines
Quoted 6 lines

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines
Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

Quoted 6 lines
Quoted 6 lines

There're two issues:

1) if a zerocopy skb won't be freed or frags orphaned in time, vhost_net removal will be blocked since it was waiting for the refcnt of ubuf to zero.
2) whether or not we should free all pending skbs during vhost_net removing.

all pending *zero copy* skbs.

Quoted 3 lines
Quoted 3 lines

My proposal is for issue 1. Another idea is not wait for the refcnt to be zero and then we can defer the freeing of vhost_net during the release method of kref_put().

Quoted 7 lines

It's not freeing that's at issue. We must not access guest memory after vhost stop, too.

Quoted 3 lines
Quoted 3 lines

For issue 2, I'm still not sure we should do this or not. Looks like there's a similar issue for the packets sent by tcp_sendpage() was blocked or delayed.

What's the issue exactly? How would you trigger it?

I mean it looks similar to the issue that if we use vmsplice() to splice user pages to TCP socket, and then the packet were blocked or delayed by qdics or other. Did we wait for all pending packets in this case before terminating the process?

#7 lore raw
Quoted 136 lines · Jason Wang
Quoted 135 lines · Michael S. Tsirkin
Quoted 117 lines · Jason Wang
Quoted 117 lines · Qin Chuanyu
Quoted 115 lines
Quoted 115 lines · Jason Wang
Quoted 92 lines
Quoted 92 lines · Michael S. Tsirkin
Quoted 60 lines
Quoted 60 lines · Jason Wang
Quoted 59 lines
Quoted 59 lines

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

    +-----+        +-----+
    | VM1 |        | VM2 |
    +--+--+        +--+--+
       |              |
    +--+--+        +--+--+
    | tap0|        | tap1|
    +--+--+        +--+--+
       |              |
    pfifo_fast   htb(10Mbit/s)
       |              |
    +--+--------------+---+
    |     bridge          |
    +--+------------------+
       |
    pfifo_fast
       |
    +-----+
    | eth0|(100Mbit/s)
    +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is
from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also
throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>
Quoted 6 lines
Quoted 6 lines

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines
Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

Quoted 6 lines
Quoted 6 lines

There're two issues:

1) if a zerocopy skb won't be freed or frags orphaned in time, vhost_net removal will be blocked since it was waiting for the refcnt of ubuf to zero.
2) whether or not we should free all pending skbs during vhost_net removing.

all pending *zero copy* skbs.

Quoted 3 lines
Quoted 3 lines

My proposal is for issue 1. Another idea is not wait for the refcnt to be zero and then we can defer the freeing of vhost_net during the release method of kref_put().

It's not freeing that's at issue. We must not access guest memory after vhost stop, too.

Quoted 3 lines
Quoted 3 lines

For issue 2, I'm still not sure we should do this or not. Looks like there's a similar issue for the packets sent by tcp_sendpage() was blocked or delayed.

Quoted 6 lines
Quoted 1 line

What's the issue exactly? How would you trigger it?

I mean it looks similar to the issue that if we use vmsplice() to splice user pages to TCP socket, and then the packet were blocked or delayed by qdics or other. Did we wait for all pending packets in this case before terminating the process?

IIUC the socket object will hang around a while
but this won't block close().

Signature · 1 line
MST
author
#8 lore raw
In reply to Qin Chuanyu
Quoted 108 lines · Qin Chuanyu
Quoted 92 lines · Jason Wang
Quoted 56 lines · Michael S. Tsirkin
Quoted 55 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

     +-----+        +-----+
     | VM1 |        | VM2 |
     +--+--+        +--+--+
        |              |
     +--+--+        +--+--+
     | tap0|        | tap1|
     +--+--+        +--+--+
        |              |
     pfifo_fast   htb(10Mbit/s)
        |              |
     +--+--------------+---+
     |     bridge          |
     +--+------------------+
        |
     pfifo_fast
        |
     +-----+
     | eth0|(100Mbit/s)
     +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is
from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled
somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

Quoted 7 lines

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

There're two issues:

1) if a zerocopy skb won't be freed or frags orphaned in time, vhost_net removal will be blocked since it was waiting for the refcnt of ubuf to zero.
2) whether or not we should free all pending skbs during vhost_net removing.

My proposal is for issue 1. Another idea is not wait for the refcnt to be zero and then we can defer the freeing of vhost_net during the release method of kref_put().

For issue 2, I'm still not sure we should do this or not. Looks like there's a similar issue for the packets sent by tcp_sendpage() was blocked or delayed.

Quoted 2 lines

The key problem is how to release the memory of zero_copy's skb while been reserved.

#9 lore raw
In reply to Jason Wang
Quoted 90 lines · Jason Wang
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Jason Wang

We used to stop the handling of tx when the number of pending DMAs exceeds VHOST_MAX_PEND. This is used to reduce the memory occupation of both host and guest. But it was too aggressive in some cases, since any delay or blocking of a single packet may delay or block the guest transmission. Consider the following setup:

     +-----+        +-----+
     | VM1 |        | VM2 |
     +--+--+        +--+--+
        |              |
     +--+--+        +--+--+
     | tap0|        | tap1|
     +--+--+        +--+--+
        |              |
     pfifo_fast   htb(10Mbit/s)
        |              |
     +--+--------------+---+
     |     bridge          |
     +--+------------------+
        |
     pfifo_fast
        |
     +-----+
     | eth0|(100Mbit/s)
     +-----+

- start two VMs and connect them to a bridge
- add an physical card (100Mbit/s) to that bridge
- setup htb on tap1 and limit its throughput to 10Mbit/s
- run two netperfs in the same time, one is from VM1 to VM2. Another is from VM1 to an external host through eth0.
- result shows that not only the VM1 to VM2 traffic were throttled but also the VM1 to external host through eth0 is also throttled somehow.

This is because the delay added by htb may lead the delay the finish of DMAs and cause the pending DMAs for tap0 exceeds the limit (VHOST_MAX_PEND). In this case vhost stop handling tx request until htb send some packets. The problem here is all of the packets transmission were blocked even if it does not go to VM2.

We can solve this issue by relaxing it a little bit: switching to use data copy instead of stopping tx when the number of pending DMAs exceed the VHOST_MAX_PEND. This is safe because:

- The number of pending DMAs were still limited by VHOST_MAX_PEND
- The out of order completion during mode switch can make sure that most of the tx buffers were freed in time in guest.

So even if about 50% packets were delayed in zero-copy case, vhost could continue to do the transmission through data copy in this case.

Test result:

Quoted 9 lines
Quoted 7 lines

Before this patch:
VM1 to VM2 throughput is 9.3Mbit/s
VM1 to External throughput is 40Mbit/s

After this patch:
VM1 to VM2 throughput is 9.3Mbit/s
Vm1 to External throughput is 93Mbit/s

Would like to see CPU utilization #s as well.

Will measure this.

Quoted 6 lines
Quoted 6 lines

Simple performance test on 40gbe shows no obvious changes in throughput after this patch.

The patch only solve this issue when unlimited sndbuf. We still need a solution for limited sndbuf.

Quoted 9 lines
Quoted 3 lines
Cc Michael S. Tsirkin<[email protected]>
Cc Qin Chuanyu<[email protected]>

I think this needs some thought.

In particular I think this works because VHOST_MAX_PEND is much smaller than the ring size.
Shouldn't max_pend then be tied to the ring size if it's small?

Yes it should. I just reuse the VHOST_MAX_PEND since it was there for a long time.

Quoted 6 lines

Another question is about stopping vhost:
ATM it's waiting for skbs to complete.
Should we maybe hunt down skbs queued and destroy them instead?
I think this happens when a device is removed.

Quoted 8 lines
Quoted 2 lines

Thoughts?

Agree, vhost net removal should not be blocked by a skb. But since the skbs could be queued may places, just destroy them may need extra locks.

Haven't thought this deeply, but another possible sloution is to rcuify destructor_arg and assign it to NULL during vhost_net removing.

Xen treat it by a timer, for those skbs which has been delivered for a while, netback would exchange page of zero_copy's skb with dom0's page.

but there is still a race between host's another process handle the skb and netback exchange its page. (This problem has been proved by testing)

and Xen hasn't solved this problem yet, because if anyone want to solve this problem completely, a page lock is necessary, but it would be complex and expensive.

rcuify destructor arg and assign it to NULL couldn't solve the problem of page release that has been reserved by host's another process.

The key problem is how to release the memory of zero_copy's skb while been reserved.

Quoted 53 lines
Quoted 46 lines
Quoted 46 lines
---
  drivers/vhost/net.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
drivers/vhost/net.c +7 -10
index a0fa5de..3e96e47 100644
@@ -345,7 +345,7 @@ static void handle_tx(struct vhost_net *net)
          .msg_flags = MSG_DONTWAIT,
      };
      size_t len, total_len = 0;
-    int err;
+    int err, num_pends;
      size_t hdr_size;
      struct socket *sock;
      struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
@@ -366,13 +366,6 @@ static void handle_tx(struct vhost_net *net)
          if (zcopy)
              vhost_zerocopy_signal_used(net, vq);
 
-        /* If more outstanding DMAs, queue the work.
-         * Handle upend_idx wrap around
-         */
-        if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
-                  % UIO_MAXIOV == nvq->done_idx))
-            break;
-
          head = vhost_get_vq_desc(&net->dev, vq, vq->iov,
                       ARRAY_SIZE(vq->iov),
                      &out,&in,
@@ -405,9 +398,13 @@ static void handle_tx(struct vhost_net *net)
              break;
          }
 
+        num_pends = likely(nvq->upend_idx>= nvq->done_idx) ?
+                (nvq->upend_idx - nvq->done_idx) :
+                (nvq->upend_idx + UIO_MAXIOV -
+                 nvq->done_idx);
+
          zcopy_used = zcopy&&  len>= VHOST_GOODCOPY_LEN
-                &&  (nvq->upend_idx + 1) % UIO_MAXIOV !=
-                      nvq->done_idx
+                &&  num_pends<= VHOST_MAX_PEND
                  &&  vhost_net_tx_select_zcopy(net);
 
Quoted 3 lines
Quoted 3 lines
drivers/vhost/net.c +0 -1
          /* use msg_control to pass vhost zerocopy ubuf info to skb */
--

1.8.3.2

.