net: route: improve route hinting
Subsystems (6)
v2 cover net: route: improve route hinting
In 2017, Paolo Abeni introduced the hinting mechanism [1] to the routing sub-system. The hinting optimization improves performance by reusing previously found dsts instead of looking them up for each skb.
This patch series introduces a generalized version of the hinting mechanism that can "remember" a larger number of dsts. This reduces the number of dst lookups for frequently encountered daddrs.
Before diving into the code and the benchmarking results, it's important to address the deletion of the old route cache [2] and why this solution is different. The original cache was complicated, vulnerable to DOS attacks and had unstable performance.
The new input dst_cache is much simpler thanks to its lazy approach, improving performance without the overhead of the removed cache implementation. Instead of using timers and GC, the deletion of invalid entries is performed lazily during their lookups.
The dsts are stored in a simple, lightweight, static hash table. This keeps the lookup times fast yet stable, preventing DOS upon cache misses. The new input dst_cache implementation is built over the existing dst_cache code which supplies a fast lockless percpu behavior.
The measurement setup is comprised of 2 machines with mlx5 100Gbit NIC. I sent small UDP packets with 5000 daddrs (10x of cache size) from one machine to the other while also varying the saddr and the tos. I set an iptables rule to drop the packets after routing. the receiving machine's CPU (i9) was saturated.
Thanks a lot to David Ahern for all the help and guidance!
I measured the rx PPS using ifpps and the per-queue PPS using ethtool -S. These are the results:
Total PPS:
mainline patched delta
Kpps Kpps %
6903 8105 17.41
Per-Queue PPS:
Queue mainline patched 0 345775 411780 1 345252 414387 2 347724 407501 3 346232 413456 4 347271 412088 5 346808 400910 6 346243 406699 7 346484 409104 8 342731 404612 9 344068 407558 10 345832 409558 11 346296 409935 12 346900 399084 13 345980 404513 14 347244 405136 15 346801 408752 16 345984 410865 17 346632 405752 18 346064 407539 19 344861 408364 total 6921182 8157593
I also verified that the number of packets caught by the iptables rule matches the measured PPS.
TCP throughput was not affected by the patch, below is iperf3 output:
mainline patched
15.4 GBytes 13.2 Gbits/sec 15.5 GBytes 13.2 Gbits/sec
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
v1->v2:
- fix bitwise cast warning
- improved measurements setup
v1:
- fix typo while allocating per-cpu cache
- while using dst from the dst_cache set IPSKB_DOREDIRECT correctly
- always compile dst_cache
RFC-v2:
- remove unnecessary macro
- move inline to .h file
RFC-v1: https://lore.kernel.org/netdev/[email protected]/
RFC-v2: https://lore.kernel.org/netdev/[email protected]/
Leone Fernando (4):
net: route: expire rt if the dst it holds is expired
net: dst_cache: add input_dst_cache API
net: route: always compile dst_cache
net: route: replace route hints with input_dst_cache
drivers/net/Kconfig | 1 - include/net/dst_cache.h | 68 +++++++++++++++++++ include/net/dst_metadata.h | 2 - include/net/ip_tunnels.h | 2 - include/net/route.h | 6 +- net/Kconfig | 4 -- net/core/Makefile | 3 +- net/core/dst.c | 4 -- net/core/dst_cache.c | 132 +++++++++++++++++++++++++++++++++++++ net/ipv4/Kconfig | 1 - net/ipv4/ip_input.c | 58 ++++++++-------- net/ipv4/ip_tunnel_core.c | 4 -- net/ipv4/route.c | 75 +++++++++++++++------ net/ipv4/udp_tunnel_core.c | 4 -- net/ipv6/Kconfig | 4 -- net/ipv6/ip6_udp_tunnel.c | 4 -- net/netfilter/nft_tunnel.c | 2 - net/openvswitch/Kconfig | 1 - net/sched/act_tunnel_key.c | 2 - 19 files changed, 291 insertions(+), 86 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 net: route: expire rt if the dst it holds is expired
The function rt_is_expired is used to verify that a cached dst is valid. Currently, this function ignores the rt.dst->expires value.
Add a check to rt_is_expired that validates that the dst is not expired.
--- net/ipv4/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/route.c +2 -1
@@ -389,7 +389,8 @@ static inline int ip_rt_proc_init(void)static inline bool rt_is_expired (const struct rtable *rth) { -return rth->rt_genid !=rt_genid_ipv4 (dev_net (rth->dst.dev)); +return rth->rt_genid !=rt_genid_ipv4 (dev_net (rth->dst.dev)) || + (rth->dst.expires &&time_after (jiffies, rth->dst.expires)); }void rt_cache_flush (struct net *net)
Signature · 1 line
2.34.1
PATCH v2 2/4 net: dst_cache: add input_dst_cache API
In reply to Leone FernandoThe input_dst_cache allows fast lookup of frequently encountered dsts.
In order to provide stable results, I implemented a simple linear hashtable with each bucket containing a constant amount of entries (DST_CACHE_INPUT_BUCKET_SIZE).
Similarly to how the route hint is used, I defined the hashtable key to contain the daddr and the tos of the IP header.
Lookup is performed in a straightforward manner: start at the bucket head corresponding the hashed key and search the following DST_CACHE_INPUT_BUCKET_SIZE entries of the array for a matching key.
When inserting a new dst to the cache, if all the bucket entries are full, the oldest one is deleted to make room for the new dst.
--- include/net/dst_cache.h | 68 +++++++++++++++++++++ net/core/dst_cache.c | 132 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+)
include/net/dst_cache.h +68 -0
@@ -7,12 +7,40 @@#if IS_ENABLED (CONFIG_IPV6 )#include <net/ip6_fib.h> #endif +#include <net/ip.h> + +#define DST_CACHE_INPUT_SHIFT (9) +#define DST_CACHE_INPUT_SIZE (1 << DST_CACHE_INPUT_SHIFT) +#define DST_CACHE_INPUT_BUCKET_SIZE (4) +#define DST_CACHE_INPUT_HASH_MASK (~(DST_CACHE_INPUT_BUCKET_SIZE - 1)) +#define INVALID_DST_CACHE_INPUT_KEY (~(u64)(0))struct dst_cache {struct dst_cache_pcpu __percpu *cache;unsigned long reset_ts; }; +extern unsigned int dst_cache_net_id__read_mostly ; + +/** +* idst_for_each_in_bucket - iterate over a dst cache bucket +* @pos: the type * to use as a loop cursor +* @head: the head of the cpu dst cache. +* @hash: the hash of the bucket +*/ +#define idst_for_each_in_bucket (pos, head, hash) \ + for (pos = &head[hash]; \ + pos < &head[hash + DST_CACHE_INPUT_BUCKET_SIZE]; \ + pos++) + +/** +* idst_for_each_in_cache - iterate over the dst cache +* @pos: the type * to use as a loop cursor +* @head: the head of the cpu dst cache. +*/ +#define idst_for_each_in_cache (pos, head) \ + for (pos = head; pos < head + DST_CACHE_INPUT_SIZE; pos++) +/** * dst_cache_get - perform cache lookup * @dst_cache: the cache
@@ -106,4 +134,44 @@ int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);*/ void dst_cache_destroy (struct dst_cache *dst_cache); +/** +* dst_cache_input_get_noref - perform lookup in the input cache, +* return a noref dst +* @dst_cache: the input cache +* @skb: the packet according to which the dst entry will be searched +* local BH must be disabled. +*/ +struct dst_entry *dst_cache_input_get_noref (struct dst_cache *dst_cache, +struct sk_buff *skb); + +/** +* dst_cache_input_add - add the dst of the given skb to the input cache. +* +* in case the cache bucket is full, the oldest entry will be deleted +* and replaced with the new one. +* @dst_cache: the input cache +* @skb: The packet according to which the dst entry will be searched +* +* local BH must be disabled. +*/ +void dst_cache_input_add (struct dst_cache *dst_cache, +const struct sk_buff *skb); + +/** +* dst_cache_input_init - initialize the input cache, +* allocating the required storage +*/ +int __init dst_cache_input_init (void ); + +static inline u64 create_dst_cache_key_ip4 (const struct sk_buff *skb) +{ +struct iphdr *iphdr =ip_hdr (skb); + +return (((u64 )ntohl (iphdr->daddr)) <<8 ) | iphdr->tos; +} + +static inline u32 hash_dst_cache_key (u64 key) +{ +return hash_64 (key,DST_CACHE_INPUT_SHIFT ) &DST_CACHE_INPUT_HASH_MASK ; +}#endif
net/core/dst_cache.c +132 -0
150 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 3/4 net: route: always compile dst_cache
In reply to Leone Fernandomake dst_cache to always compile, delete all relevant ifdefs
--- drivers/net/Kconfig | 1 - include/net/dst_metadata.h | 2 -- include/net/ip_tunnels.h | 2 -- net/Kconfig | 4 ---- net/core/Makefile | 3 +-- net/core/dst.c | 4 ---- net/ipv4/Kconfig | 1 - net/ipv4/ip_tunnel_core.c | 4 ---- net/ipv4/udp_tunnel_core.c | 4 ---- net/ipv6/Kconfig | 4 ---- net/ipv6/ip6_udp_tunnel.c | 4 ---- net/netfilter/nft_tunnel.c | 2 -- net/openvswitch/Kconfig | 1 - net/sched/act_tunnel_key.c | 2 -- 14 files changed, 1 insertion(+), 37 deletions(-)
drivers/net/Kconfig +0 -1
@@ -78,7 +78,6 @@ config WIREGUARD depends on IPV6 || !IPV6 depends on !KMSAN # KMSAN doesn't support the crypto configs below select NET_UDP_TUNNEL - select DST_CACHE select CRYPTO select CRYPTO_LIB_CURVE25519 select CRYPTO_LIB_CHACHA20POLY1305
include/net/dst_metadata.h +0 -2
@@ -165,7 +165,6 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb)memcpy (&new_md->u.tun_info, &md_dst->u.tun_info,sizeof (struct ip_tunnel_info ) + md_size); -#ifdef CONFIG_DST_CACHE /* Unclone the dst cache if there is one */ if (new_md->u.tun_info.dst_cache.cache) {int ret;
@@ -176,7 +175,6 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb)return ERR_PTR (ret); } } -#endif skb_dst_drop (skb);skb_dst_set (skb, &new_md->dst);
include/net/ip_tunnels.h +0 -2
@@ -102,9 +102,7 @@ struct ip_tunnel_encap {struct ip_tunnel_info {struct ip_tunnel_key key;struct ip_tunnel_encap encap; -#ifdef CONFIG_DST_CACHE struct dst_cache dst_cache; -#endif u8 options_len;u8 mode; };
net/Kconfig +0 -4
@@ -441,10 +441,6 @@ config LWTUNNEL_BPF Allows to run BPF programs as a nexthop action following a route lookup for incoming and outgoing packets. -config DST_CACHE - bool - default n - config GRO_CELLS bool default n
net/core/Makefile +1 -2
@@ -13,7 +13,7 @@ obj-y += dev.o dev_addr_lists.o dst.o netevent.o \ neighbour.o rtnetlink.o utils.o link_watch.o filter.o \ sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \ fib_notifier.o xdp.o flow_offload.o gro.o \ - netdev-genl.o netdev-genl-gen.o gso.o + netdev-genl.o netdev-genl-gen.o gso.o dst_cache.o obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
@@ -33,7 +33,6 @@ obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o obj-$(CONFIG_LWTUNNEL) += lwtunnel.o obj-$(CONFIG_LWTUNNEL_BPF) += lwt_bpf.o -obj-$(CONFIG_DST_CACHE) += dst_cache.o obj-$(CONFIG_HWBM) += hwbm.o obj-$(CONFIG_GRO_CELLS) += gro_cells.o obj-$(CONFIG_FAILOVER) += failover.o
net/core/dst.c +0 -4
@@ -291,10 +291,8 @@ EXPORT_SYMBOL_GPL(metadata_dst_alloc);void metadata_dst_free (struct metadata_dst *md_dst) { -#ifdef CONFIG_DST_CACHE if (md_dst->type ==METADATA_IP_TUNNEL )dst_cache_destroy (&md_dst->u.tun_info.dst_cache); -#endif if (md_dst->type ==METADATA_XFRM )dst_release (md_dst->u.xfrm_info.dst_orig);kfree (md_dst);
@@ -326,10 +324,8 @@ void metadata_dst_free_percpu(struct metadata_dst __percpu *md_dst)for_each_possible_cpu (cpu) {struct metadata_dst *one_md_dst =per_cpu_ptr (md_dst, cpu); -#ifdef CONFIG_DST_CACHE if (one_md_dst->type ==METADATA_IP_TUNNEL )dst_cache_destroy (&one_md_dst->u.tun_info.dst_cache); -#endif if (one_md_dst->type ==METADATA_XFRM )dst_release (one_md_dst->u.xfrm_info.dst_orig); }
net/ipv4/Kconfig +0 -1
@@ -185,7 +185,6 @@ config NET_IPGRE_DEMUX config NET_IP_TUNNEL tristate - select DST_CACHE select GRO_CELLS default n
net/ipv4/ip_tunnel_core.c +0 -4
@@ -683,13 +683,11 @@ static int ip_tun_build_state(struct net *net, struct nlattr *attr,return err; } -#ifdef CONFIG_DST_CACHE err =dst_cache_init (&tun_info->dst_cache,GFP_KERNEL );if (err) {lwtstate_free (new_state);return err; } -#endif if (tb[LWTUNNEL_IP_ID ]) tun_info->key.tun_id =nla_get_be64 (tb[LWTUNNEL_IP_ID ]);
@@ -727,11 +725,9 @@ static int ip_tun_build_state(struct net *net, struct nlattr *attr,static void ip_tun_destroy_state (struct lwtunnel_state *lwtstate) { -#ifdef CONFIG_DST_CACHE struct ip_tunnel_info *tun_info =lwt_tun_info (lwtstate);dst_cache_destroy (&tun_info->dst_cache); -#endif } static int ip_tun_fill_encap_opts_geneve(struct sk_buff *skb,
net/ipv4/udp_tunnel_core.c +0 -4
@@ -216,13 +216,11 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,struct rtable *rt =NULL ;struct flowi4 fl4; -#ifdef CONFIG_DST_CACHE if (dst_cache) { rt =dst_cache_get_ip4 (dst_cache, saddr);if (rt)return rt; } -#endif memset (&fl4,0 ,sizeof (fl4)); fl4.flowi4_mark = skb->mark;
@@ -245,10 +243,8 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,ip_rt_put (rt);return ERR_PTR (-ELOOP ); } -#ifdef CONFIG_DST_CACHE if (dst_cache)dst_cache_set_ip4 (dst_cache, &rt->dst, fl4.saddr); -#endif *saddr = fl4.saddr;return rt; }
net/ipv6/Kconfig +0 -4
@@ -124,7 +124,6 @@ config IPV6_MIP6 config IPV6_ILA tristate "IPv6: Identifier Locator Addressing (ILA)" depends on NETFILTER - select DST_CACHE select LWTUNNEL help Support for IPv6 Identifier Locator Addressing (ILA).
@@ -203,7 +202,6 @@ config IPV6_NDISC_NODETYPE config IPV6_TUNNEL tristate "IPv6: IP-in-IPv6 tunnel (RFC2473)" select INET6_TUNNEL - select DST_CACHE select GRO_CELLS help Support for IPv6-in-IPv6 and IPv4-in-IPv6 tunnels described in
@@ -291,7 +289,6 @@ config IPV6_SEG6_LWTUNNEL bool "IPv6: Segment Routing Header encapsulation support" depends on IPV6 select LWTUNNEL - select DST_CACHE select IPV6_MULTIPLE_TABLES help Support for encapsulation of packets within an outer IPv6
@@ -333,7 +330,6 @@ config IPV6_IOAM6_LWTUNNEL bool "IPv6: IOAM Pre-allocated Trace insertion support" depends on IPV6 select LWTUNNEL - select DST_CACHE help Support for the insertion of IOAM Pre-allocated Trace Header using the lightweight tunnels mechanism.
net/ipv6/ip6_udp_tunnel.c +0 -4
@@ -145,13 +145,11 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,struct dst_entry *dst =NULL ;struct flowi6 fl6; -#ifdef CONFIG_DST_CACHE if (dst_cache) { dst =dst_cache_get_ip6 (dst_cache, saddr);if (dst)return dst; } -#endif memset (&fl6,0 ,sizeof (fl6)); fl6.flowi6_mark = skb->mark; fl6.flowi6_proto =IPPROTO_UDP ;
@@ -173,10 +171,8 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,dst_release (dst);return ERR_PTR (-ELOOP ); } -#ifdef CONFIG_DST_CACHE if (dst_cache)dst_cache_set_ip6 (dst_cache, dst, &fl6.saddr); -#endif *saddr = fl6.saddr;return dst; }
net/netfilter/nft_tunnel.c +0 -2
@@ -514,13 +514,11 @@ static int nft_tunnel_obj_init(const struct nft_ctx *ctx,return -ENOMEM ;memcpy (&md->u.tun_info, &info,sizeof (info)); -#ifdef CONFIG_DST_CACHE err =dst_cache_init (&md->u.tun_info.dst_cache,GFP_KERNEL );if (err <0 ) {metadata_dst_free (md);return err; } -#endif ip_tunnel_info_opts_set (&md->u.tun_info, &priv->opts.u, priv->opts.len, priv->opts.flags); priv->md = md;
net/openvswitch/Kconfig +0 -1
@@ -13,7 +13,6 @@ config OPENVSWITCH select LIBCRC32C select MPLS select NET_MPLS_GSO - select DST_CACHE select NET_NSH select NF_CONNTRACK_OVS if NF_CONNTRACK select NF_NAT_OVS if NF_NAT
net/sched/act_tunnel_key.c +0 -2
@@ -476,11 +476,9 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla, goto err_out; } -#ifdef CONFIG_DST_CACHE ret =dst_cache_init (&metadata->u.tun_info.dst_cache,GFP_KERNEL );if (ret) goto release_tun_meta; -#endif if (opts_len) { ret = tunnel_key_opts_set(tb[TCA_TUNNEL_KEY_ENC_OPTS],
Signature · 1 line
2.34.1
PATCH v2 4/4 net: route: replace route hints with input_dst_cache
In reply to Leone FernandoReplace route hints with cached dsts - ip_rcv_finish_core will first try to use the cache and only then fall back to the demux or perform a full lookup.
Only add newly found dsts to the cache after all the checks have passed successfully to avoid adding a dropped packet's dst to the cache.
Multicast dsts are not added to the dst_cache as it will require additional checks and multicast packets are rarer and a slower path anyway.
A check was added to ip_route_use_dst_cache that prevents forwarding packets received by devices for which forwarding is disabled.
Relevant checks were added to ip_route_use_dst_cache to make sure the dst can be used and to ensure IPCB(skb) flags are correct.
--- include/net/route.h | 6 ++-- net/ipv4/ip_input.c | 58 +++++++++++++++++++----------------- net/ipv4/route.c | 72 +++++++++++++++++++++++++++++++++------------ 3 files changed, 88 insertions(+), 48 deletions(-)
include/net/route.h +3 -3
@@ -202,9 +202,9 @@ int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr, struct in_device *in_dev, u32 *itag);int ip_route_input_noref (struct sk_buff *skb,__be32 dst,__be32 src,u8 tos,struct net_device *devin); -int ip_route_use_hint (struct sk_buff *skb,__be32 dst,__be32 src, -u8 tos,struct net_device *devin, -const struct sk_buff *hint); +int ip_route_use_dst_cache (struct sk_buff *skb,__be32 daddr,__be32 saddr, +u8 tos,struct net_device *dev, +struct dst_entry *dst);static inline int ip_route_input (struct sk_buff *skb,__be32 dst,__be32 src,u8 tos,struct net_device *devin)
net/ipv4/ip_input.c +31 -27
109 lines not on this page · raw message
net/ipv4/route.c +54 -18
117 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 29 lines · Leone Fernando
In 2017, Paolo Abeni introduced the hinting mechanism [1] to the routing sub-system. The hinting optimization improves performance by reusing previously found dsts instead of looking them up for each skb.
This patch series introduces a generalized version of the hinting mechanism that can "remember" a larger number of dsts. This reduces the number of dst lookups for frequently encountered daddrs.
Before diving into the code and the benchmarking results, it's important to address the deletion of the old route cache [2] and why this solution is different. The original cache was complicated, vulnerable to DOS attacks and had unstable performance.
The new input
dst_cacheis much simpler thanks to its lazy approach, improving performance without the overhead of the removed cache implementation. Instead of using timers and GC, the deletion of invalid entries is performed lazily during their lookups.
The dsts are stored in a simple, lightweight, static hash table. This keeps the lookup times fast yet stable, preventing DOS upon cache misses. The new inputdst_cacheimplementation is built over the existingdst_cachecode which supplies a fast lockless percpu behavior.The measurement setup is comprised of 2 machines with mlx5 100Gbit NIC. I sent small UDP packets with 5000 daddrs (10x of cache size) from one machine to the other while also varying the saddr and the tos. I set an iptables rule to drop the packets after routing. the receiving machine's CPU (i9) was saturated.
Quoted 4 lines
Thanks a lot to David Ahern for all the help and guidance!
I measured the rx PPS using ifpps and the per-queue PPS using ethtool -S. These are the results:
How device dismantles are taken into account ?
I am currently tracking a bug in dst_cache, triggering sometimes when running pmtu.sh selftest.
Apparently, dst_cache_per_cpu_dst_set() can cache dst that have no dst->rt_uncached
linkage.
There is no cleanup (at least in vxlan) to make sure cached dst are either freed or
their dst->dev changed.
TEST: ipv6: cleanup of cached exceptions - nexthop objects [ OK ]
[ 1001.344490] vxlan: __vxlan_fdb_free calling dst_cache_destroy(ffff8f12422cbb90) [ 1001.345253] dst_cache_destroy dst_cache=ffff8f12422cbb90 ->cache=0000417580008d30 [ 1001.378615] vxlan: __vxlan_fdb_free calling dst_cache_destroy(ffff8f12471e31d0) [ 1001.379260] dst_cache_destroy dst_cache=ffff8f12471e31d0 ->cache=0000417580008608 [ 1011.349730] unregister_netdevice: waiting for veth_A-R1 to become free. Usage count = 7 [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] dst_alloc+0x76/0x160 [ 1011.350562] ip6_dst_alloc+0x25/0x80 [ 1011.350562] ip6_pol_route+0x2a8/0x450 [ 1011.350562] ip6_pol_route_output+0x1f/0x30 [ 1011.350562] fib6_rule_lookup+0x163/0x270 [ 1011.350562] ip6_route_output_flags+0xda/0x190 [ 1011.350562] ip6_dst_lookup_tail.constprop.0+0x1d0/0x260 [ 1011.350562] ip6_dst_lookup_flow+0x47/0xa0 [ 1011.350562] udp_tunnel6_dst_lookup+0x158/0x210 [ 1011.350562] vxlan_xmit_one+0x4c6/0x1550 [vxlan] [ 1011.350562] vxlan_xmit+0x535/0x1500 [vxlan] [ 1011.350562] dev_hard_start_xmit+0x7b/0x1e0 [ 1011.350562] __dev_queue_xmit+0x20c/0xe40 [ 1011.350562] arp_xmit+0x1d/0x50 [ 1011.350562] arp_send_dst+0x7f/0xa0 [ 1011.350562] arp_solicit+0xf6/0x2f0 [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 3/6 users at [ 1011.350562] dst_alloc+0x76/0x160 [ 1011.350562] ip6_dst_alloc+0x25/0x80 [ 1011.350562] ip6_pol_route+0x2a8/0x450 [ 1011.350562] ip6_pol_route_output+0x1f/0x30 [ 1011.350562] fib6_rule_lookup+0x163/0x270 [ 1011.350562] ip6_route_output_flags+0xda/0x190 [ 1011.350562] ip6_dst_lookup_tail.constprop.0+0x1d0/0x260 [ 1011.350562] ip6_dst_lookup_flow+0x47/0xa0 [ 1011.350562] udp_tunnel6_dst_lookup+0x158/0x210 [ 1011.350562] vxlan_xmit_one+0x4c6/0x1550 [vxlan] [ 1011.350562] vxlan_xmit+0x535/0x1500 [vxlan] [ 1011.350562] dev_hard_start_xmit+0x7b/0x1e0 [ 1011.350562] __dev_queue_xmit+0x20c/0xe40 [ 1011.350562] ip6_finish_output2+0x2ea/0x6e0 [ 1011.350562] ip6_finish_output+0x143/0x320 [ 1011.350562] ip6_output+0x74/0x140 [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] netdev_get_by_index+0xc0/0xe0 [ 1011.350562] fib6_nh_init+0x1a9/0xa90 [ 1011.350562] rtm_new_nexthop+0x6fa/0x1580 [ 1011.350562] rtnetlink_rcv_msg+0x155/0x3e0 [ 1011.350562] netlink_rcv_skb+0x61/0x110 [ 1011.350562] rtnetlink_rcv+0x19/0x20 [ 1011.350562] netlink_unicast+0x23f/0x380 [ 1011.350562] netlink_sendmsg+0x1fc/0x430 [ 1011.350562] ____sys_sendmsg+0x2ef/0x320 [ 1011.350562] ___sys_sendmsg+0x86/0xd0 [ 1011.350562] __sys_sendmsg+0x67/0xc0 [ 1011.350562] __x64_sys_sendmsg+0x21/0x30 [ 1011.350562] x64_sys_call+0x252/0x2030 [ 1011.350562] do_syscall_64+0x6c/0x190 [ 1011.350562] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] ipv6_add_dev+0x136/0x530 [ 1011.350562] addrconf_notify+0x19d/0x770 [ 1011.350562] notifier_call_chain+0x65/0xd0 [ 1011.350562] raw_notifier_call_chain+0x1a/0x20 [ 1011.350562] call_netdevice_notifiers_info+0x54/0x90 [ 1011.350562] register_netdevice+0x61e/0x790 [ 1011.350562] veth_newlink+0x230/0x440 [ 1011.350562] __rtnl_newlink+0x7d2/0xaa0 [ 1011.350562] rtnl_newlink+0x4c/0x70 [ 1011.350562] rtnetlink_rcv_msg+0x155/0x3e0 [ 1011.350562] netlink_rcv_skb+0x61/0x110 [ 1011.350562] rtnetlink_rcv+0x19/0x20 [ 1011.350562] netlink_unicast+0x23f/0x380 [ 1011.350562] netlink_sendmsg+0x1fc/0x430 [ 1011.350562] ____sys_sendmsg+0x2ef/0x320 [ 1011.350562] ___sys_sendmsg+0x86/0xd0 [ 1011.350562]
Quoted 35 lines · Leone Fernando
Quoted 29 lines
In 2017, Paolo Abeni introduced the hinting mechanism [1] to the routing sub-system. The hinting optimization improves performance by reusing previously found dsts instead of looking them up for each skb.
This patch series introduces a generalized version of the hinting mechanism that can "remember" a larger number of dsts. This reduces the number of dst lookups for frequently encountered daddrs.
Before diving into the code and the benchmarking results, it's important to address the deletion of the old route cache [2] and why this solution is different. The original cache was complicated, vulnerable to DOS attacks and had unstable performance.
The new input
dst_cacheis much simpler thanks to its lazy approach, improving performance without the overhead of the removed cache implementation. Instead of using timers and GC, the deletion of invalid entries is performed lazily during their lookups.
The dsts are stored in a simple, lightweight, static hash table. This keeps the lookup times fast yet stable, preventing DOS upon cache misses. The new inputdst_cacheimplementation is built over the existingdst_cachecode which supplies a fast lockless percpu behavior.The measurement setup is comprised of 2 machines with mlx5 100Gbit NIC. I sent small UDP packets with 5000 daddrs (10x of cache size) from one machine to the other while also varying the saddr and the tos. I set an iptables rule to drop the packets after routing. the receiving machine's CPU (i9) was saturated.
Quoted 4 lines
Thanks a lot to David Ahern for all the help and guidance!
I measured the rx PPS using ifpps and the per-queue PPS using ethtool -S. These are the results:
Quoted 8 lines
How device dismantles are taken into account ?
I am currently tracking a bug in
dst_cache, triggering sometimes when runningpmtu.shselftest.Apparently,
dst_cache_per_cpu_dst_set()can cache dst that have nodst->rt_uncached
linkage.
The dst_cache_input that was introduced in this series caches input routes that are owned by the fib tree.
These routes have a rt_uncached linkage. So I think this bug will not replicate to dst_cache_input.
Quoted 87 lines
There is no cleanup (at least in vxlan) to make sure cached dst are either freed or
theirdst->devchanged.TEST: ipv6: cleanup of cached exceptions - nexthop objects [ OK ]
[ 1001.344490] vxlan: __vxlan_fdb_free calling dst_cache_destroy(ffff8f12422cbb90) [ 1001.345253] dst_cache_destroy dst_cache=ffff8f12422cbb90 ->cache=0000417580008d30 [ 1001.378615] vxlan: __vxlan_fdb_free calling dst_cache_destroy(ffff8f12471e31d0) [ 1001.379260] dst_cache_destroy dst_cache=ffff8f12471e31d0 ->cache=0000417580008608 [ 1011.349730] unregister_netdevice: waiting for veth_A-R1 to become free. Usage count = 7 [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] dst_alloc+0x76/0x160 [ 1011.350562] ip6_dst_alloc+0x25/0x80 [ 1011.350562] ip6_pol_route+0x2a8/0x450 [ 1011.350562] ip6_pol_route_output+0x1f/0x30 [ 1011.350562] fib6_rule_lookup+0x163/0x270 [ 1011.350562] ip6_route_output_flags+0xda/0x190 [ 1011.350562] ip6_dst_lookup_tail.constprop.0+0x1d0/0x260 [ 1011.350562] ip6_dst_lookup_flow+0x47/0xa0 [ 1011.350562] udp_tunnel6_dst_lookup+0x158/0x210 [ 1011.350562] vxlan_xmit_one+0x4c6/0x1550 [vxlan] [ 1011.350562] vxlan_xmit+0x535/0x1500 [vxlan] [ 1011.350562] dev_hard_start_xmit+0x7b/0x1e0 [ 1011.350562] __dev_queue_xmit+0x20c/0xe40 [ 1011.350562] arp_xmit+0x1d/0x50 [ 1011.350562] arp_send_dst+0x7f/0xa0 [ 1011.350562] arp_solicit+0xf6/0x2f0 [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 3/6 users at [ 1011.350562] dst_alloc+0x76/0x160 [ 1011.350562] ip6_dst_alloc+0x25/0x80 [ 1011.350562] ip6_pol_route+0x2a8/0x450 [ 1011.350562] ip6_pol_route_output+0x1f/0x30 [ 1011.350562] fib6_rule_lookup+0x163/0x270 [ 1011.350562] ip6_route_output_flags+0xda/0x190 [ 1011.350562] ip6_dst_lookup_tail.constprop.0+0x1d0/0x260 [ 1011.350562] ip6_dst_lookup_flow+0x47/0xa0 [ 1011.350562] udp_tunnel6_dst_lookup+0x158/0x210 [ 1011.350562] vxlan_xmit_one+0x4c6/0x1550 [vxlan] [ 1011.350562] vxlan_xmit+0x535/0x1500 [vxlan] [ 1011.350562] dev_hard_start_xmit+0x7b/0x1e0 [ 1011.350562] __dev_queue_xmit+0x20c/0xe40 [ 1011.350562] ip6_finish_output2+0x2ea/0x6e0 [ 1011.350562] ip6_finish_output+0x143/0x320 [ 1011.350562] ip6_output+0x74/0x140 [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] netdev_get_by_index+0xc0/0xe0 [ 1011.350562] fib6_nh_init+0x1a9/0xa90 [ 1011.350562] rtm_new_nexthop+0x6fa/0x1580 [ 1011.350562] rtnetlink_rcv_msg+0x155/0x3e0 [ 1011.350562] netlink_rcv_skb+0x61/0x110 [ 1011.350562] rtnetlink_rcv+0x19/0x20 [ 1011.350562] netlink_unicast+0x23f/0x380 [ 1011.350562] netlink_sendmsg+0x1fc/0x430 [ 1011.350562] ____sys_sendmsg+0x2ef/0x320 [ 1011.350562] ___sys_sendmsg+0x86/0xd0 [ 1011.350562] __sys_sendmsg+0x67/0xc0 [ 1011.350562] __x64_sys_sendmsg+0x21/0x30 [ 1011.350562] x64_sys_call+0x252/0x2030 [ 1011.350562] do_syscall_64+0x6c/0x190 [ 1011.350562] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 1011.350562] [ 1011.350562] ref_tracker: veth_A-R1@000000009392ed3b has 1/6 users at [ 1011.350562] ipv6_add_dev+0x136/0x530 [ 1011.350562] addrconf_notify+0x19d/0x770 [ 1011.350562] notifier_call_chain+0x65/0xd0 [ 1011.350562] raw_notifier_call_chain+0x1a/0x20 [ 1011.350562] call_netdevice_notifiers_info+0x54/0x90 [ 1011.350562] register_netdevice+0x61e/0x790 [ 1011.350562] veth_newlink+0x230/0x440 [ 1011.350562] __rtnl_newlink+0x7d2/0xaa0 [ 1011.350562] rtnl_newlink+0x4c/0x70 [ 1011.350562] rtnetlink_rcv_msg+0x155/0x3e0 [ 1011.350562] netlink_rcv_skb+0x61/0x110 [ 1011.350562] rtnetlink_rcv+0x19/0x20 [ 1011.350562] netlink_unicast+0x23f/0x380 [ 1011.350562] netlink_sendmsg+0x1fc/0x430 [ 1011.350562] ____sys_sendmsg+0x2ef/0x320 [ 1011.350562] ___sys_sendmsg+0x86/0xd0 [ 1011.350562]