ipv6: prevent fib6_run_gc() contention
Subsystems (3)
PATCH 1/1 ipv6: prevent fib6_run_gc() contention
On a high-traffic router with many processors and many IPv6 dst entries, soft lockup in fib6_run_gc() can occur when number of entries reaches gc_thresh.
This happens because fib6_run_gc() uses fib6_gc_lock to allow only one thread to run the garbage collector but ip6_dst_gc() doesn't update net->ipv6.ip6_rt_last_gc until fib6_run_gc() returns. On a system with many entries, this can take some time so that in the meantime, other threads pass the tests in ip6_dst_gc() (ip6_rt_last_gc is still not updated) and wait for the lock. They then have to run the garbage collector one after another which blocks them for quite long.
Resolve this by replacing special value ~0UL of expire parameter to fib6_run_gc() by explicit "force" parameter to choose between spin_lock_bh() and spin_trylock_bh() and call fib6_run_gc() with force=false if gc_thresh is reached but not max_size.
--- include/net/ip6_fib.h | 2 +- net/ipv6/ip6_fib.c | 19 ++++++++----------- net/ipv6/ndisc.c | 4 ++-- net/ipv6/route.c | 4 ++-- 4 files changed, 13 insertions(+), 16 deletions(-)
include/net/ip6_fib.h +1 -1
@@ -300,7 +300,7 @@ extern void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info);extern void fib6_run_gc (unsigned long expires, -struct net *net); +struct net *net,bool force);extern void fib6_gc_cleanup (void );
net/ipv6/ip6_fib.c +8 -11
@@ -1625,19 +1625,16 @@ static int fib6_age(struct rt6_info *rt, void *arg)static DEFINE_SPINLOCK (fib6_gc_lock); -void fib6_run_gc (unsigned long expires,struct net *net) +void fib6_run_gc (unsigned long expires,struct net *net,bool force) { -if (expires != ~0UL ) { +if (force)spin_lock_bh (&fib6_gc_lock); - gc_args.timeout = expires ? (int )expires : - net->ipv6.sysctl.ip6_rt_gc_interval; - }else { -if (!spin_trylock_bh (&fib6_gc_lock)) { -mod_timer (&net->ipv6.ip6_fib_timer, jiffies +HZ ); -return ; - } - gc_args.timeout = net->ipv6.sysctl.ip6_rt_gc_interval; +else if (!spin_trylock_bh (&fib6_gc_lock)) { +mod_timer (&net->ipv6.ip6_fib_timer, jiffies +HZ ); +return ; } + gc_args.timeout = expires ? (int )expires : + net->ipv6.sysctl.ip6_rt_gc_interval; gc_args.more =icmp6_dst_gc ();
@@ -1654,7 +1651,7 @@ void fib6_run_gc(unsigned long expires, struct net *net)static void fib6_gc_timer_cb (unsigned long arg) { -fib6_run_gc (0 , (struct net *)arg); +fib6_run_gc (0 , (struct net *)arg, true); }static int __net_init fib6_net_init (struct net *net)
net/ipv6/ndisc.c +2 -2
@@ -1575,7 +1575,7 @@ 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 (~0UL , net); +fib6_run_gc (0 , net, false); idev =in6_dev_get (dev);if (!idev)break ;
@@ -1585,7 +1585,7 @@ static int ndisc_netdev_event(struct notifier_block *this, unsigned long event,break ;case NETDEV_DOWN :neigh_ifdown (&nd_tbl, dev); -fib6_run_gc (~0UL , net); +fib6_run_gc (0 , net, false);break ;case NETDEV_NOTIFY_PEERS :ndisc_send_unsol_na (dev);
net/ipv6/route.c +2 -2
@@ -1300,7 +1300,7 @@ static int ip6_dst_gc(struct dst_ops *ops) goto out; net->ipv6.ip6_rt_gc_expire++; -fib6_run_gc (net->ipv6.ip6_rt_gc_expire, net); +fib6_run_gc (net->ipv6.ip6_rt_gc_expire, net, entries > rt_max_size); net->ipv6.ip6_rt_last_gc = now; entries =dst_entries_get_slow (ops);if (entries < ops->gc_thresh)
@@ -2801,7 +2801,7 @@ int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write, net = (struct net *)ctl->extra1; delay = net->ipv6.sysctl.flush_delay;proc_dointvec (ctl, write, buffer, lenp, ppos); -fib6_run_gc (delay <=0 ? ~0UL : (unsigned long )delay, net); +fib6_run_gc (delay <=0 ?0 : (unsigned long )delay, net, delay >0 );return 0 ; }
Signature · 1 line
1.8.1.4
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Tue, 4 Jun 2013 13:08:59 +0200
Quoted 13 lines
On a high-traffic router with many processors and many IPv6 dst entries, soft lockup in
fib6_run_gc()can occur when number of entries reachesgc_thresh.This happens because
fib6_run_gc()usesfib6_gc_lockto allow only one thread to run the garbage collector butip6_dst_gc()doesn't updatenet->ipv6.ip6_rt_last_gcuntilfib6_run_gc()returns. On a system with many entries, this can take some time so that in the meantime, other threads pass the tests inip6_dst_gc()(ip6_rt_last_gcis still not updated) and wait for the lock. They then have to run the garbage collector one after another which blocks them for quite long.
Quoted 6 lines
Resolve this by replacing special value ~0UL of expire parameter to
fib6_run_gc()by explicit "force" parameter to choose betweenspin_lock_bh()andspin_trylock_bh()and callfib6_run_gc()with force=false ifgc_threshis reached but notmax_size.Signed-off-by Michal Kubecek <[email protected]>
It seems to me that it would be much simpler to simply update ip6_rt_last_gc first, that way the other threads would elide the GC call.
Can you see if simply doing that fixes the problem too?
Thanks.
Quoted 21 lines · David Miller
From: Michal Kubecek <[email protected]>
Date: Tue, 4 Jun 2013 13:08:59 +0200Quoted 18 lines
On a high-traffic router with many processors and many IPv6 dst entries, soft lockup in
fib6_run_gc()can occur when number of entries reachesgc_thresh.This happens because
fib6_run_gc()usesfib6_gc_lockto allow only one thread to run the garbage collector butip6_dst_gc()doesn't updatenet->ipv6.ip6_rt_last_gcuntilfib6_run_gc()returns. On a system with many entries, this can take some time so that in the meantime, other threads pass the tests inip6_dst_gc()(ip6_rt_last_gcis still not updated) and wait for the lock. They then have to run the garbage collector one after another which blocks them for quite long.Resolve this by replacing special value ~0UL of expire parameter to
fib6_run_gc()by explicit "force" parameter to choose betweenspin_lock_bh()andspin_trylock_bh()and callfib6_run_gc()with force=false ifgc_threshis reached but notmax_size.
Quoted 5 lines
Quoted 1 line
Signed-off-by Michal Kubecek <[email protected]>It seems to me that it would be much simpler to simply update
ip6_rt_last_gcfirst, that way the other threads would elide the GC call.
That was my original idea but I was afraid that while the remaining window in ip6_dst_gc() would be very short and probably safe, we could still run into problem if fib6_gc_lock was locked by some other caller of fib6_run_gc() which doesn't update net->ipv6.ip6_rt_last_gc, especially via a timer.
Michal Kubecek
Quoted 5 lines · Michal Kubecek
That was my original idea but I was afraid that while the remaining window in
ip6_dst_gc()would be very short and probably safe, we could still run into problem iffib6_gc_lockwas locked by some other caller offib6_run_gc()which doesn't updatenet->ipv6.ip6_rt_last_gc, especially via a timer.
This looks a bug (but not a big one) to me :
We should update ip6_rt_last_gc if we did a gc,
not only from ip6_dst_gc()
So, I would move the "net->ipv6.ip6_rt_last_gc = now;" from ip6_dst_gc() to fib6_run_gc(), right after the spin_lock_bh() ?
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 12:07:18 +0200
Quoted 28 lines · David Miller
Quoted 21 lines
From: Michal Kubecek <[email protected]>
Date: Tue, 4 Jun 2013 13:08:59 +0200Quoted 18 lines
On a high-traffic router with many processors and many IPv6 dst entries, soft lockup in
fib6_run_gc()can occur when number of entries reachesgc_thresh.This happens because
fib6_run_gc()usesfib6_gc_lockto allow only one thread to run the garbage collector butip6_dst_gc()doesn't updatenet->ipv6.ip6_rt_last_gcuntilfib6_run_gc()returns. On a system with many entries, this can take some time so that in the meantime, other threads pass the tests inip6_dst_gc()(ip6_rt_last_gcis still not updated) and wait for the lock. They then have to run the garbage collector one after another which blocks them for quite long.Resolve this by replacing special value ~0UL of expire parameter to
fib6_run_gc()by explicit "force" parameter to choose betweenspin_lock_bh()andspin_trylock_bh()and callfib6_run_gc()with force=false ifgc_threshis reached but notmax_size.Quoted 5 lines
Quoted 1 line
Signed-off-by Michal Kubecek <[email protected]>It seems to me that it would be much simpler to simply update
ip6_rt_last_gcfirst, that way the other threads would elide the GC call.
Quoted 5 lines
That was my original idea but I was afraid that while the remaining window in
ip6_dst_gc()would be very short and probably safe, we could still run into problem iffib6_gc_lockwas locked by some other caller offib6_run_gc()which doesn't updatenet->ipv6.ip6_rt_last_gc, especially via a timer.
Why don't you simply try it and find out?
Quoted 9 lines · David Miller
From: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 12:07:18 +0200Quoted 6 lines · David Miller
Quoted 4 lines
It seems to me that it would be much simpler to simply update
ip6_rt_last_gcfirst, that way the other threads would elide the GC call.
Quoted 7 lines
Quoted 5 lines
That was my original idea but I was afraid that while the remaining window in
ip6_dst_gc()would be very short and probably safe, we could still run into problem iffib6_gc_lockwas locked by some other caller offib6_run_gc()which doesn't updatenet->ipv6.ip6_rt_last_gc, especially via a timer.Why don't you simply try it and find out?
I don't have the system where the issue was observed at hand. I'll have to ask the customer who reported it to run the test so that it may take some time.
Michal Kubecek
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 22:49:12 +0200
Quoted 16 lines · David Miller
Quoted 15 lines
From: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 12:07:18 +0200Quoted 11 lines · David Miller
Quoted 4 lines
It seems to me that it would be much simpler to simply update
ip6_rt_last_gcfirst, that way the other threads would elide the GC call.That was my original idea but I was afraid that while the remaining window in
ip6_dst_gc()would be very short and probably safe, we could still run into problem iffib6_gc_lockwas locked by some other caller offib6_run_gc()which doesn't updatenet->ipv6.ip6_rt_last_gc, especially via a timer.
Quoted 5 lines
Quoted 1 line
Why don't you simply try it and find out?
I don't have the system where the issue was observed at hand. I'll have to ask the customer who reported it to run the test so that it may take some time.
Please also take care of the issue Eric mentioned, in that some GC calls erroneously do not update the last GC timestamp.
Quoted 19 lines · David Miller
From: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 22:49:12 +0200Quoted 16 lines · David Miller
Quoted 15 lines
From: Michal Kubecek <[email protected]>
Date: Tue, 11 Jun 2013 12:07:18 +0200Quoted 11 lines · David Miller
Quoted 4 lines
It seems to me that it would be much simpler to simply update
ip6_rt_last_gcfirst, that way the other threads would elide the GC call.That was my original idea but I was afraid that while the remaining window in
ip6_dst_gc()would be very short and probably safe, we could still run into problem iffib6_gc_lockwas locked by some other caller offib6_run_gc()which doesn't updatenet->ipv6.ip6_rt_last_gc, especially via a timer.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Why don't you simply try it and find out?
I don't have the system where the issue was observed at hand. I'll have to ask the customer who reported it to run the test so that it may take some time.
Please also take care of the issue Eric mentioned, in that some GC calls erroneously do not update the last GC timestamp.
I received the feedback today. The customer reported the patch moving update of ip6_rt_last_gc into fib6_run_gc() before the call of fib6_clean_all() was not sufficient to prevent the contention with their workload.
So I suggest to return back to the approach I submitted originally but to move the update into fib6_run_gc() anyway so that every run of the garbage collector updates it. I will submit the patches tomorrow.
Michal Kubecek
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Thu, 1 Aug 2013 00:19:31 +0200
Quoted 8 lines
I received the feedback today. The customer reported the patch moving update of
ip6_rt_last_gcintofib6_run_gc()before the call offib6_clean_all()was not sufficient to prevent the contention with their workload.So I suggest to return back to the approach I submitted originally but to move the update into
fib6_run_gc()anyway so that every run of the garbage collector updates it. I will submit the patches tomorrow.
Fair enough.