veth: Avoid drop packets when xdp_redirect performs
Subsystems (2)
PATCH 1/1 veth: Avoid drop packets when xdp_redirect performs
In the current processing logic, when xdp_redirect occurs, it transmits the xdp frame based on napi.
If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use veth_xmit() to deliver it to the peer veth.
Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:
NIC -> veth0----veth1
| | (XDP) (no XDP)
--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/net/veth.c +35 -1
@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ()); +if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq); + } + + ret = nxmit; goto out; + } max_len = rcv->mtu + rcv->hard_header_len +VLAN_HLEN ;
Signature · 1 line
1.8.3.1
Quoted 5 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
Quoted 47 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +21
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++;
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 10 lines
drivers/net/veth.c +10
-0+ + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ()); +if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);
Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
-Toke
Quoted 9 lines · Toke Høiland-Jørgensen
Quoted 5 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
In general, we don't expect veth to drop packets when it doesn't mount the xdp program or otherwise, because this is not as expected.
Quoted 51 lines
Quoted 51 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +25
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ());
Quoted 8 lines
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 6 lines
drivers/net/veth.c +6
-0+if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
Yes, there are indeed some optimizations that can be done here, like putting the lock outside the loop.
But in __dev_queue_xmit(), where each packet sent is also protected by a lock.
Thanks.
Quoted 2 lines
-Toke
Quoted 6 lines · Heng Qi
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
In general, we don't expect veth to drop packets when it doesn't mount the xdp program or otherwise, because this is not as expected.
Well, did you consider that maybe your expectation is wrong? ;)
Quoted 60 lines
Quoted 51 lines
Quoted 51 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +25
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ());Quoted 8 lines
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 6 lines
drivers/net/veth.c +6
-0+if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
Quoted 3 lines
Yes, there are indeed some optimizations that can be done here, like putting the lock outside the loop.
But in__dev_queue_xmit(), where each packet sent is also protected by a lock.
...which is another reason why this is a bad idea: it's going to perform terribly, which means we'll just end up with users wondering why their XDP performance is terrible and we're going to have to tell them to turn on GRO anyway. So why not do this from the beginning?
If you want to change the default, flipping GRO to be on by default is a better solution IMO. I don't actually recall why we didn't do that when the support was added, but maybe Paolo remembers?
-Toke
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Heng Qi
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
In general, we don't expect veth to drop packets when it doesn't mount the xdp program or otherwise, because this is not as expected.
Well, did you consider that maybe your expectation is wrong? ;)
For users who don't know what other conditions are required for the readiness of napi, all they can observe is why the packets cannot be sent to the peer veth, which is also the problem we encountered in the actual case scenarios.
Quoted 63 lines
Quoted 60 lines
Quoted 52 lines
Quoted 52 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +25
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ());Quoted 8 lines
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 6 lines
drivers/net/veth.c +6
-0+if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
Quoted 3 lines
Yes, there are indeed some optimizations that can be done here, like putting the lock outside the loop.
But in__dev_queue_xmit(), where each packet sent is also protected by a lock.
Quoted 8 lines
...which is another reason why this is a bad idea: it's going to perform terribly, which means we'll just end up with users wondering why their XDP performance is terrible and we're going to have to tell them to turn on GRO anyway. So why not do this from the beginning?
If you want to change the default, flipping GRO to be on by default is a better solution IMO. I don't actually recall why we didn't do that when the support was added, but maybe Paolo remembers?
As I said above in the real case, the user's concern is not why the performance of xdp becomes bad, but why the data packets are not received.
The default number of veth queues is not num_possible_cpus(). When GRO is enabled by default, if there is only one veth queue, but multiple CPUs read and write at the same time, the efficiency of napi is actually very low due to the existence of production locks and races. On the contrary, the default veth_xmit() each cpu has its own unique queue, and this way of sending and receiving packets is also efficient.
Thanks.
Quoted 2 lines
-Toke
Paolo Abeni
maintainerHello,
Quoted 13 lines · Heng Qi
Quoted 12 lines · Toke Høiland-Jørgensen
Quoted 10 lines · Heng Qi
Quoted 9 lines · Toke Høiland-Jørgensen
Quoted 5 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
Quoted 80 lines
Quoted 3 lines
Quoted 2 lines
In general, we don't expect veth to drop packets when it doesn't mount the xdp program or otherwise, because this is not as expected.
Well, did you consider that maybe your expectation is wrong? ;)
For users who don't know what other conditions are required for the readiness of napi, all they can observe is why the packets cannot be sent to the peer veth, which is also the problem we encountered in the actual case scenarios.
Quoted 71 lines
Quoted 60 lines
Quoted 52 lines
Quoted 52 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +25
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ());Quoted 8 lines
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 6 lines
drivers/net/veth.c +6
-0+if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
Quoted 3 lines
Yes, there are indeed some optimizations that can be done here, like putting the lock outside the loop.
But in__dev_queue_xmit(), where each packet sent is also protected by a lock....which is another reason why this is a bad idea: it's going to perform terribly, which means we'll just end up with users wondering why their XDP performance is terrible and we're going to have to tell them to turn on GRO anyway. So why not do this from the beginning?
If you want to change the default, flipping GRO to be on by default is a better solution IMO. I don't actually recall why we didn't do that when the support was added, but maybe Paolo remembers?
I preferred to avoid changing the default behavior. Additionally, the veth GRO stage needs some tuning to really be able to aggregate the packets (e.g. napi thread or gro_flush_timeout > 0)
Quoted 2 lines
As I said above in the real case, the user's concern is not why the performance of xdp becomes bad, but why the data packets are not received.
Well, that arguably tells the end-user there is something wrong in their setup. On the flip side, having a functionally working setup with horrible performances would likely lead the users (perhaps not yours, surely others) in very wrong directions (from "XDP is slow" to "the problem is in the application")...
Quoted 6 lines
The default number of veth queues is not
num_possible_cpus(). When GRO is enabled by default, if there is only one veth queue, but multiple CPUs read and write at the same time, the efficiency of napi is actually very low due to the existence of production locks and races. On the contrary, the defaultveth_xmit()each cpu has its own unique queue, and this way of sending and receiving packets is also efficient.
This patch adds a bit of complexity and it looks completely avoidable with some configuration - you could enable GRO and set the number of queues to num_possible_cpus().
I agree with Toke, you should explain the end-users that their expecations are wrong, and guide them towards a better setup.
Thanks!
Paolo
Quoted 112 lines · Paolo Abeni
Hello,
Quoted 11 lines · Heng Qi
Quoted 10 lines · Toke Høiland-Jørgensen
Quoted 8 lines · Heng Qi
Quoted 7 lines · Toke Høiland-Jørgensen
Quoted 5 lines · Heng Qi
In the current processing logic, when
xdp_redirectoccurs, it transmits the xdp frame based on napi.If napi of the peer veth is not ready, the veth will drop the packets. This doesn't meet our expectations.
Quoted 80 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Erm, why don't you just enable NAPI? Loading an XDP program is not needed these days, you can just enable GRO on both peers...
In general, we don't expect veth to drop packets when it doesn't mount the xdp program or otherwise, because this is not as expected.
Well, did you consider that maybe your expectation is wrong? ;)
For users who don't know what other conditions are required for the readiness of napi, all they can observe is why the packets cannot be sent to the peer veth, which is also the problem we encountered in the actual case scenarios.
Quoted 70 lines
Quoted 59 lines
Quoted 51 lines
Quoted 51 lines
In this context, if napi is not ready, we convert the xdp frame to a skb, and then use
veth_xmit()to deliver it to the peer veth.Like the following case:
Even if veth1's napi cannot be used, the packet redirected from the NIC will be transmitted to veth1 successfully:NIC -> veth0----veth1
| | (XDP) (no XDP)Signed-off-by Heng Qi <[email protected]>Signed-off-by Xuan Zhuo <[email protected]>--- drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)drivers/net/veth.c +25
-1@@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,/* The napi pointer is set if NAPI is enabled, which ensures that * xdp_ring is initialized on receive side and the peer device is up. */ -if (!rcu_access_pointer (rq->napi)) +if (!rcu_access_pointer (rq->napi)) { +for (i =0 ; i < n; i++) { +struct xdp_frame *xdpf = frames[i]; +struct netdev_queue *txq =NULL ; +struct sk_buff *skb; +int queue_mapping; +u16 mac_len; + + skb =xdp_build_skb_from_frame (xdpf, dev); +if (unlikely (!skb)) { + ret = nxmit; + goto out; + } + +/* We need to restore ETH header, because it is pulled +* in eth_type_trans. +*/ + mac_len = skb->data -skb_mac_header (skb); +skb_push (skb, mac_len); + + nxmit++; + + queue_mapping =skb_get_queue_mapping (skb); + txq =netdev_get_tx_queue (dev,netdev_cap_txqueue (dev, queue_mapping)); +__netif_tx_lock (txq,smp_processor_id ());Quoted 8 lines
drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 502
Quoted 6 lines
drivers/net/veth.c +6
-0+if (unlikely (veth_xmit (skb, dev) !=NETDEV_TX_OK )) { +__netif_tx_unlock (txq); + ret = nxmit; + goto out; + } +__netif_tx_unlock (txq);Locking and unlocking the txq repeatedly for each packet? Yikes! Did you measure the performance overhead of this?
Quoted 3 lines
Yes, there are indeed some optimizations that can be done here, like putting the lock outside the loop.
But in__dev_queue_xmit(), where each packet sent is also protected by a lock....which is another reason why this is a bad idea: it's going to perform terribly, which means we'll just end up with users wondering why their XDP performance is terrible and we're going to have to tell them to turn on GRO anyway. So why not do this from the beginning?
If you want to change the default, flipping GRO to be on by default is a better solution IMO. I don't actually recall why we didn't do that when the support was added, but maybe Paolo remembers?
I preferred to avoid changing the default behavior. Additionally, the veth GRO stage needs some tuning to really be able to aggregate the packets (e.g. napi thread or
gro_flush_timeout> 0)Quoted 2 lines
As I said above in the real case, the user's concern is not why the performance of xdp becomes bad, but why the data packets are not received.
Well, that arguably tells the end-user there is something wrong in their setup. On the flip side, having a functionally working setup with horrible performances would likely lead the users (perhaps not yours, surely others) in very wrong directions (from "XDP is slow" to "the problem is in the application")...
Quoted 6 lines
The default number of veth queues is not
num_possible_cpus(). When GRO is enabled by default, if there is only one veth queue, but multiple CPUs read and write at the same time, the efficiency of napi is actually very low due to the existence of production locks and races. On the contrary, the defaultveth_xmit()each cpu has its own unique queue, and this way of sending and receiving packets is also efficient.
Quoted 8 lines
This patch adds a bit of complexity and it looks completely avoidable with some configuration - you could enable GRO and set the number of queues to
num_possible_cpus().I agree with Toke, you should explain the end-users that their expecations are wrong, and guide them towards a better setup.
Thanks!
Well, one thing I want to know is that in the following scenario,
NIC -> veth0----veth1
| | | (XDP) (XDP) (no XDP)
xdp_redirect is triggered,
and NIC and veth0 are both mounted with the xdp program, then why our default behavior is to drop packets that should be sent to veth1 instead of when veth0 is mounted with xdp program, the napi ring of veth1 is opened by default at the same time? Why not make it like this, but we must configure a simple xdp program on veth1?
Thanks.
Quoted 2 lines
Paolo
Quoted 26 lines · Heng Qi
Quoted 14 lines
Quoted 2 lines
As I said above in the real case, the user's concern is not why the performance of xdp becomes bad, but why the data packets are not received.
Well, that arguably tells the end-user there is something wrong in their setup. On the flip side, having a functionally working setup with horrible performances would likely lead the users (perhaps not yours, surely others) in very wrong directions (from "XDP is slow" to "the problem is in the application")...
Quoted 6 lines
The default number of veth queues is not
num_possible_cpus(). When GRO is enabled by default, if there is only one veth queue, but multiple CPUs read and write at the same time, the efficiency of napi is actually very low due to the existence of production locks and races. On the contrary, the defaultveth_xmit()each cpu has its own unique queue, and this way of sending and receiving packets is also efficient.Quoted 8 lines
This patch adds a bit of complexity and it looks completely avoidable with some configuration - you could enable GRO and set the number of queues to
num_possible_cpus().I agree with Toke, you should explain the end-users that their expecations are wrong, and guide them towards a better setup.
Thanks!
Well, one thing I want to know is that in the following scenario,
NIC -> veth0----veth1
Quoted 8 lines
| | | (XDP) (XDP) (no XDP)
xdp_redirectis triggered,
and NIC and veth0 are both mounted with the xdp program, then why our default behavior is to drop packets that should be sent to veth1 instead of when veth0 is mounted with xdp program, the napi ring of veth1 is opened by default at the same time? Why not make it like this, but we must configure a simple xdp program on veth1?
As I said in my initial reply, you don't actually need to load an XDP program (anymore), it's enough to enable GRO through ethtool on both peers. You can easily do this on setup if you know XDP is going to be used in your environment.
-Toke
Quoted 35 lines · Toke Høiland-Jørgensen
Quoted 25 lines · Heng Qi
Quoted 14 lines
Quoted 2 lines
As I said above in the real case, the user's concern is not why the performance of xdp becomes bad, but why the data packets are not received.
Well, that arguably tells the end-user there is something wrong in their setup. On the flip side, having a functionally working setup with horrible performances would likely lead the users (perhaps not yours, surely others) in very wrong directions (from "XDP is slow" to "the problem is in the application")...
Quoted 6 lines
The default number of veth queues is not
num_possible_cpus(). When GRO is enabled by default, if there is only one veth queue, but multiple CPUs read and write at the same time, the efficiency of napi is actually very low due to the existence of production locks and races. On the contrary, the defaultveth_xmit()each cpu has its own unique queue, and this way of sending and receiving packets is also efficient.Quoted 8 lines
This patch adds a bit of complexity and it looks completely avoidable with some configuration - you could enable GRO and set the number of queues to
num_possible_cpus().I agree with Toke, you should explain the end-users that their expecations are wrong, and guide them towards a better setup.
Thanks!
Well, one thing I want to know is that in the following scenario,
NIC -> veth0----veth1
Quoted 8 lines
| | | (XDP) (XDP) (no XDP)
xdp_redirectis triggered,
and NIC and veth0 are both mounted with the xdp program, then why our default behavior is to drop packets that should be sent to veth1 instead of when veth0 is mounted with xdp program, the napi ring of veth1 is opened by default at the same time? Why not make it like this, but we must configure a simple xdp program on veth1?
Quoted 4 lines
As I said in my initial reply, you don't actually need to load an XDP program (anymore), it's enough to enable GRO through ethtool on both peers. You can easily do this on setup if you know XDP is going to be used in your environment.
This does serve our purpose, but in fact, users of veth pair do not necessarily understand how it works. In this case, for users who are not familiar with veth pair, they may not know that they need to enable GRO or load the xdp program for peer veth to ensure that the redirected packets can be received smoothly. In order to solve this overwhelming problem, they may go to take the time to look at the source code, or even find someone else to solve it, but we can avoid these with simple modifications (modifications may not be the rollback, using the backlog instead of the napi ring, made by this patch), for example, maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
Thanks.
Quoted 1 line
-Toke
Quoted 6 lines · Heng Qi
maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
It could be, perhaps? One issue is what to do once the XDP program is then unloaded? We should probably disable NAPI on the peer in this case, but then we'd need to track whether it was enabled by loading an XDP program; we don't want to disable GRO/NAPI if the user requested it explicitly. This kind of state tracking gets icky fast, so I guess it'll depend on the patch...
-Toke
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Heng Qi
maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
Quoted 6 lines
It could be, perhaps? One issue is what to do once the XDP program is then unloaded? We should probably disable NAPI on the peer in this case, but then we'd need to track whether it was enabled by loading an XDP program; we don't want to disable GRO/NAPI if the user requested it explicitly. This kind of state tracking gets icky fast, so I guess it'll depend on the patch...
Regarding tracking whether we disable the napi of peer veth when unloading the veth's xdp program, this can actually be handled cleanly.
We need to note that when peer veth enable GRO, the peer veth device will update the dev->wanted_features with NETIF_F_GRO of peer veth (refer to __netdev_update_features() and veth_set_features() ).
When veth loads the xdp program and the napi of peer veth is not ready (that is, peer veth does not load the xdp program or has no enable gro), at this time, we can choose ethtool -K veth0 gro on to enable the napi of peer veth, this command also makes the peer veth device update their wanted_features, or choose we automatically enable napi for peer veth.
If we want to unload the xdp program for veth, peer veth cannot directly disable its napi, because we need to judge whether peer veth is gro_requested ( ref to veth_gro_requested() ) or has its priv->_xdp_prog, if so, just clean veth's xdp environment and disable the napi of veth instead of directly disable the napi of peer veth, because of the existence of the gro_requested and the xdp program loading on peer veth.
But, if peer veth does not have gro_requested or xdp_program loading on itself, then we can directly disable the napi of peer veth.
Thanks.
Quoted 1 line
-Toke
Quoted 38 lines · Heng Qi
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Heng Qi
maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
Quoted 6 lines
It could be, perhaps? One issue is what to do once the XDP program is then unloaded? We should probably disable NAPI on the peer in this case, but then we'd need to track whether it was enabled by loading an XDP program; we don't want to disable GRO/NAPI if the user requested it explicitly. This kind of state tracking gets icky fast, so I guess it'll depend on the patch...
Regarding tracking whether we disable the napi of peer veth when unloading the veth's xdp program, this can actually be handled cleanly.
We need to note that when peer veth enable GRO, the peer veth device will update the
dev->wanted_featureswithNETIF_F_GROof peer veth (refer to__netdev_update_features()andveth_set_features()).When veth loads the xdp program and the napi of peer veth is not ready (that is, peer veth does not load the xdp program or has no enable gro), at this time, we can choose
ethtool -K veth0 gro onto enable the napi of peer veth, this command also makes the peer veth device update theirwanted_features, or choose we automatically enable napi for peer veth.If we want to unload the xdp program for veth, peer veth cannot directly disable its napi, because we need to judge whether peer veth is
gro_requested( ref toveth_gro_requested()) or has itspriv->_xdp_prog, if so, just clean veth's xdp environment and disable the napi of veth instead of directly disable the napi of peer veth, because of the existence of thegro_requestedand the xdp program loading on peer veth.
Quoted 2 lines
But, if peer veth does not have
gro_requestedorxdp_programloading on itself, then we can directly disable the napi of peer veth.
Hi, Toke. Do you think the above solution is effective for the problem of veth xdp_rediect dropping packets? Or is there more to add? If the above solution seems to be no problem for the time being, I'm ready to start with this idea and try to make the corresponding patch.
Thanks.
Quoted 5 lines
Thanks.
Quoted 1 line
-Toke
Quoted 46 lines · Heng Qi
Quoted 41 lines · Heng Qi
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Heng Qi
maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
Quoted 6 lines
It could be, perhaps? One issue is what to do once the XDP program is then unloaded? We should probably disable NAPI on the peer in this case, but then we'd need to track whether it was enabled by loading an XDP program; we don't want to disable GRO/NAPI if the user requested it explicitly. This kind of state tracking gets icky fast, so I guess it'll depend on the patch...
Regarding tracking whether we disable the napi of peer veth when unloading
the veth's xdp program, this can actually be handled cleanly.We need to note that when peer veth enable GRO, the peer veth device will update the
dev->wanted_featureswithNETIF_F_GROof peer veth (refer to__netdev_update_features()andveth_set_features()).When veth loads the xdp program and the napi of peer veth is not ready (that is, peer veth does not load the xdp program or has no enable gro), at this time, we can choose
ethtool -K veth0 gro onto enable the napi of
peer veth, this command also makes the peer veth device update theirwanted_features, or choose we automatically enable napi for peer veth.If we want to unload the xdp program for veth, peer veth cannot directly disable its napi, because we need to judge whether peer veth is
gro_requested
( ref toveth_gro_requested()) or has itspriv->_xdp_prog, if so, just clean veth's xdp environment and disable the napi of veth instead of directly disable the napi of peer veth, because of the existence of thegro_requestedand the xdp program loading on peer veth.Quoted 3 lines
But, if peer veth does not have
gro_requestedorxdp_programloading on itself,
then we can directly disable the napi of peer veth.
Quoted 5 lines
Hi, Toke. Do you think the above solution is effective for the problem of veth
xdp_rediectdropping packets? Or is there more to add? If the above solution seems to be no problem for the time being, I'm ready to start with this idea and try to make the corresponding patch.
I think it might? Please write a patch and we can have a look :)
-Toke
Quoted 45 lines · Toke Høiland-Jørgensen
Quoted 43 lines · Heng Qi
Quoted 42 lines · Heng Qi
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Heng Qi
maybe we should consider a simpler method: when loading xdp in veth, we can automatically enable the napi ring of peer veth, which seems to have no performance impact and functional impact on the veth pair, and no longer requires users to do more things for peer veth (after all, they may be unaware of more requirements for peer veth). Do you think this is feasible?
Quoted 6 lines
It could be, perhaps? One issue is what to do once the XDP program is then unloaded? We should probably disable NAPI on the peer in this case, but then we'd need to track whether it was enabled by loading an XDP program; we don't want to disable GRO/NAPI if the user requested it explicitly. This kind of state tracking gets icky fast, so I guess it'll depend on the patch...
Regarding tracking whether we disable the napi of peer veth when unloading
the veth's xdp program, this can actually be handled cleanly.We need to note that when peer veth enable GRO, the peer veth device will update the
dev->wanted_featureswithNETIF_F_GROof peer veth (refer to__netdev_update_features()andveth_set_features()).When veth loads the xdp program and the napi of peer veth is not ready (that is, peer veth does not load the xdp program or has no enable gro), at this time, we can choose
ethtool -K veth0 gro onto enable the napi of
peer veth, this command also makes the peer veth device update theirwanted_features, or choose we automatically enable napi for peer veth.If we want to unload the xdp program for veth, peer veth cannot directly disable its napi, because we need to judge whether peer veth is
gro_requested
( ref toveth_gro_requested()) or has itspriv->_xdp_prog, if so, just clean veth's xdp environment and disable the napi of veth instead of directly disable the napi of peer veth, because of the existence of thegro_requestedand the xdp program loading on peer veth.But, if peer veth does not have
gro_requestedorxdp_programloading on itself,
then we can directly disable the napi of peer veth.
Quoted 6 lines
Quoted 5 lines
Hi, Toke. Do you think the above solution is effective for the problem of veth
xdp_rediectdropping packets? Or is there more to add? If the above solution seems to be no problem for the time being, I'm ready to start with this idea and try to make the corresponding patch.I think it might? Please write a patch and we can have a look :)
Okay, I will do it right away.
Thanks.
Quoted 2 lines
-Toke