Skip to content

Commit a366e30

Browse files
Eric Dumazetdavem330
authored andcommitted
ip6mr: remove synchronize_rcu() in favor of SOCK_RCU_FREE
Kirill found that recently added synchronize_rcu() call in ip6mr_sk_done() was slowing down netns dismantle and posted a patch to use it only if the socket was found. I instead suggested to get rid of this call, and use instead SOCK_RCU_FREE We might later change IPv4 side to use the same technique and unify both stacks. IPv4 does not use synchronize_rcu() but has a call_rcu() that could be replaced by SOCK_RCU_FREE. Tested: time for i in {1..1000}; do unshare -n /bin/false;done Before : real 7m18.911s After : real 10.187s Fixes: 8571ab4 ("ip6mr: Make mroute_sk rcu-based") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Kirill Tkhai <[email protected]> Cc: Yuval Mintz <[email protected]> Reviewed-by: Kirill Tkhai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3f6be0e commit a366e30

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

net/ipv6/ip6mr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk)
14431443
err = -EADDRINUSE;
14441444
} else {
14451445
rcu_assign_pointer(mrt->mroute_sk, sk);
1446+
sock_set_flag(sk, SOCK_RCU_FREE);
14461447
net->ipv6.devconf_all->mc_forwarding++;
14471448
}
14481449
write_unlock_bh(&mrt_lock);
@@ -1472,6 +1473,10 @@ int ip6mr_sk_done(struct sock *sk)
14721473
if (sk == rtnl_dereference(mrt->mroute_sk)) {
14731474
write_lock_bh(&mrt_lock);
14741475
RCU_INIT_POINTER(mrt->mroute_sk, NULL);
1476+
/* Note that mroute_sk had SOCK_RCU_FREE set,
1477+
* so the RCU grace period before sk freeing
1478+
* is guaranteed by sk_destruct()
1479+
*/
14751480
net->ipv6.devconf_all->mc_forwarding--;
14761481
write_unlock_bh(&mrt_lock);
14771482
inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
@@ -1485,7 +1490,6 @@ int ip6mr_sk_done(struct sock *sk)
14851490
}
14861491
}
14871492
rtnl_unlock();
1488-
synchronize_rcu();
14891493

14901494
return err;
14911495
}

0 commit comments

Comments
 (0)