Skip to content

Commit c9d1d23

Browse files
nbd168Paolo Abeni
authored andcommitted
net: add heuristic for enabling TCP fraglist GRO
When forwarding TCP after GRO, software segmentation is very expensive, especially when the checksum needs to be recalculated. One case where that's currently unavoidable is when routing packets over PPPoE. Performance improves significantly when using fraglist GRO implemented in the same way as for UDP. When NETIF_F_GRO_FRAGLIST is enabled, perform a lookup for an established socket in the same netns as the receiving device. While this may not cover all relevant use cases in multi-netns configurations, it should be good enough for most configurations that need this. Here's a measurement of running 2 TCP streams through a MediaTek MT7622 device (2-core Cortex-A53), which runs NAT with flow offload enabled from one ethernet port to PPPoE on another ethernet port + cake qdisc set to 1Gbps. rx-gro-list off: 630 Mbit/s, CPU 35% idle rx-gro-list on: 770 Mbit/s, CPU 40% idle Acked-by: Paolo Abeni <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Felix Fietkau <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 7516b27 commit c9d1d23

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

net/ipv4/tcp_offload.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,36 @@ void tcp_gro_complete(struct sk_buff *skb)
407407
}
408408
EXPORT_SYMBOL(tcp_gro_complete);
409409

410+
static void tcp4_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
411+
struct tcphdr *th)
412+
{
413+
const struct iphdr *iph;
414+
struct sk_buff *p;
415+
struct sock *sk;
416+
struct net *net;
417+
int iif, sdif;
418+
419+
if (likely(!(skb->dev->features & NETIF_F_GRO_FRAGLIST)))
420+
return;
421+
422+
p = tcp_gro_lookup(head, th);
423+
if (p) {
424+
NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
425+
return;
426+
}
427+
428+
inet_get_iif_sdif(skb, &iif, &sdif);
429+
iph = skb_gro_network_header(skb);
430+
net = dev_net(skb->dev);
431+
sk = __inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
432+
iph->saddr, th->source,
433+
iph->daddr, ntohs(th->dest),
434+
iif, sdif);
435+
NAPI_GRO_CB(skb)->is_flist = !sk;
436+
if (sk)
437+
sock_put(sk);
438+
}
439+
410440
INDIRECT_CALLABLE_SCOPE
411441
struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb)
412442
{
@@ -422,6 +452,8 @@ struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb)
422452
if (!th)
423453
goto flush;
424454

455+
tcp4_check_fraglist_gro(head, skb, th);
456+
425457
return tcp_gro_receive(head, skb, th);
426458

427459
flush:

net/ipv6/tcpv6_offload.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,45 @@
77
*/
88
#include <linux/indirect_call_wrapper.h>
99
#include <linux/skbuff.h>
10+
#include <net/inet6_hashtables.h>
1011
#include <net/gro.h>
1112
#include <net/protocol.h>
1213
#include <net/tcp.h>
1314
#include <net/ip6_checksum.h>
1415
#include "ip6_offload.h"
1516

17+
static void tcp6_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
18+
struct tcphdr *th)
19+
{
20+
#if IS_ENABLED(CONFIG_IPV6)
21+
const struct ipv6hdr *hdr;
22+
struct sk_buff *p;
23+
struct sock *sk;
24+
struct net *net;
25+
int iif, sdif;
26+
27+
if (likely(!(skb->dev->features & NETIF_F_GRO_FRAGLIST)))
28+
return;
29+
30+
p = tcp_gro_lookup(head, th);
31+
if (p) {
32+
NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
33+
return;
34+
}
35+
36+
inet6_get_iif_sdif(skb, &iif, &sdif);
37+
hdr = skb_gro_network_header(skb);
38+
net = dev_net(skb->dev);
39+
sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
40+
&hdr->saddr, th->source,
41+
&hdr->daddr, ntohs(th->dest),
42+
iif, sdif);
43+
NAPI_GRO_CB(skb)->is_flist = !sk;
44+
if (sk)
45+
sock_put(sk);
46+
#endif /* IS_ENABLED(CONFIG_IPV6) */
47+
}
48+
1649
INDIRECT_CALLABLE_SCOPE
1750
struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)
1851
{
@@ -28,6 +61,8 @@ struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)
2861
if (!th)
2962
goto flush;
3063

64+
tcp6_check_fraglist_gro(head, skb, th);
65+
3166
return tcp_gro_receive(head, skb, th);
3267

3368
flush:

0 commit comments

Comments
 (0)