While unregistering a netdev, we must find and clean up all resources holding refcounts of the device. This operation is usually triggered for each component via NETDEV_UNREGISTER and typically requires a full scan of hash tables, etc. For example, rt_flush_dev() and rt6_uncached_list_flush_dev() are called for each netdev and iterate over the global per-cpu lists to find uncached routes tied to the device, resulting in O(N_dev x (N_cpu + N_route)) loops during netns dismantle. Moreover, rt_flush_dev() and rt6_uncached_list_flush_dev() do not even require RTNL. To batch such cleanup across dying netns without holding RTNL before ops_exit_rtnl_list(), let's add a new ->pre_exit_batch() hook to pernet_operations. Signed-off-by: Kuniyuki Iwashima --- include/net/net_namespace.h | 1 + net/core/net_namespace.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index b4247e767d13..58b2601bb869 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -488,6 +488,7 @@ struct pernet_operations { */ int (*init)(struct net *net); void (*pre_exit)(struct net *net); + void (*pre_exit_batch)(struct list_head *net_exit_list); void (*exit)(struct net *net); void (*exit_batch)(struct list_head *net_exit_list); /* Following method is called with RTNL held. */ diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 0e13de0cd36b..476fbf913bad 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -160,6 +160,9 @@ static void ops_pre_exit_list(const struct pernet_operations *ops, list_for_each_entry(net, net_exit_list, exit_list) ops->pre_exit(net); } + + if (ops->pre_exit_batch) + ops->pre_exit_batch(net_exit_list); } static void ops_exit_rtnl_list(const struct list_head *ops_list, -- 2.56.0.rc1.315.gc6ed9934b7-goog