Prevent packet reordering on tap/tun interfaces
Subsystems (3)
cover Prevent packet reordering on tap/tun interfaces
This patch set is meant to address a recent issue I found with VMs sending traffic across a network. Specifically what I found was that the tap interfaces were spreading single flows across all CPUs on the system due to the fact that the sending VM was being load balanced across them. Under light load this doesn't have much of an impact, however under heavier loads where the interfaces are already running with Rx cleanup from other flows on the CPUs I have seen this have a fairly significant impact as we can avoid any issues due to reordering. The results can be anywhere from 10 to 30% improvement from what I have seen.
---
Alexander Duyck (2):
net: Add function to allow configuration of RPS
tun: Configure Rx queues to default to RPS enabled
drivers/net/tun.c | 4 +++- include/linux/netdevice.h | 9 ++++++++ net/core/dev.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- net/core/net-sysfs.c | 45 +++++++--------------------------------- 4 files changed, 70 insertions(+), 39 deletions(-)
PATCH 1/2 net: Add function to allow configuration of RPS
This patch gives drivers the ability to set their own default RPS configuration. The general idea is to allow drivers that might benefit from enabling RPS an opportunity to configure it for themselves.
--- include/linux/netdevice.h | 9 ++++++++ net/core/dev.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- net/core/net-sysfs.c | 45 +++++++--------------------------------- 3 files changed, 67 insertions(+), 38 deletions(-)
include/linux/netdevice.h +9 -0
@@ -684,6 +684,15 @@ static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,bool rps_may_expire_flow (struct net_device *dev,u16 rxq_index,u32 flow_id,u16 filter_id);#endif +int netif_set_rps_cpus (struct net_device *dev,const struct cpumask *mask, +u16 index); +#else +static inline int netif_set_rps_cpus (struct net_device *dev, +const struct cpumask *mask, +u16 index) +{ +return 0 ; +}#endif /* CONFIG_RPS */ /* This structure contains an instance of an RX queue. */
net/core/dev.c +50 -1
63 lines not on this page · raw message
net/core/net-sysfs.c +8 -37
66 lines not on this page · raw message
PATCH 2/2 tun: Configure Rx queues to default to RPS enabled
In reply to Alexander DuyckThis patch enables tun/tap interfaces to use RPS by default. The motivation behind this is to address the fact that the interfaces are currently using netif_rx_ni which in turn will queue packets on whatever CPU the function is called on, and when combined with load balancing this can result in packets being received out of order.
--- drivers/net/tun.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/tun.c +3 -1
@@ -646,7 +646,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte tfile->socket.sk->sk_shutdown &= ~RCV_SHUTDOWN ;rcu_assign_pointer (tfile->tun, tun);rcu_assign_pointer (tun->tfiles[tun->numqueues], tfile); - tun->numqueues++;if (tfile->detached)tun_enable_queue (tfile);
@@ -655,6 +654,9 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filtetun_set_real_num_queues (tun); +netif_set_rps_cpus (tun->dev, cpu_online_mask, tun->numqueues); + tun->numqueues++; +/* device is allowed to go away first, so no need to hold extra * refcnt. */
Re: [net-next PATCH 1/2] net: Add function to allow configuration of RPS
In reply to Alexander DuyckQuoted 36 lines · Alexander Duyck
This patch gives drivers the ability to set their own default RPS configuration. The general idea is to allow drivers that might benefit from enabling RPS an opportunity to configure it for themselves.
Signed-off-by Alexander Duyck <[email protected]>--- include/linux/netdevice.h | 9 ++++++++ net/core/dev.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- net/core/net-sysfs.c | 45 +++++++--------------------------------- 3 files changed, 67 insertions(+), 38 deletions(-)include/linux/netdevice.h +9
-0@@ -684,6 +684,15 @@ static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,bool rps_may_expire_flow (struct net_device *dev,u16 rxq_index,u32 flow_id,u16 filter_id);#endif +int netif_set_rps_cpus (struct net_device *dev,const struct cpumask *mask, +u16 index); +#else +static inline int netif_set_rps_cpus (struct net_device *dev, +const struct cpumask *mask, +u16 index) +{ +return 0 ; +}#endif /* CONFIG_RPS */ /* This structure contains an instance of an RX queue. */ net/core/dev.c +0
-0
net/core/dev.c static void netif_setup_tc(struct net_device *dev, unsigned int txq) · line 1940
Quoted 8 lines
net/core/dev.c +1
-1@@ -1934,7 +1934,7 @@ static void netif_setup_tc(struct net_device *dev, unsigned int txq)return ; } -/* Invalidated prio to tc mappings set to TC0 */ +/* Invaldated prio to tc mappings set to TC0 */ for (i =1 ; i <TC_BITMASK +1 ; i++) {int q =netdev_get_prio_tc_map (dev, i);
I just noticed that I fat fingered this when doing some last edits on the patch. So I will be submitting a v2.
For now I will leave this out here for review, and I will wait to see if there are any other changes needed after others have had a chance to look over the rest of this patch set.
- Alex
Re: [net-next PATCH 2/2] tun: Configure Rx queues to default to RPS enabled
In reply to Alexander DuyckQuoted 5 lines · Alexander Duyck
This patch enables tun/tap interfaces to use RPS by default. The motivation behind this is to address the fact that the interfaces are currently using
netif_rx_niwhich in turn will queue packets on whatever CPU the function is called on, and when combined with load balancing this can result in packets being received out of order.
Hmm...
I do not believe this can be made the default, this would be a major regression in some cases.
Some users want cpu isolation. This is their number one priority.
If they use one cpu to feed packets through tun device, they do not want to spread a DDOS to all online cpus. Traffic from one VM would hurt all others.
We have ways to avoid reorders already in TX path (skb->ooo_okay) and receive path in RFS layer.
tun could probably avoid reorders using a similar technique.
netif_rx_ni() could be extended to give a hint on the cpu that processed prior packets.
(This would be a new function)
If the prior cpu is different than current cpu, we have to look at the backlog of prior cpu.
If not empty, and prior cpu online, we need to queue the packet to prior cpu queue.
If empty, we can 'switch' to the new cpu queue.
Re: [net-next PATCH 2/2] tun: Configure Rx queues to default to RPS enabled
Quoted 11 lines · Eric Dumazet
Quoted 5 lines · Alexander Duyck
This patch enables tun/tap interfaces to use RPS by default. The motivation behind this is to address the fact that the interfaces are currently using
netif_rx_niwhich in turn will queue packets on whatever CPU the function is called on, and when combined with load balancing this can result in packets being received out of order.Hmm...
I do not believe this can be made the default, this would be a major regression in some cases.
Yeah, while thinking about it this morning I kind of realized the solution is very x86-centric as well. It assumes all CPUs are equal and I know there are a few architectures where that is not the case.
Quoted 14 lines
Some users want cpu isolation. This is their number one priority.
If they use one cpu to feed packets through tun device, they do not want to spread a DDOS to all online cpus. Traffic from one VM would hurt all others.
We have ways to avoid reorders already in TX path (
skb->ooo_okay) and receive path in RFS layer.tun could probably avoid reorders using a similar technique.
netif_rx_ni()could be extended to give a hint on the cpu that processed prior packets.
Quoted 7 lines
(This would be a new function)
If the prior cpu is different than current cpu, we have to look at the backlog of prior cpu.
If not empty, and prior cpu online, we need to queue the packet to prior cpu queue.
If empty, we can 'switch' to the new cpu queue.
What I can probably do is look into borrowing some of the code from the receive flow steering path. I believe there was some logic there that already did checks for packets in the backlog. What I can probably do is just make use of that in order to avoid reordering.
- Alex