nexthop: Fix performance regression in nexthop deletion
Subsystems (3)
PATCH 1/1 nexthop: Fix performance regression in nexthop deletion
From: Ido Schimmel <[email protected]>
While insertion of 16k nexthops all using the same netdev ('dummy10') takes less than a second, deletion takes about 130 seconds:
# time -p ip -b nexthop.batch real 0.29 user 0.01 sys 0.15
# time -p ip link set dev dummy10 down real 131.03 user 0.06 sys 0.52
This is because of repeated calls to synchronize_rcu() whenever a nexthop is removed from a nexthop group:
# /usr/share/bcc/tools/offcputime -p `pgrep -nx ip` -K
...
b'finish_task_switch'
b'schedule'
b'schedule_timeout'
b'wait_for_completion'
b'__wait_rcu_gp'
b'synchronize_rcu.part.0'
b'synchronize_rcu'
b'__remove_nexthop'
b'remove_nexthop'
b'nexthop_flush_dev'
b'nh_netdev_event'
b'raw_notifier_call_chain'
b'call_netdevice_notifiers_info'
b'__dev_notify_flags'
b'dev_change_flags'
b'do_setlink'
b'__rtnl_newlink'
b'rtnl_newlink'
b'rtnetlink_rcv_msg'
b'netlink_rcv_skb'
b'rtnetlink_rcv'
b'netlink_unicast'
b'netlink_sendmsg'
b'____sys_sendmsg'
b'___sys_sendmsg'
b'__sys_sendmsg'
b'__x64_sys_sendmsg'
b'do_syscall_64'
b'entry_SYSCALL_64_after_hwframe'
- ip (277)
126554955Since nexthops are always deleted under RTNL, synchronize_net() can be used instead. It will call synchronize_rcu_expedited() which only blocks for several microseconds as opposed to multiple milliseconds like synchronize_rcu().
With this patch deletion of 16k nexthops takes less than a second:
# time -p ip link set dev dummy10 down real 0.12 user 0.00 sys 0.04
Tested with fib_nexthops.sh which includes torture tests that prompted the initial change:
# ./fib_nexthops.sh ... Tests passed: 134 Tests failed: 0
--- net/ipv4/nexthop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +1 -1
@@ -845,7 +845,7 @@ static void remove_nexthop_from_groups(struct net *net, struct nexthop *nh,remove_nh_grp_entry (net, nhge, nlinfo);/* make sure all see the newly published array before releasing rtnl */ -synchronize_rcu (); +synchronize_net (); }static void remove_nexthop_group (struct nexthop *nh,struct nl_info *nlinfo)
Signature · 1 line
2.26.2
Quoted 14 lines · Ido Schimmel
From: Ido Schimmel <[email protected]>
While insertion of 16k nexthops all using the same netdev ('dummy10') takes less than a second, deletion takes about 130 seconds:
# time -p ip -b nexthop.batch real 0.29 user 0.01 sys 0.15# time -p ip link set dev dummy10 down real 131.03 user 0.06 sys 0.52
snip...
Quoted 11 lines
Since nexthops are always deleted under RTNL,
synchronize_net()can be used instead. It will callsynchronize_rcu_expedited()which only blocks for several microseconds as opposed to multiple milliseconds likesynchronize_rcu().With this patch deletion of 16k nexthops takes less than a second:
# time -p ip link set dev dummy10 down real 0.12 user 0.00 sys 0.04
That's a nice result! Well done! I can't really speak to whether or not there is any horrible side effect of using synchronize_rcu_expedited(), but FWIW:
Quoted 11 lines
Tested with
fib_nexthops.shwhich includes torture tests that prompted the initial change:# ./fib_nexthops.sh ... Tests passed: 134 Tests failed: 0Fixes 90f33bffa382 ("nexthops: don't modify published nexthop groups")Signed-off-by Ido Schimmel <[email protected]>
Nice fix, good commit message, thanks!
Quoted 17 lines
--- net/ipv4/nexthop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/nexthop.c +1
-1@@ -845,7 +845,7 @@ static void remove_nexthop_from_groups(struct net *net, struct nexthop *nh,remove_nh_grp_entry (net, nhge, nlinfo);/* make sure all see the newly published array before releasing rtnl */ -synchronize_rcu (); +synchronize_net (); }static void remove_nexthop_group (struct nexthop *nh,struct nl_info *nlinfo)
Quoted 72 lines · Ido Schimmel
From: Ido Schimmel <[email protected]>
While insertion of 16k nexthops all using the same netdev ('dummy10') takes less than a second, deletion takes about 130 seconds:
# time -p ip -b nexthop.batch real 0.29 user 0.01 sys 0.15# time -p ip link set dev dummy10 down real 131.03 user 0.06 sys 0.52This is because of repeated calls to
synchronize_rcu()whenever a nexthop is removed from a nexthop group:# /usr/share/bcc/tools/offcputime -p `pgrep -nx ip` -K ... b'finish_task_switch' b'schedule' b'schedule_timeout' b'wait_for_completion' b'__wait_rcu_gp' b'synchronize_rcu.part.0' b'synchronize_rcu' b'__remove_nexthop' b'remove_nexthop' b'nexthop_flush_dev' b'nh_netdev_event' b'raw_notifier_call_chain' b'call_netdevice_notifiers_info' b'__dev_notify_flags' b'dev_change_flags' b'do_setlink' b'__rtnl_newlink' b'rtnl_newlink' b'rtnetlink_rcv_msg' b'netlink_rcv_skb' b'rtnetlink_rcv' b'netlink_unicast' b'netlink_sendmsg' b'____sys_sendmsg' b'___sys_sendmsg' b'__sys_sendmsg' b'__x64_sys_sendmsg' b'do_syscall_64' b'entry_SYSCALL_64_after_hwframe' - ip (277) 126554955Since nexthops are always deleted under RTNL,
synchronize_net()can be used instead. It will callsynchronize_rcu_expedited()which only blocks for several microseconds as opposed to multiple milliseconds likesynchronize_rcu().With this patch deletion of 16k nexthops takes less than a second:
# time -p ip link set dev dummy10 down real 0.12 user 0.00 sys 0.04Tested with
fib_nexthops.shwhich includes torture tests that prompted the initial change:# ./fib_nexthops.sh ... Tests passed: 134 Tests failed: 0
Quoted 6 lines
Fixes 90f33bffa382 ("nexthops: don't modify published nexthop groups")Signed-off-by Ido Schimmel <[email protected]>--- net/ipv4/nexthop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks for finding this, Ido.
Quoted 72 lines · Ido Schimmel
From: Ido Schimmel <[email protected]>
While insertion of 16k nexthops all using the same netdev ('dummy10') takes less than a second, deletion takes about 130 seconds:
# time -p ip -b nexthop.batch real 0.29 user 0.01 sys 0.15# time -p ip link set dev dummy10 down real 131.03 user 0.06 sys 0.52This is because of repeated calls to
synchronize_rcu()whenever a nexthop is removed from a nexthop group:# /usr/share/bcc/tools/offcputime -p `pgrep -nx ip` -K ... b'finish_task_switch' b'schedule' b'schedule_timeout' b'wait_for_completion' b'__wait_rcu_gp' b'synchronize_rcu.part.0' b'synchronize_rcu' b'__remove_nexthop' b'remove_nexthop' b'nexthop_flush_dev' b'nh_netdev_event' b'raw_notifier_call_chain' b'call_netdevice_notifiers_info' b'__dev_notify_flags' b'dev_change_flags' b'do_setlink' b'__rtnl_newlink' b'rtnl_newlink' b'rtnetlink_rcv_msg' b'netlink_rcv_skb' b'rtnetlink_rcv' b'netlink_unicast' b'netlink_sendmsg' b'____sys_sendmsg' b'___sys_sendmsg' b'__sys_sendmsg' b'__x64_sys_sendmsg' b'do_syscall_64' b'entry_SYSCALL_64_after_hwframe' - ip (277) 126554955Since nexthops are always deleted under RTNL,
synchronize_net()can be used instead. It will callsynchronize_rcu_expedited()which only blocks for several microseconds as opposed to multiple milliseconds likesynchronize_rcu().With this patch deletion of 16k nexthops takes less than a second:
# time -p ip link set dev dummy10 down real 0.12 user 0.00 sys 0.04Tested with
fib_nexthops.shwhich includes torture tests that prompted the initial change:# ./fib_nexthops.sh ... Tests passed: 134 Tests failed: 0
Quoted 7 lines
Fixes 90f33bffa382 ("nexthops: don't modify published nexthop groups")Signed-off-by Ido Schimmel <[email protected]>--- net/ipv4/nexthop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Looks good.
Quoted 4 lines · On Fri, 16 Oct 2020 20:29:14 +0300 Ido Schimmel wrote:
From: Ido Schimmel <[email protected]>
While insertion of 16k nexthops all using the same netdev ('dummy10') takes less than a second, deletion takes about 130 seconds:
Applied, thank you!