linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: fruggeri@arista.com (Francesco Ruggeri)
To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	xiyou.wangcong@gmail.com, ap420073@gmail.com, andriin@fb.com,
	edumazet@google.com, jiri@mellanox.com, ast@kernel.org,
	kuba@kernel.org, davem@davemloft.net, fruggeri@arista.com
Subject: [PATCH] net: make netdev_wait_allrefs wake-able
Date: Wed, 16 Sep 2020 19:00:20 -0700	[thread overview]
Message-ID: <20200917020021.0860995C06B9@us180.sjc.aristanetworks.com> (raw)

The combination of aca_free_rcu, introduced in commit 2384d02520ff
("net/ipv6: Add anycast addresses to a global hashtable"), and
fib6_info_destroy_rcu, introduced in commit 9b0a8da8c4c6 ("net/ipv6:
respect rcu grace period before freeing fib6_info"), can result in
an extra rcu grace period being needed when deleting an interface,
with the result that netdev_wait_allrefs ends up hitting the msleep(250),
which is considerably longer than the required grace period.
This can result in long delays when deleting a large number of interfaces,
and it can be observed with this script:

ns=dummy-ns
NIFS=100

ip netns add $ns
ip netns exec $ns ip link set lo up
ip netns exec $ns sysctl net.ipv6.conf.default.disable_ipv6=0
ip netns exec $ns sysctl net.ipv6.conf.default.forwarding=1

for ((i=0; i<$NIFS; i++))
do
        if=eth$i
        ip netns exec $ns ip link add $if type dummy
        ip netns exec $ns ip link set $if up
        ip netns exec $ns ip -6 addr add 2021:$i::1/120 dev $if
done

for ((i=0; i<$NIFS; i++))
do
        if=eth$i
        ip netns exec $ns ip link del $if
done

ip netns del $ns

This patch converts the msleep(250) into a wake-able wait,
allowing dev_put to wake up netdev_wait_allrefs.

Time with this patch on a 5.4 kernel:

real	0m7.494s
user	0m0.403s
sys	0m1.197s

Time without this patch:

real	0m31.522s
user	0m0.438s
sys	0m1.156s

Signed-off-by: Francesco Ruggeri <fruggeri@arista.com>

---
 include/linux/netdevice.h | 6 ++++++
 net/core/dev.c            | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index b0e303f6603f..3bbae238c11d 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1795,6 +1795,7 @@ enum netdev_priv_flags {
  *
  *	@needs_free_netdev:	Should unregister perform free_netdev?
  *	@priv_destructor:	Called from unregister
+ *	@destroy_task:		Task waiting for refcount to drop to 0
  *	@npinfo:		XXX: need comments on this one
  * 	@nd_net:		Network namespace this network device is inside
  *
@@ -2089,6 +2090,7 @@ struct net_device {
 
 	bool needs_free_netdev;
 	void (*priv_destructor)(struct net_device *dev);
+	struct task_struct	*destroy_task;
 
 #ifdef CONFIG_NETPOLL
 	struct netpoll_info __rcu	*npinfo;
@@ -3873,7 +3875,11 @@ void netdev_run_todo(void);
  */
 static inline void dev_put(struct net_device *dev)
 {
+	struct task_struct *destroy_task = dev->destroy_task;
+
 	this_cpu_dec(*dev->pcpu_refcnt);
+	if (destroy_task)
+		wake_up_process(destroy_task);
 }
 
 /**
diff --git a/net/core/dev.c b/net/core/dev.c
index 4086d335978c..795c3d39e807 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9994,6 +9994,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
 	linkwatch_forget_dev(dev);
 
 	rebroadcast_time = warning_time = jiffies;
+	dev->destroy_task = current;
 	refcnt = netdev_refcnt_read(dev);
 
 	while (refcnt != 0) {
@@ -10023,7 +10024,8 @@ static void netdev_wait_allrefs(struct net_device *dev)
 			rebroadcast_time = jiffies;
 		}
 
-		msleep(250);
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(HZ/4);
 
 		refcnt = netdev_refcnt_read(dev);
 
@@ -10033,6 +10035,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
 			warning_time = jiffies;
 		}
 	}
+	dev->destroy_task = NULL;
 }
 
 /* The sequence is:
-- 
2.28.0



             reply	other threads:[~2020-09-17  2:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17  2:00 Francesco Ruggeri [this message]
2020-09-17  6:33 ` [PATCH] net: make netdev_wait_allrefs wake-able Francesco Ruggeri
2020-09-17  6:51   ` Eric Dumazet
2020-09-17 16:17     ` Francesco Ruggeri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917020021.0860995C06B9@us180.sjc.aristanetworks.com \
    --to=fruggeri@arista.com \
    --cc=andriin@fb.com \
    --cc=ap420073@gmail.com \
    --cc=ast@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jiri@mellanox.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).