xen-netback: improve guest-receive-side flow control
Subsystems (2)
PATCH 1/1 xen-netback: improve guest-receive-side flow control
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number of times, flow control is completely broken.
This patch simplifies things by making a very quick static analysis of the minimal number or ring slots needed for an skb and then only stopping the queue if that minimal number of slots is not available. The worker thread does a worst-case analysis and only processes what will definitely fit, leaving remaining skbs on the internal queue. This patch also gets rid of the drop that occurs if an skb won't fit (because that doesn't matter - we always internally queue *at least* what we can put in the shared ring) and adds some hysteresis to waking the external queue. (It only gets woken when at least half the shared ring is available).
Without this patch I can trivially stall netback permanently by just doing a large guest to guest file copy between two Windows Server 2008R2 VMs on a single host.
--- drivers/net/xen-netback/common.h | 26 ++--- drivers/net/xen-netback/interface.c | 45 ++++---- drivers/net/xen-netback/netback.c | 202 ++++++++++------------------------- 3 files changed, 87 insertions(+), 186 deletions(-)
drivers/net/xen-netback/common.h +9 -17
@@ -136,12 +136,7 @@ struct xenvif {char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */ struct xen_netif_rx_back_ring rx;struct sk_buff_head rx_queue; - -/* Allow xenvif_start_xmit() to peek ahead in the rx request -* ring. This is a prediction of what rx_req_cons will be -* once all queued skbs are put on the ring. -*/ -RING_IDX rx_req_cons_peek; +bool rx_event;/* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each * head/fragment page uses 2 copy operations because it
@@ -198,8 +193,6 @@ void xenvif_xenbus_fini(void);int xenvif_schedulable (struct xenvif *vif); -int xenvif_rx_ring_full (struct xenvif *vif); -int xenvif_must_stop_queue (struct xenvif *vif);/* (Un)Map communication rings. */
@@ -211,21 +204,20 @@ int xenvif_map_frontend_rings(struct xenvif *vif,/* Check for SKBs from frontend and schedule backend processing */ void xenvif_check_rx_xenvif (struct xenvif *vif); -/* Queue an SKB for transmission to the frontend */ -void xenvif_queue_tx_skb (struct xenvif *vif,struct sk_buff *skb); -/* Notify xenvif that ring now has space to send an skb to the frontend */ -void xenvif_notify_tx_completion (struct xenvif *vif); -/* Prevent the device from generating any further traffic. */ void xenvif_carrier_off (struct xenvif *vif); -/* Returns number of ring slots required to send an skb to the frontend */ -unsigned int xenvif_count_skb_slots (struct xenvif *vif,struct sk_buff *skb); -int xenvif_tx_action (struct xenvif *vif,int budget); -void xenvif_rx_action (struct xenvif *vif);int xenvif_kthread (void *data); +void xenvif_kick_thread (struct xenvif *vif); + +/* Determine whether the needed number of slots (req) are available, +* and set req_event if not. +*/ +bool xenvif_rx_ring_slots_available (struct xenvif *vif,int needed); + +void xenvif_stop_queue (struct xenvif *vif);extern bool separate_tx_rx_irq;
drivers/net/xen-netback/interface.c +23 -22
90 lines not on this page · raw message
drivers/net/xen-netback/netback.c +55 -147
295 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 6 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number of times, flow control is completely broken.
Please add blank lines between paragraphs in later versions.
Quoted 9 lines
This patch simplifies things by making a very quick static analysis of the minimal number or ring slots needed for an skb and then only stopping the queue if that minimal number of slots is not available. The worker thread does a worst-case analysis and only processes what will definitely fit, leaving remaining skbs on the internal queue. This patch also gets rid of the drop that occurs if an skb won't fit (because that doesn't matter - we always internally queue *at least* what we can put in the shared ring) and adds some hysteresis to waking the external queue. (It only gets woken when at least half the shared ring is available).
I think this is the right direction to go. However we've tripped over this several times so is it possible to test it with XenRT?
Quoted 19 lines
Without this patch I can trivially stall netback permanently by just doing a large guest to guest file copy between two Windows Server 2008R2 VMs on a single host.
Signed-off-by Paul Durrant <[email protected]>Cc Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc David Vrabel <[email protected]>--- drivers/net/xen-netback/common.h | 26 ++--- drivers/net/xen-netback/interface.c | 45 ++++---- drivers/net/xen-netback/netback.c | 202 ++++++++++------------------------- 3 files changed, 87 insertions(+), 186 deletions(-)drivers/net/xen-netback/common.h +0
-0@@ -136,12 +136,7 @@ struct xenvif {char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */
drivers/net/xen-netback/common.h struct xenvif { · line 140
Quoted 10 lines
drivers/net/xen-netback/common.h +1
-6struct xen_netif_rx_back_ring rx;struct sk_buff_head rx_queue; - -/* Allow xenvif_start_xmit() to peek ahead in the rx request -* ring. This is a prediction of what rx_req_cons will be -* once all queued skbs are put on the ring. -*/ -RING_IDX rx_req_cons_peek; +bool rx_event;
What is this for? Reading through the code my impression is that this is a flag indicating RX interrupt is triggered. Why is it useful? Why is skb_queue_empty not sufficient?
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-0/* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each * head/fragment page uses 2 copy operations because it @@ -198,8 +193,6 @@ void xenvif_xenbus_fini(void);
[...]
Quoted 11 lines
drivers/net/xen-netback/common.h +0
-6-void xenvif_notify_tx_completion (struct xenvif *vif) -{ -if (netif_queue_stopped (vif->dev) &&xenvif_rx_schedulable (vif)) -netif_wake_queue (vif->dev); -} -static struct net_device_stats *xenvif_get_stats (struct net_device *dev) {struct xenvif *vif =netdev_priv (dev);
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref, · line 382
Quoted 5 lines
drivers/net/xen-netback/common.h +2
-0@@ -378,6 +378,8 @@ int xenvif_connect(struct xenvif *vif, unsigned long tx_ring_ref,if (err <0 ) goto err; +init_waitqueue_head (&vif->wq); +
I guess the reason behind this code movement is that, if we don't do this netback will crash if we get interrupt before waitqueue is set up?
Quoted 3 lines
drivers/net/xen-netback/common.h +0
-0if (tx_evtchn == rx_evtchn) {/* feature-split-event-channels == 0 */ err = bind_interdomain_evtchn_to_irqhandler(
[...]
Quoted 10 lines
drivers/net/xen-netback/common.h +1
-4@@ -583,23 +477,36 @@ void xenvif_rx_action(struct xenvif *vif)skb_queue_head_init (&rxq); - count =0 ; -while ((skb =skb_dequeue (&vif->rx_queue)) !=NULL ) { - vif =netdev_priv (skb->dev); - nr_frags =skb_shinfo (skb)->nr_frags; +int max_slots_needed;
drivers/net/xen-netback/common.h void xenvif_rx_action(struct xenvif *vif) · line 488
Quoted 10 lines
drivers/net/xen-netback/common.h +5
-3+int i; - sco = (struct skb_cb_overlay *)skb->cb; - sco->meta_slots_used =xenvif_gop_skb (skb, &npo); +/* We need a cheap worse case estimate for the number of +* slots we'll use. +*/ - count += nr_frags +1 ; + max_slots_needed =2 ;
I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
drivers/net/xen-netback/common.h void xenvif_rx_action(struct xenvif *vif) · line 493
Quoted 6 lines
drivers/net/xen-netback/common.h +4
-1+for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +struct page *page; -__skb_queue_tail (&rxq, skb); + page =skb_frag_page (&skb_shinfo (skb)->frags[i]); + max_slots_needed +=1 <<compound_order (page);
This estimation might reserve slots more than necessary.
The removal of xenvif_count_skb_slots() is OK because you're now estimating minimum slots, but the actual number of slots consumed needs to be acurate. Any reason you don't want to use xenvif_gop_skb()?
Quoted 21 lines
drivers/net/xen-netback/common.h +14
-3+ } +if (skb_shinfo (skb)->gso_type &SKB_GSO_TCPV4 || +skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 ) + max_slots_needed++; -/* Filled the batch queue? */ -/* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */ -if (count +MAX_SKB_FRAGS >=XEN_NETIF_RX_RING_SIZE ) +/* If the skb may not fit then bail out now */ +if (!xenvif_rx_ring_slots_available (vif, max_slots_needed)) { +skb_queue_head (&vif->rx_queue, skb);break ; + } + + sco = (struct skb_cb_overlay *)skb->cb; + sco->meta_slots_used =xenvif_gop_skb (skb, &npo); +BUG_ON (sco->meta_slots_used > max_slots_needed); + +__skb_queue_tail (&rxq, skb); }
[...]
drivers/net/xen-netback/common.h
Quoted 8 lines
drivers/net/xen-netback/common.h +3
-0+int xenvif_kthread (void *data) {struct xenvif *vif = data; +const int threshold =XEN_NETIF_RX_RING_SIZE /2 ;while (!kthread_should_stop ()) { +
Stray blank line.
Wei.
Quoted 19 lines
drivers/net/xen-netback/common.h +5
-1wait_event_interruptible (vif->wq,rx_work_todo (vif) ||kthread_should_stop ());if (kthread_should_stop ())break ; -if (rx_work_todo (vif)) +if (!skb_queue_empty (&vif->rx_queue))xenvif_rx_action (vif); + vif->rx_event = false; +if (xenvif_rx_ring_slots_available (vif, threshold)) +xenvif_start_queue (vif); +cond_resched (); }Signature · 2 lines
-- 1.7.10.4
Quoted 25 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 15:51
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 5 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
of
Quoted 1 line
times, flow control is completely broken.
Please add blank lines between paragraphs in later versions.
Quoted 6 lines
This patch simplifies things by making a very quick static analysis of the minimal number or ring slots needed for an skb and then only stopping the queue if that minimal number of slots is not available. The worker thread does a worst-case analysis and only processes what will definitely fit, leaving remaining skbs on the internal queue. This patch also gets rid of the drop that occurs if an skb won't fit (because that doesn't matter - we
Quoted 8 lines
always
Quoted 3 lines
internally queue *at least* what we can put in the shared ring) and adds some hysteresis to waking the external queue. (It only gets woken when at least half the shared ring is available).
I think this is the right direction to go. However we've tripped over this several times so is it possible to test it with XenRT?
That's on its way. It'll be a day or so to get results back though.
Quoted 28 lines
Quoted 2 lines
Without this patch I can trivially stall netback permanently by just doing a large guest to guest file copy between two Windows Server 2008R2 VMs
on a
Quoted 9 lines
single host.
Signed-off-by Paul Durrant <[email protected]>Cc Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc David Vrabel <[email protected]>--- drivers/net/xen-netback/common.h | 26 ++--- drivers/net/xen-netback/interface.c | 45 ++++---- drivers/net/xen-netback/netback.c | 202 ++++++++++-------------------------
drivers/net/xen-
Quoted 3 lines
3 files changed, 87 insertions(+), 186 deletions(-)drivers/net/xen- renamed from drivers/net/xen-netback/common.h +0
-0
netback/common.hQuoted 11 lines
index 08ae01b..d7888db 100644
drivers/net/xen-netback/common.h +0
-4@@ -136,12 +136,7 @@ struct xenvif {char rx_irq_name[IFNAMSIZ +4 ];/* DEVNAME-rx */ struct xen_netif_rx_back_ring rx;struct sk_buff_head rx_queue; - -/* Allow xenvif_start_xmit() to peek ahead in the rx request -* ring. This is a prediction of what rx_req_cons will be -* once all queued skbs are put on the ring.
Quoted 9 lines
drivers/net/xen-netback/common.h struct xenvif { · line 140
Quoted 4 lines
drivers/net/xen-netback/common.h +1
-2-*/ -RING_IDX rx_req_cons_peek; +bool rx_event;What is this for? Reading through the code my impression is that this is a flag indicating RX interrupt is triggered. Why is it useful? Why is
skb_queue_emptynot sufficient?
The thread is kicked in two cases now; when a new packet is added and when the frontend sends an event (e.g. when new requests are posted). This is an explicit flag for the latter. I didn't want to risk missing a queue wake in the case where the internal queue was fully drained yielding a shared ring that was more than half full, which I think is what would happen if I didn't have a flag such as this to control the thread wake.
Quoted 17 lines
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-0/* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each * head/fragment page uses 2 copy operations because it @@ -198,8 +193,6 @@ void xenvif_xenbus_fini(void);[...]
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long
Quoted 11 lines
drivers/net/xen-netback/common.h +0
-6-void xenvif_notify_tx_completion (struct xenvif *vif) -{ -if (netif_queue_stopped (vif->dev) &&xenvif_rx_schedulable (vif)) -netif_wake_queue (vif->dev); -} -static struct net_device_stats *xenvif_get_stats (struct net_device *dev) {struct xenvif *vif =netdev_priv (dev);@@ -378,6 +378,8 @@ int xenvif_connect(struct xenvif *vif, unsigned long
tx_ring_ref,
Quoted 9 lines
drivers/net/xen-netback/common.h int xenvif_connect(struct xenvif *vif, unsigned long · line 382
Quoted 5 lines
drivers/net/xen-netback/common.h +2
-0if (err <0 ) goto err; +init_waitqueue_head (&vif->wq); +I guess the reason behind this code movement is that, if we don't do this netback will crash if we get interrupt before waitqueue is set up?
Yep.
Quoted 22 lines
Quoted 3 lines
drivers/net/xen-netback/common.h +0
-0if (tx_evtchn == rx_evtchn) {/* feature-split-event-channels == 0 */ err = bind_interdomain_evtchn_to_irqhandler([...]
Quoted 18 lines
drivers/net/xen-netback/common.h +5
-6@@ -583,23 +477,36 @@ void xenvif_rx_action(struct xenvif *vif)skb_queue_head_init (&rxq); - count =0 ; -while ((skb =skb_dequeue (&vif->rx_queue)) !=NULL ) { - vif =netdev_priv (skb->dev); - nr_frags =skb_shinfo (skb)->nr_frags; +int max_slots_needed; +int i; - sco = (struct skb_cb_overlay *)skb->cb; - sco->meta_slots_used =xenvif_gop_skb (skb, &npo); +/* We need a cheap worse case estimate for the number of +* slots we'll use. +*/
Quoted 7 lines
drivers/net/xen-netback/common.h void xenvif_rx_action(struct xenvif *vif) · line 488
Quoted 2 lines
drivers/net/xen-netback/common.h +1
-1- count += nr_frags +1 ; + max_slots_needed =2 ;I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
I was wondering about that. Would a roundup of mtu to the nearest 4k boundary be sufficient?
Quoted 9 lines
drivers/net/xen-netback/common.h void xenvif_rx_action(struct xenvif *vif) · line 493
Quoted 6 lines
drivers/net/xen-netback/common.h +4
-1+for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +struct page *page; -__skb_queue_tail (&rxq, skb); + page =skb_frag_page (&skb_shinfo (skb)->frags[i]); + max_slots_needed +=1 <<compound_order (page);This estimation might reserve slots more than necessary.
Yes, it needs to be worse case - but not too bad.
Quoted 4 lines
The removal of
xenvif_count_skb_slots()is OK because you're now estimating minimum slots, but the actual number of slots consumed needs to be acurate. Any reason you don't want to usexenvif_gop_skb()?
I can't. xenvif_gop_skb() pulls requests off the ring and if there aren't enough there it will crash'n'burn as far as I can tell. So, I need an upper bound on the number of slots before I call it.
Quoted 28 lines
Quoted 21 lines
drivers/net/xen-netback/common.h +14
-3+ } +if (skb_shinfo (skb)->gso_type &SKB_GSO_TCPV4 || +skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 ) + max_slots_needed++; -/* Filled the batch queue? */ -/* XXX FIXME: RX path dependent on MAX_SKB_FRAGS */ -if (count +MAX_SKB_FRAGS >=XEN_NETIF_RX_RING_SIZE ) +/* If the skb may not fit then bail out now */ +if (!xenvif_rx_ring_slots_available (vif, max_slots_needed)) { +skb_queue_head (&vif->rx_queue, skb);break ; + } + + sco = (struct skb_cb_overlay *)skb->cb; + sco->meta_slots_used =xenvif_gop_skb (skb, &npo); +BUG_ON (sco->meta_slots_used > max_slots_needed); + +__skb_queue_tail (&rxq, skb); }[...]
Quoted 6 lines
drivers/net/xen-netback/common.h +2
-0+int xenvif_kthread (void *data) {struct xenvif *vif = data; +const int threshold =XEN_NETIF_RX_RING_SIZE /2 ;
Quoted 4 lines
drivers/net/xen-netback/common.h
Quoted 2 lines
drivers/net/xen-netback/common.h +1
-0while (!kthread_should_stop ()) { +Stray blank line.
Yep - will ditch that.
Thanks,
Paul
Quoted 23 lines
Wei.
Quoted 19 lines
drivers/net/xen-netback/common.h +5
-2wait_event_interruptible (vif->wq,rx_work_todo (vif) ||kthread_should_stop ());if (kthread_should_stop ())break ; -if (rx_work_todo (vif)) +if (!skb_queue_empty (&vif->rx_queue))xenvif_rx_action (vif); + vif->rx_event = false; +if (xenvif_rx_ring_slots_available (vif, threshold)) +xenvif_start_queue (vif); +cond_resched (); } --1.7.10.4
Quoted 30 lines · Paul Durrant
Quoted 30 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 15:51
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 5 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
of
Quoted 1 line
times, flow control is completely broken.
Please add blank lines between paragraphs in later versions.
Quoted 6 lines
This patch simplifies things by making a very quick static analysis of the minimal number or ring slots needed for an skb and then only stopping the queue if that minimal number of slots is not available. The worker thread does a worst-case analysis and only processes what will definitely fit, leaving remaining skbs on the internal queue. This patch also gets rid of the drop that occurs if an skb won't fit (because that doesn't matter - we
always
Quoted 3 lines
internally queue *at least* what we can put in the shared ring) and adds some hysteresis to waking the external queue. (It only gets woken when at least half the shared ring is available).
Quoted 6 lines
Quoted 3 lines
I think this is the right direction to go. However we've tripped over this several times so is it possible to test it with XenRT?
That's on its way. It'll be a day or so to get results back though.
Good, thanks.
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Without this patch I can trivially stall netback permanently by just doing a large guest to guest file copy between two Windows Server 2008R2 VMs
on a
Quoted 6 lines
single host.
Signed-off-by Paul Durrant <[email protected]>Cc Wei Liu <[email protected]>Cc Ian Campbell <[email protected]>Cc David Vrabel <[email protected]>---
[...]
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/xen-netback/common.h +0
-4- -/* Allow xenvif_start_xmit() to peek ahead in the rx request -* ring. This is a prediction of what rx_req_cons will be -* once all queued skbs are put on the ring. Quoted 9 lines
drivers/net/xen-netback/common.h struct xenvif { · line 139
Quoted 4 lines
drivers/net/xen-netback/common.h +1
-2-*/ -RING_IDX rx_req_cons_peek; +bool rx_event;What is this for? Reading through the code my impression is that this is a flag indicating RX interrupt is triggered. Why is it useful? Why is
skb_queue_emptynot sufficient?
Quoted 7 lines
The thread is kicked in two cases now; when a new packet is added and when the frontend sends an event (e.g. when new requests are posted). This is an explicit flag for the latter. I didn't want to risk missing a queue wake in the case where the internal queue was fully drained yielding a shared ring that was more than half full, which I think is what would happen if I didn't have a flag such as this to control the thread wake.
OK, I get it. Better add comment for this flag.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/xen-netback/common.h +0
-0/* Given MAX_BUFFER_OFFSET of 4096 the worst case is that each * head/fragment page uses 2 copy operations because it @@ -198,8 +193,6 @@ void xenvif_xenbus_fini(void);
[...]
Quoted 10 lines
Quoted 7 lines
drivers/net/xen-netback/netback.c void xenvif_rx_action(struct xenvif *vif) · line 488
Quoted 2 lines
drivers/net/xen-netback/netback.c +1
-1- count += nr_frags +1 ; + max_slots_needed =2 ;I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
I was wondering about that. Would a roundup of mtu to the nearest 4k boundary be sufficient?
I think we can reuse the logic in xenvif_gop_skb, there's a snippet used to calculate how many slots are necessary for linear area. We just need to avoid pulling requrests from the ring.
Quoted 10 lines
Quoted 9 lines
drivers/net/xen-netback/netback.c void xenvif_rx_action(struct xenvif *vif) · line 493
Quoted 6 lines
drivers/net/xen-netback/netback.c +4
-1+for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +struct page *page; -__skb_queue_tail (&rxq, skb); + page =skb_frag_page (&skb_shinfo (skb)->frags[i]); + max_slots_needed +=1 <<compound_order (page);This estimation might reserve slots more than necessary.
Quoted 9 lines
Yes, it needs to be worse case - but not too bad.
Quoted 4 lines
The removal of
xenvif_count_skb_slots()is OK because you're now estimating minimum slots, but the actual number of slots consumed needs to be acurate. Any reason you don't want to usexenvif_gop_skb()?I can't.
xenvif_gop_skb()pulls requests off the ring and if there aren't enough there it will crash'n'burn as far as I can tell. So, I need an upper bound on the number of slots before I call it.
I get what you mean. We can at least use some of the snippet in it without pulling requests. See above.
Wei.
Quoted 7 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 16:27
To: Paul Durrant
Cc: Wei Liu; [email protected]; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow control
[snip]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
Quoted 8 lines
Quoted 1 line
I was wondering about that. Would a roundup of mtu to the nearest 4k
boundary be sufficient?
Quoted 1 line
I think we can reuse the logic in
xenvif_gop_skb, there's a snippet used to calculate how many slots are necessary for linear area. We just need to avoid pulling requrests from the ring.
Actually, DIV_ROUND(skb_headlen(skb), PAGE_SIZE) should give a cheap upper bound, shouldn't it? I don't want the code here to get too complex.
Paul
Quoted 18 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 16:27
To: Paul Durrant
Cc: Wei Liu; [email protected]; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow control[snip]
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
I was wondering about that. Would a roundup of mtu to the nearest 4k
boundary be sufficient?
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
I think we can reuse the logic in
xenvif_gop_skb, there's a snippet used to calculate how many slots are necessary for linear area. We just need to avoid pulling requrests from the ring.Actually,
DIV_ROUND(skb_headlen(skb), PAGE_SIZE)should give a cheap upper bound, shouldn't it? I don't want the code here to get too complex.
I guess this would work.
Wei.
Quoted 1 line
Paul
Quoted 18 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 16:27
To: Paul Durrant
Cc: Wei Liu; [email protected]; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow control[snip]
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
I'm afraid this starting point is not correct. Consider you have a SKB with very large linear buffer, you might need more than 2 slots to fit that in, right?
I was wondering about that. Would a roundup of mtu to the nearest 4k
boundary be sufficient?
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I think we can reuse the logic in
xenvif_gop_skb, there's a snippet used to calculate how many slots are necessary for linear area. We just need to avoid pulling requrests from the ring.Actually,
DIV_ROUND(skb_headlen(skb), PAGE_SIZE)should give a cheap upper bound, shouldn't it? I don't want the code here to get too complex.
Make sure it does the right thing if the head is not page aligned etc.
David
Quoted 9 lines · Wei Liu
Quoted 8 lines · Paul Durrant
Quoted 8 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 15:51
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow control
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Paul Durrant
Quoted 5 lines
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
of
Quoted 1 line
times, flow control is completely broken.
Can you describe it in more details? What kind of scenarios does this issue happen? I assume current xenvif_count_skb_slots() returns accurate value now.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The removal of
xenvif_count_skb_slots()is OK because you're now estimating minimum slots, but the actual number of slots consumed needs to be acurate. Any reason you don't want to usexenvif_gop_skb()?I can't.
xenvif_gop_skb()pulls requests off the ring and if there aren't enough there it will crash'n'burn as far as I can tell. So, I need an upper bound on the number of slots before I call it.I get what you mean. We can at least use some of the snippet in it without pulling requests. See above.
I prefer accurate value since it would help to save more slots. But I am not sure what the flow control issue is, does using similar mechanism of xenvif_count_skb_slots here would cause this issue too?
Thanks
Annie
Quoted 27 lines
-----Original Message-----
From: annie li [mailto:[email protected]]
Sent: 29 November 2013 08:21
To: Wei Liu
Cc: Paul Durrant; David Vrabel; Ian Campbell; [email protected]
Subject: Re: [Xen-devel] [PATCH net-next] xen-netback: improve guest- receive-side flow controlQuoted 7 lines · Wei Liu
Quoted 6 lines · Paul Durrant
Quoted 6 lines
-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 28 November 2013 15:51
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell; David Vrabel
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-sideflow
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
control
Quoted 2 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references,
and
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and
the
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
number of references consumed differs and, after this happens a
number
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
of
Quoted 1 line
times, flow control is completely broken.
Can you describe it in more details? What kind of scenarios does this issue happen? I assume current
xenvif_count_skb_slots()returns accurate value now.
Ok, I'll elaborate a bit for the record...
The way that flow control works without this patch is that, in start_xmit the code uses xenvif_count_skb_slots() to predict how many slots xenvif_gop_skb() will consume and then adds this to a 'req_cons_peek' counter which it then uses to determine if that shared ring has that amount of space available by checking whether 'req_prod' has passed that value. If the ring doesn't have space the tx queue is stopped. xenvif_gop_skb() will then consume slots and update 'req_cons' and issue responses, updating 'rsp_prod' as it goes. The frontend will consume those responses and post new requests, by updating req_prod. So, req_prod chases req_cons which chases rsp_prod, and can never exceed that value. Thus if xenvif_count_skb_slots() ever returns a number of slots greater than xenvif_gop_skb() uses
req_cons_peek will get to a value that req_prod cannot achieve (since it's limited by the 'real' req_cons) and, if this happens enough times, req_cons_peek gets more than a ring size ahead of req_cons and the tx queue then remains stopped forever waiting for an unachievable amount of space to become available in the ring. It was fairly trivial to check that this was happening by adding a BUG_ON if the value calculated by xenvif_count_skb_slots() was ever different to that returned by xenvif_gob_skb(). Starting a simple SMB transfer between a couple of windows VMs was enough to trigger it.
Having two routines trying to calculate the same value is always going to be fragile, so this patch does away with that. All we essentially need to do is make sure that we have 'enough stuff' on our internal queue without letting it build up uncontrollably. So start_xmit makes a cheap optimistic check of how much space is needed for an skb and only turns the queue off if that is unachievable. net_rx_action() is the place where we could do with an accurate predicition but, since that has proven tricky to calculate, a cheap worse-case (but not too bad) estimate is all we really need since the only thing we *must* prevent is xenvif_gop_skb() consuming more slots than are available.
I also added some hysteresis as the code was pretty dumb in that respect and would wake the tx queue as soon as enough space for a single skb became available, basically leading to a lot of thrashing between the queue being stopped or active.
Does that explain?
Paul
Quoted 7 lines · Paul Durrant
Quoted 4 lines
Can you describe it in more details? What kind of scenarios does this issue happen? I assume current
xenvif_count_skb_slots()returns accurate value now.Ok, I'll elaborate a bit for the record...
The way that flow control works without this patch is that, in
start_xmitthe code usesxenvif_count_skb_slots()to predict how many slotsxenvif_gop_skb()will consume and then adds this to a 'req_cons_peek' counter which it then uses to determine if that shared ring has that amount of space available by checking whether 'req_prod' has passed that value. If the ring doesn't have space the tx queue is stopped.xenvif_gop_skb()will then consume slots and update 'req_cons' and issue responses, updating 'rsp_prod' as it goes. The frontend will consume those responses and post new requests, by updatingreq_prod. So,req_prodchasesreq_conswhich chasesrsp_prod, and can never exceed that value. Thus ifxenvif_count_skb_slots()ever returns a number of slots greater thanxenvif_gop_skb()us
es req_cons_peek will get to a value that req_prod cannot achieve (since it's limited by the 'real' req_cons) and, if this happens enough times, req_cons_peek gets more than a ring size ahead!
Quoted 1 line
of
req_consand the tx queue then remains stopped forever waiting for an unachievable amount of space to become available in the ring. It was fairly trivial to check that this was happening by adding aBUG_ONif the value calculated byxenvif_count_skb_slots()was ever different to that returned byxenvif_gob_skb(). Starting a simple SMB transfer between a couple of windows VMs was enough to trigger it.
So xenvif_count_skb_slots() not returning accurate vaule causes this issue.
Quoted 7 lines
Having two routines trying to calculate the same value is always going to be fragile, so this patch does away with that. All we essentially need to do is make sure that we have 'enough stuff' on our internal queue without letting it build up uncontrollably. So
start_xmitmakes a cheap optimistic check of how much space is needed for an skb and only turns the queue off if that is unachievable.net_rx_action()is the place where we could do with an accurate predicition but, since that has proven tricky to calculate, a cheap worse-case (but not too bad) estimate is all we really need since the only thing we *must* prevent isxenvif_gop_skb()consuming more slots than are available.I also added some hysteresis as the code was pretty dumb in that respect and would wake the tx queue as soon as enough space for a single skb became available, basically leading to a lot of thrashing between the queue being stopped or active.
Does that explain?
This makes sense, thanks Paul.
Thanks
Annie
Quoted 31 lines
-----Original Message-----
From: annie li [mailto:[email protected]]
Sent: 01 December 2013 04:18
To: Paul Durrant
Cc: Wei Liu; [email protected]; David Vrabel; Ian Campbell
Subject: Re: [Xen-devel] [PATCH net-next] xen-netback: improve guest- receive-side flow controlQuoted 2 lines · Paul Durrant
Quoted 2 lines
Can you describe it in more details? What kind of scenarios does this issue happen? I assume current
xenvif_count_skb_slots()returnsaccurate
Quoted 5 lines
Quoted 2 lines
value now.
Ok, I'll elaborate a bit for the record...
The way that flow control works without this patch is that, in
start_xmitthecode uses
xenvif_count_skb_slots()to predict how many slotsxenvif_gop_skb()will consume and then adds this to a 'req_cons_peek' counter which it then uses to determine if that shared ring has that amount of space available by checking whether 'req_prod' has passed that value. If the ring doesn't have space the tx queue is stopped.xenvif_gop_skb()will then consume slots and update 'req_cons' and issue responses, updating 'rsp_prod' as it goes. The frontend will consume those responses and post new requests, by updatingreq_prod. So,req_prodchasesreq_conswhich chasesrsp_prod, and can never exceed that value. Thus ifxenvif_count_skb_slots()ever returns a number of slots greater thanxenvif_gop_skb()usesreq_cons_peekwill get to a value thatreq_prodcannot achieve (since it's limited by the 'real'req_cons) and, if this happens enough times,req_cons_peekgets more than a ring size ahead!
Quoted 9 lines
Quoted 1 line
of
req_consand the tx queue then remains stopped forever waiting foran unachievable amount of space to become available in the ring. It was fairly trivial to check that this was happening by adding a
BUG_ONif the value calculated byxenvif_count_skb_slots()was ever different to that returned byxenvif_gob_skb(). Starting a simple SMB transfer between a couple of windows VMs was enough to trigger it.So
xenvif_count_skb_slots()not returning accurate vaule causes this issue.
Yes, that's right.
Quoted 12 lines
Quoted 2 lines
Having two routines trying to calculate the same value is always going to be
fragile, so this patch does away with that. All we essentially need to do is make sure that we have 'enough stuff' on our internal queue without letting it build up uncontrollably. So
start_xmitmakes a cheap optimistic check of how much space is needed for an skb and only turns the queue off if that is unachievable.net_rx_action()is the place where we could do with an accurate predicition but, since that has proven tricky to calculate, a cheap worse-case (but not too bad) estimate is all we really need since the only thing we *must* prevent isxenvif_gop_skb()consuming more slots than are available.Quoted 1 line
Quoted 9 lines
Quoted 1 line
I also added some hysteresis as the code was pretty dumb in that respect
and would wake the tx queue as soon as enough space for a single skb became available, basically leading to a lot of thrashing between the queue being stopped or active.
Quoted 3 lines
Does that explain?
This makes sense, thanks Paul.
Good :-)
Paul
Quoted 6 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number of times, flow control is completely broken.
Can you describe in more detail the cases where it gets it wrong?
Quoted 1 line
-unsigned int
xenvif_count_skb_slots(struct xenvif *vif, struct sk_buff *skb)
Any patch that gets rid of this gets my vote (provided it works!).
Can you list all the guest frontends that you've tested this with?
David
Quoted 14 lines
-----Original Message-----
From: David Vrabel
Sent: 02 December 2013 11:52
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 5 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
Quoted 5 lines
of
Quoted 1 line
times, flow control is completely broken.
Can you describe in more detail the cases where it gets it wrong?
I've already elaborated on this thread (at Annie Li's request). That explanation is probably a little long for inclusion in the comment though.
Quoted 7 lines
Quoted 1 line
-unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct
sk_buff*skb)
Any patch that gets rid of this gets my vote (provided it works!).
Can you list all the guest frontends that you've tested this with?
So, far a couple of windows guests for dev test purposes, but it is going through XenRT too which will exercise linux guests too.
Paul
Quoted 14 lines · Paul Durrant
Quoted 14 lines
-----Original Message-----
From: David Vrabel
Sent: 02 December 2013 11:52
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 5 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
Quoted 8 lines
Quoted 5 lines
of
Quoted 1 line
times, flow control is completely broken.
Can you describe in more detail the cases where it gets it wrong?
I've already elaborated on this thread (at Annie Li's request). That explanation is probably a little long for inclusion in the comment though.
I understand that count_slot() going wrong is bad. What specifically is it counting incorrectly. What frag layout is causing it? If this is understood there may be a more more minimal patch we can mark for stable.
David
Quoted 32 lines
-----Original Message-----
From: David Vrabel
Sent: 02 December 2013 12:00
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 6 lines · Paul Durrant
Quoted 6 lines
-----Original Message-----
From: David Vrabel
Sent: 02 December 2013 11:52
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-sideflow
Quoted 5 lines
Quoted 5 lines
control
Quoted 2 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references,
and
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a
number
Quoted 6 lines
Quoted 5 lines
of
Quoted 1 line
times, flow control is completely broken.
Can you describe in more detail the cases where it gets it wrong?
Quoted 8 lines
Quoted 2 lines
I've already elaborated on this thread (at Annie Li's request). That explanation is probably a little long for inclusion in the comment though.
I understand that
count_slot()going wrong is bad. What specifically is it counting incorrectly. What frag layout is causing it? If this is understood there may be a more more minimal patch we can mark for stable.
TBH once I realised the value returned was different from xenvif_gop_skb() I didn' t look further; this function has needed putting out of its misery for a long time.
Paul
Quoted 14 lines · Paul Durrant
Quoted 14 lines
-----Original Message-----
From: David Vrabel
Sent: 02 December 2013 11:52
To: Paul Durrant
Cc: [email protected]; Wei Liu; Ian Campbell
Subject: Re: [PATCH net-next] xen-netback: improve guest-receive-side flow controlQuoted 5 lines · Paul Durrant
The flow control code relies on a double pass of tke skb, firstly to count the number of ring slots needed to supply sufficient grant references, and another to actually consume those references and build the grant copy operations. It transpires that, in some scenarios, the initial count and the number of references consumed differs and, after this happens a number
Quoted 7 lines
Quoted 5 lines
of
Quoted 1 line
times, flow control is completely broken.
Can you describe in more detail the cases where it gets it wrong?
I've already elaborated on this thread (at Annie Li's request). That explanation is probably a little long for inclusion in the comment though.
Please do add it. It never hurts to have more documentation.
Quoted 17 lines
Quoted 8 lines
Quoted 2 lines
-unsigned int xenvif_count_skb_slots(struct xenvif *vif, struct
sk_buff*skb)
Any patch that gets rid of this gets my vote (provided it works!).
Can you list all the guest frontends that you've tested this with?
So, far a couple of windows guests for dev test purposes, but it is going through XenRT too which will exercise linux guests too.
Paul
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel