netns: add pre_exit method to struct pernet_operations
authorEric Dumazet <edumazet@google.com>
Tue, 18 Jun 2019 18:08:59 +0000 (11:08 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 19 Jun 2019 15:37:47 +0000 (11:37 -0400)
commitd7d99872c144a2c2f5d9c9d83627fa833836cba5
treef3a83dacc74fbe6c81665fb4c46ac2572173fcc8
parent2a54003e7af1eaddc05848dac14f7bcd77301478
netns: add pre_exit method to struct pernet_operations

Current struct pernet_operations exit() handlers are highly
discouraged to call synchronize_rcu().

There are cases where we need them, and exit_batch() does
not help the common case where a single netns is dismantled.

This patch leverages the existing synchronize_rcu() call
in cleanup_net()

Calling optional ->pre_exit() method before ->exit() or
->exit_batch() allows to benefit from a single synchronize_rcu()
call.

Note that the synchronize_rcu() calls added in this patch
are only in error paths or slow paths.

Tested:

$ time for i in {1..1000}; do unshare -n /bin/false;done

real 0m2.612s
user 0m0.171s
sys 0m2.216s

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/net_namespace.h
net/core/net_namespace.c