Mitigate the Issue of Expired Routes in Linux IPv6 Routing Tables
Subsystems (3)
v2 cover Mitigate the Issue of Expired Routes in Linux IPv6 Routing Tables
This RFC is resent to ensure maintainers getting awared. Also remove some forward declarations that we don't use anymore.
The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.
For example, years ago, there is a commit about "ICMPv6 Packet too big messages". The root cause is that malicious ICMPv6 packets were sent back for every small packet sent to them. These packets have to lookup/insert a new route, putting hosts under high stress due to contention on a spinlock while one is stuck in fib6_run_gc().
Why Route Expires
=================
Users can add IPv6 routes with an expiration time manually. However, the Neighbor Discovery protocol may also generate routes that can expire. For example, Router Advertisement (RA) messages may create a default route with an expiration time. [RFC 4861] For IPv4, it is not possible to set an expiration time for a route, and there is no RA, so there is no need to worry about such issues.
Create Routes with Expires
==========================
You can create routes with expires with the command.
For example,
ip -6 route add 2001:b000:591::3 via fe80::5054:ff:fe12:3457 \
dev enp0s3 expires 30
The route that has been generated will be deleted automatically in 30 seconds.
GC of FIB6
==========
The function called fib6_run_gc() is responsible for performing garbage collection (GC) for the Linux IPv6 stack. It checks for the expiration of every route by traversing the tries of routing tables. The time taken to traverse a routing table increases with its size. Holding the routing table lock during traversal is particularly undesirable. Therefore, it is preferable to keep the lock for the shortest possible duration.
Solution
========
The cause of the issue is keeping the routing table locked during the traversal of large tries. To address this, the patchset eliminates garbage collection that does the tries traversal and introduces individual timers for each route that eventually expires. Walking trials are no longer necessary with the timers. Additionally, the time required to handle a timer is consistent.
If the expiration time is long, the timer becomes less precise. The drawback is that the longer the expiration time, the less accurate the timer.
Kui-Feng Lee (2):
net: Remove expired routes with separated timers.
net: Remove unused code and variables.
include/net/ip6_fib.h | 21 ++--- include/net/ip6_route.h | 2 - include/net/netns/ipv6.h | 6 -- net/ipv6/addrconf.c | 8 +- net/ipv6/ip6_fib.c | 162 ++++++++++++++++++--------------------- net/ipv6/ndisc.c | 4 +- net/ipv6/route.c | 120 ++--------------------------- 7 files changed, 95 insertions(+), 228 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v2 1/2 net: Remove expired routes with separated timers.
FIB6 GC walks tries of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big. Creating a separated timer for each route that can expire will avoid this potential issue.
--- include/net/ip6_fib.h | 19 ++++------ net/ipv6/addrconf.c | 8 ++-- net/ipv6/ip6_fib.c | 88 ++++++++++++++++++++++++++++++++++++------- net/ipv6/ndisc.c | 2 +- net/ipv6/route.c | 6 +-- 5 files changed, 91 insertions(+), 32 deletions(-)
include/net/ip6_fib.h +8 -11
@@ -161,6 +161,8 @@ struct fib6_nh {struct rt6_exception_bucket __rcu *rt6i_exception_bucket; }; +struct fib6_info_timer ; +struct fib6_info {struct fib6_table *fib6_table;struct fib6_info __rcu *fib6_next;
@@ -179,6 +181,7 @@ struct fib6_info {refcount_t fib6_ref;unsigned long expires; +struct fib6_info_timer *timer;struct dst_metrics *fib6_metrics;#define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1]
@@ -247,18 +250,11 @@ static inline bool fib6_requires_src(const struct fib6_info *rt)return rt->fib6_src.plen >0 ; } -static inline void fib6_clean_expires (struct fib6_info *f6i) -{ - f6i->fib6_flags &= ~RTF_EXPIRES ; - f6i->expires =0 ; -} +void fib6_clean_expires (struct fib6_info *f6i); -static inline void fib6_set_expires (struct fib6_info *f6i, -unsigned long expires) -{ - f6i->expires = expires; - f6i->fib6_flags |=RTF_EXPIRES ; -} +void fib6_set_expires (struct net *net, +struct fib6_info *f6i, +unsigned long expires);static inline bool fib6_check_expired (const struct fib6_info *f6i) {
@@ -388,6 +384,7 @@ struct fib6_table {struct inet_peer_base tb6_peers;unsigned int flags;unsigned int fib_seq; +struct hlist_head tb6_timer_hlist;#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0) };
net/ipv6/addrconf.c +5 -3
@@ -1254,7 +1254,8 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires,ip6_del_rt (dev_net (ifp->idev->dev), f6i, false); else {if (!(f6i->fib6_flags &RTF_EXPIRES )) -fib6_set_expires (f6i, expires); +fib6_set_expires (dev_net (ifp->idev->dev), + f6i, expires);fib6_info_release (f6i); } }
@@ -2762,7 +2763,8 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) rt =NULL ; }else if (addrconf_finite_timeout (rt_expires)) {/* not infinity */ -fib6_set_expires (rt, jiffies + rt_expires); +fib6_set_expires (net, rt, + jiffies + rt_expires); }else {fib6_clean_expires (rt); }
@@ -4723,7 +4725,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp,if (!expires)fib6_clean_expires (f6i);else -fib6_set_expires (f6i, expires); +fib6_set_expires (dev_net (ifp->idev->dev), f6i, expires);fib6_info_release (f6i); }
net/ipv6/ip6_fib.c +74 -14
136 lines not on this page · raw message
net/ipv6/ndisc.c +1 -1
@@ -1407,7 +1407,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) }if (rt) -fib6_set_expires (rt, jiffies + (HZ * lifetime)); +fib6_set_expires (net, rt, jiffies + (HZ * lifetime));if (in6_dev->cnf.accept_ra_min_hop_limit <256 && ra_msg->icmph.icmp6_hop_limit) {if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) {
net/ipv6/route.c +3 -3
@@ -990,7 +990,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,if (!addrconf_finite_timeout (lifetime))fib6_clean_expires (rt);else -fib6_set_expires (rt, jiffies +HZ * lifetime); +fib6_set_expires (net, rt, jiffies +HZ * lifetime);fib6_info_release (rt); }
@@ -3755,8 +3755,8 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg, rt->dst_nocount = true;if (cfg->fc_flags &RTF_EXPIRES ) -fib6_set_expires (rt, jiffies + -clock_t_to_jiffies (cfg->fc_expires)); +fib6_set_expires (net, rt, jiffies + +clock_t_to_jiffies (cfg->fc_expires));else fib6_clean_expires (rt);
Signature · 1 line
2.34.1
David Ahern
maintainerRe: [RFC PATCH net-next v2 1/2] net: Remove expired routes with separated timers.
include/net/ip6_fib.h struct fib6_info { · line 184
Quoted 5 lines · Kui-Feng Lee
include/net/ip6_fib.h +1
-0@@ -179,6 +181,7 @@ struct fib6_info {refcount_t fib6_ref;unsigned long expires; +struct fib6_info_timer *timer;
if this solution moves forward as a separate timer per route with an expiration, the timer related info can be added inline. Current fib6_info with a single nexthop is 264B so it is already rounded up to 512B on the allocation.
RFC PATCH v2 2/2 net: Remove unused code and variables.
In reply to Kui-Feng LeeSince GC has been removed, some functions and variables are useless. That includes some sysctl variables that control GC.
--- include/net/ip6_fib.h | 2 - include/net/ip6_route.h | 2 - include/net/netns/ipv6.h | 6 --- net/ipv6/ip6_fib.c | 74 ------------------------- net/ipv6/ndisc.c | 2 - net/ipv6/route.c | 114 ++------------------------------------- 6 files changed, 4 insertions(+), 196 deletions(-)
include/net/ip6_fib.h +0 -2
@@ -495,8 +495,6 @@ void fib6_rt_update(struct net *net, struct fib6_info *rt,void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info,unsigned int flags); -void fib6_run_gc (unsigned long expires,struct net *net,bool force); -void fib6_gc_cleanup (void );int fib6_init (void );
include/net/ip6_route.h +0 -2
@@ -152,8 +152,6 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,struct dst_entry *icmp6_dst_alloc (struct net_device *dev,struct flowi6 *fl6); -void fib6_force_start_gc (struct net *net); -struct fib6_info *addrconf_f6i_alloc (struct net *net,struct inet6_dev *idev,const struct in6_addr *addr,bool anycast,gfp_t gfp_flags);
include/net/netns/ipv6.h +0 -6
@@ -20,12 +20,8 @@ struct netns_sysctl_ipv6 {struct ctl_table_header *frags_hdr;struct ctl_table_header *xfrm6_hdr;#endif -int flush_delay;int ip6_rt_max_size; -int ip6_rt_gc_min_interval; -int ip6_rt_gc_timeout;int ip6_rt_gc_interval; -int ip6_rt_gc_elasticity;int ip6_rt_mtu_expires;int ip6_rt_min_advmss;u32 multipath_hash_fields;
@@ -70,14 +66,12 @@ struct netns_ipv6 {struct fib6_info *fib6_null_entry;struct rt6_info *ip6_null_entry;struct rt6_statistics *rt6_stats; -struct timer_list ip6_fib_timer;struct hlist_head *fib_table_hash;struct fib6_table *fib6_main_tbl;struct list_head fib6_walkers;rwlock_t fib6_walker_lock;spinlock_t fib6_gc_lock;atomic_t ip6_rt_gc_expire; -unsigned long ip6_rt_last_gc;unsigned char flowlabel_has_excl;#ifdef CONFIG_IPV6_MULTIPLE_TABLES bool fib6_has_custom_rules;
net/ipv6/ip6_fib.c +0 -74
110 lines not on this page · raw message
net/ipv6/ndisc.c +0 -2
@@ -1869,7 +1869,6 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event,switch (event) {case NETDEV_CHANGEADDR :neigh_changeaddr (&nd_tbl, dev); -fib6_run_gc (0 , net, false); fallthrough;case NETDEV_UP : idev =in6_dev_get (dev);
@@ -1898,7 +1897,6 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event,break ;case NETDEV_DOWN :neigh_ifdown (&nd_tbl, dev); -fib6_run_gc (0 , net, false);break ;case NETDEV_NOTIFY_PEERS :ndisc_send_unsol_na (dev);
net/ipv6/route.c +4 -110
169 lines not on this page · raw message
Signature · 1 line
2.34.1
David Ahern
maintainerQuoted 8 lines · Kui-Feng Lee
This RFC is resent to ensure maintainers getting awared. Also remove some forward declarations that we don't use anymore.
The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.
I take it this problem was seen internally to your org? Can you give representative numbers on how many routes, stats on the blocked time, and reason for the large time block (I am guessing the notifier)?
Quoted 46 lines
For example, years ago, there is a commit about "ICMPv6 Packet too big messages". The root cause is that malicious ICMPv6 packets were sent back for every small packet sent to them. These packets have to lookup/insert a new route, putting hosts under high stress due to contention on a spinlock while one is stuck in
fib6_run_gc().Why Route Expires
=================Users can add IPv6 routes with an expiration time manually. However, the Neighbor Discovery protocol may also generate routes that can expire. For example, Router Advertisement (RA) messages may create a default route with an expiration time. [RFC 4861] For IPv4, it is not possible to set an expiration time for a route, and there is no RA, so there is no need to worry about such issues.
Create Routes with Expires
==========================You can create routes with expires with the command.
For example,
ip -6 route add 2001:b000:591::3 via fe80::5054:ff:fe12:3457 \
dev enp0s3 expires 30The route that has been generated will be deleted automatically in 30 seconds.
GC of FIB6
==========The function called
fib6_run_gc()is responsible for performing garbage collection (GC) for the Linux IPv6 stack. It checks for the expiration of every route by traversing the tries of routing tables. The time taken to traverse a routing table increases with its size. Holding the routing table lock during traversal is particularly undesirable. Therefore, it is preferable to keep the lock for the shortest possible duration.Solution
========
Quoted 6 lines
The cause of the issue is keeping the routing table locked during the traversal of large tries. To address this, the patchset eliminates garbage collection that does the tries traversal and introduces individual timers for each route that eventually expires. Walking trials are no longer necessary with the timers. Additionally, the time required to handle a timer is consistent.
And then for the number of routes mentioned above what does that mean for having a timer per route? If this is 10's or 100's of 1000s of expired routes what does that mean for the timer subsystem dealing with that number of entries on top of other timers and the impact on the timer softirq? ie., are you just moving the problem around.
did you consider other solutions? e.g., if it is the notifier, then perhaps the entries can be deleted from the fib and then put into a list for cleanup in a worker thread.
Quoted 18 lines
If the expiration time is long, the timer becomes less precise. The drawback is that the longer the expiration time, the less accurate the timer.
Kui-Feng Lee (2):
net: Remove expired routes with separated timers.
net: Remove unused code and variables.include/net/ip6_fib.h | 21 ++--- include/net/ip6_route.h | 2 - include/net/netns/ipv6.h | 6 -- net/ipv6/addrconf.c | 8 +- net/ipv6/ip6_fib.c | 162 ++++++++++++++++++--------------------- net/ipv6/ndisc.c | 4 +- net/ipv6/route.c | 120 ++--------------------------- 7 files changed, 95 insertions(+), 228 deletions(-)
Quoted 10 lines · David Ahern
Quoted 8 lines · Kui-Feng Lee
This RFC is resent to ensure maintainers getting awared. Also remove some forward declarations that we don't use anymore.
The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.
Quoted 3 lines
I take it this problem was seen internally to your org? Can you give representative numbers on how many routes, stats on the blocked time, and reason for the large time block (I am guessing the notifier)?
We don't have existing incidents so far. Consider it as a potential issue.
Quoted 54 lines
Quoted 47 lines
For example, years ago, there is a commit about "ICMPv6 Packet too big messages". The root cause is that malicious ICMPv6 packets were sent back for every small packet sent to them. These packets have to lookup/insert a new route, putting hosts under high stress due to contention on a spinlock while one is stuck in
fib6_run_gc().Why Route Expires
=================Users can add IPv6 routes with an expiration time manually. However, the Neighbor Discovery protocol may also generate routes that can expire. For example, Router Advertisement (RA) messages may create a default route with an expiration time. [RFC 4861] For IPv4, it is not possible to set an expiration time for a route, and there is no RA, so there is no need to worry about such issues.
Create Routes with Expires
==========================You can create routes with expires with the command.
For example,
ip -6 route add 2001:b000:591::3 via fe80::5054:ff:fe12:3457 \
dev enp0s3 expires 30The route that has been generated will be deleted automatically in 30 seconds.
GC of FIB6
==========The function called
fib6_run_gc()is responsible for performing garbage collection (GC) for the Linux IPv6 stack. It checks for the expiration of every route by traversing the tries of routing tables. The time taken to traverse a routing table increases with its size. Holding the routing table lock during traversal is particularly undesirable. Therefore, it is preferable to keep the lock for the shortest possible duration.Solution
========Quoted 6 lines
The cause of the issue is keeping the routing table locked during the traversal of large tries. To address this, the patchset eliminates garbage collection that does the tries traversal and introduces individual timers for each route that eventually expires. Walking trials are no longer necessary with the timers. Additionally, the time required to handle a timer is consistent.
Quoted 5 lines
And then for the number of routes mentioned above what does that mean for having a timer per route? If this is 10's or 100's of 1000s of expired routes what does that mean for the timer subsystem dealing with that number of entries on top of other timers and the impact on the timer softirq? ie., are you just moving the problem around.
Yes, each expired route has a timer. But, not all routes have expire times. The timer subsystem will handle every single one. Let me address the timer subsystem later.
Quoted 4 lines
did you consider other solutions? e.g., if it is the notifier, then perhaps the entries can be deleted from the fib and then put into a list for cleanup in a worker thread.
Yes, I considered to keep a separated list of routes that is expiring, just like what neighbor tables do. However, we need to sort them in the order of expire times. Other solutions can be a RB-tree or priority queues. However, later, I went to the timers solution suggested by Martin Lau.
If I read it correctly, the timer subsystem handles each timer with a constant time. It puts timers into buckets and levels. Every level means different granularity. For example, it has granularity of 1ms, 8ms (level 0), 64ms, 512ms, ... up to 4 hours (level 8) for 1000Hz. Each level (granularity) has 64 buckets. Every bucket represent a time slot. That means level 0 holds timers that is expiring in 0ms~63ms in its 64 buckets, level 1 holds timers that is expiring in 64ms~511ms, ... so on. What the timer subsystem does is to emit every timers in the corresponding current buckets of every level. In other word, it checks the current bucket from level 0 ~ level 8, and emit timers if there is any timer in the buckets.
In contrast, the current GC has to walk every tree even only one route expired. Timers is far better. It emits every timer in the buckets associated with current time, no search needed. The current GC is triggered by a timer as well. So, it should reduce the computation of the timer softirq.
However, just like what I mentioned earlier, the drawback of timers are its granularity can vary. The longer expiration time means more coarse- grained. But, it probably is not a big issue.
Quoted 21 lines
Quoted 19 lines
If the expiration time is long, the timer becomes less precise. The drawback is that the longer the expiration time, the less accurate the timer.
Kui-Feng Lee (2):
net: Remove expired routes with separated timers.
net: Remove unused code and variables.include/net/ip6_fib.h | 21 ++--- include/net/ip6_route.h | 2 - include/net/netns/ipv6.h | 6 -- net/ipv6/addrconf.c | 8 +- net/ipv6/ip6_fib.c | 162 ++++++++++++++++++--------------------- net/ipv6/ndisc.c | 4 +- net/ipv6/route.c | 120 ++--------------------------- 7 files changed, 95 insertions(+), 228 deletions(-)
David Ahern
maintainerQuoted 13 lines · Kui-Feng Lee
Quoted 10 lines · David Ahern
Quoted 8 lines · Kui-Feng Lee
This RFC is resent to ensure maintainers getting awared. Also remove some forward declarations that we don't use anymore.
The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.
Quoted 6 lines
Quoted 3 lines
I take it this problem was seen internally to your org? Can you give representative numbers on how many routes, stats on the blocked time, and reason for the large time block (I am guessing the notifier)?
We don't have existing incidents so far. Consider it as a potential issue.
So no data to compare how the system was operating before and after.
...
Quoted 3 lines
In contrast, the current GC has to walk every tree even only one route expired.
As I recall the largest overhead is systems (e.g., switchdev) handling the notifier. The tree walk scaling problem can be addressed with a much simpler change -- e.g., add a list_head per fib6_table for fib6_info entries that can expire and make the list time sorted. Then the gc only needs to walk those lists up to the expired point.
Quoted 14 lines · David Ahern
Quoted 13 lines · Kui-Feng Lee
Quoted 10 lines · David Ahern
Quoted 8 lines · Kui-Feng Lee
This RFC is resent to ensure maintainers getting awared. Also remove some forward declarations that we don't use anymore.
The size of a Linux IPv6 routing table can become a big problem if not managed appropriately. Now, Linux has a garbage collector to remove expired routes periodically. However, this may lead to a situation in which the routing path is blocked for a long period due to an excessive number of routes.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I take it this problem was seen internally to your org? Can you give representative numbers on how many routes, stats on the blocked time, and reason for the large time block (I am guessing the notifier)?
We don't have existing incidents so far. Consider it as a potential issue.
So no data to compare how the system was operating before and after.
I can generate traffic to test it.
Quoted 4 lines
...
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
In contrast, the current GC has to walk every tree even only one route expired.
As I recall the largest overhead is systems (e.g., switchdev) handling the notifier. The tree walk scaling problem can be addressed with a much simpler change -- e.g., add a
list_headperfib6_tableforfib6_infoentries that can expire and make the list time sorted. Then the gc only needs to walk those lists up to the expired point.
This is one of solutions I considered at beginning.
With this approach, we can have a maximum
number of entries like what neighbor tables do.
Remove entries only if the list reach the maximum without running a GC timer. However, it can be very inefficient to insert a new entry ordered. Stephen mentioned 3 million routes on backbone router in another message. We may need something more complicated like RB-tree or HEAP to reduce the overhead.
David Ahern
maintainerQuoted 8 lines · Kui-Feng Lee
This is one of solutions I considered at beginning.
With this approach, we can have a maximum
number of entries like what neighbor tables do.
Remove entries only if the list reach the maximum without running a GC timer. However, it can be very inefficient to insert a new entry ordered. Stephen mentioned 3 million routes on backbone router in another message. We may need something more complicated like RB-tree or HEAP to reduce the overhead.
I do not believe so. Not every route will have an expiration timer. Only those are added to the new, time ordered list_head.
And you can not cap the number of entries in a FIB.
Quoted 50 lines · On Wed, 17 May 2023 22:40:08 -0700 Kui-Feng Lee <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines
Solution
========The cause of the issue is keeping the routing table locked during the traversal of large tries. To address this, the patchset eliminates garbage collection that does the tries traversal and introduces individual timers for each route that eventually expires. Walking trials are no longer necessary with the timers. Additionally, the time required to handle a timer is consistent.
Quoted 5 lines
And then for the number of routes mentioned above what does that mean for having a timer per route? If this is 10's or 100's of 1000s of expired routes what does that mean for the timer subsystem dealing with that number of entries on top of other timers and the impact on the timer softirq? ie., are you just moving the problem around.
Yes, each expired route has a timer. But, not all routes have expire times. The timer subsystem will handle every single one. Let me address the timer subsystem later.
Quoted 4 lines
did you consider other solutions? e.g., if it is the notifier, then perhaps the entries can be deleted from the fib and then put into a list for cleanup in a worker thread.
Yes, I considered to keep a separated list of routes that is expiring, just like what neighbor tables do. However, we need to sort them in the order of expire times. Other solutions can be a RB-tree or priority queues. However, later, I went to the timers solution suggested by Martin Lau.
If I read it correctly, the timer subsystem handles each timer with a constant time. It puts timers into buckets and levels. Every level means different granularity. For example, it has granularity of 1ms, 8ms (level 0), 64ms, 512ms, ... up to 4 hours (level 8) for 1000Hz. Each level (granularity) has 64 buckets. Every bucket represent a time slot. That means level 0 holds timers that is expiring in 0ms~63ms in its 64 buckets, level 1 holds timers that is expiring in 64ms~511ms, ... so on. What the timer subsystem does is to emit every timers in the corresponding current buckets of every level. In other word, it checks the current bucket from level 0 ~ level 8, and emit timers if there is any timer in the buckets.
In contrast, the current GC has to walk every tree even only one route expired. Timers is far better. It emits every timer in the buckets associated with current time, no search needed. The current GC is triggered by a timer as well. So, it should reduce the computation of the timer softirq.
Quoted 3 lines
However, just like what I mentioned earlier, the drawback of timers are its granularity can vary. The longer expiration time means more coarse- grained. But, it probably is not a big issue.
If Linux is used on backbone router it can easily have 3 million routes to deal with. That won't make timer subsystem happy.
Quoted 53 lines · Stephen Hemminger
Quoted 50 lines · On Wed, 17 May 2023 22:40:08 -0700 Kui-Feng Lee <[email protected]> wrote:
Quoted 10 lines
Quoted 9 lines
Solution
========The cause of the issue is keeping the routing table locked during the traversal of large tries. To address this, the patchset eliminates garbage collection that does the tries traversal and introduces individual timers for each route that eventually expires. Walking trials are no longer necessary with the timers. Additionally, the time required to handle a timer is consistent.
Quoted 5 lines
And then for the number of routes mentioned above what does that mean for having a timer per route? If this is 10's or 100's of 1000s of expired routes what does that mean for the timer subsystem dealing with that number of entries on top of other timers and the impact on the timer softirq? ie., are you just moving the problem around.
Yes, each expired route has a timer. But, not all routes have expire times. The timer subsystem will handle every single one. Let me address the timer subsystem later.
Quoted 4 lines
did you consider other solutions? e.g., if it is the notifier, then perhaps the entries can be deleted from the fib and then put into a list for cleanup in a worker thread.
Yes, I considered to keep a separated list of routes that is expiring, just like what neighbor tables do. However, we need to sort them in the order of expire times. Other solutions can be a RB-tree or priority queues. However, later, I went to the timers solution suggested by Martin Lau.
If I read it correctly, the timer subsystem handles each timer with a constant time. It puts timers into buckets and levels. Every level means different granularity. For example, it has granularity of 1ms, 8ms (level 0), 64ms, 512ms, ... up to 4 hours (level 8) for 1000Hz. Each level (granularity) has 64 buckets. Every bucket represent a time slot. That means level 0 holds timers that is expiring in 0ms~63ms in its 64 buckets, level 1 holds timers that is expiring in 64ms~511ms, ... so on. What the timer subsystem does is to emit every timers in the corresponding current buckets of every level. In other word, it checks the current bucket from level 0 ~ level 8, and emit timers if there is any timer in the buckets.
In contrast, the current GC has to walk every tree even only one route expired. Timers is far better. It emits every timer in the buckets associated with current time, no search needed. The current GC is triggered by a timer as well. So, it should reduce the computation of the timer softirq.
Quoted 6 lines
Quoted 3 lines
However, just like what I mentioned earlier, the drawback of timers are its granularity can vary. The longer expiration time means more coarse- grained. But, it probably is not a big issue.
If Linux is used on backbone router it can easily have 3 million routes to deal with. That won't make timer subsystem happy.
I will run experiments to get numbers to see how the compact actually is.