From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: davem@davemloft.net, nicolas.dichtel@6wind.com,
vyasevic@redhat.com, ktkhai@virtuozzo.com,
paulmck@linux.vnet.ibm.com, vyasevich@gmail.com,
mark.rutland@arm.com, gregkh@linuxfoundation.org,
leonro@mellanox.com, avagin@virtuozzo.com, fw@strlen.de,
roman.kapl@sysgo.com, netdev@vger.kernel.org
Subject: [PATCH 2/3] net: Make cleanup_list and net::cleanup_list of llist type
Date: Mon, 19 Feb 2018 12:58:45 +0300 [thread overview]
Message-ID: <151903432575.8021.5189428113212356710.stgit@localhost.localdomain> (raw)
In-Reply-To: <151903409491.8021.11032992295248447417.stgit@localhost.localdomain>
This simplifies cleanup queueing and makes cleanup lists
to use llist primitives. Since llist has its own cmpxchg()
ordering, cleanup_list_lock is not more need.
Also, struct llist_node is smaller, than struct list_head,
so we save some bytes in struct net with this patch.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
include/net/net_namespace.h | 3 ++-
net/core/net_namespace.c | 20 ++++++--------------
2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 115b01b92f4d..d4417495773a 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -59,12 +59,13 @@ struct net {
atomic64_t cookie_gen;
struct list_head list; /* list of network namespaces */
- struct list_head cleanup_list; /* namespaces on death row */
struct list_head exit_list; /* To linked to call pernet exit
* methods on dead net (net_sem
* read locked), or to unregister
* pernet ops (net_sem wr locked).
*/
+ struct llist_node cleanup_list; /* namespaces on death row */
+
struct user_namespace *user_ns; /* Owning user namespace */
struct ucounts *ucounts;
spinlock_t nsid_lock;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index e89a516620dd..abf8a46e94e2 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -481,21 +481,18 @@ static void unhash_nsid(struct net *net, struct net *last)
spin_unlock_bh(&net->nsid_lock);
}
-static DEFINE_SPINLOCK(cleanup_list_lock);
-static LIST_HEAD(cleanup_list); /* Must hold cleanup_list_lock to touch */
+static LLIST_HEAD(cleanup_list);
static void cleanup_net(struct work_struct *work)
{
const struct pernet_operations *ops;
struct net *net, *tmp, *last;
- struct list_head net_kill_list;
+ struct llist_node *net_kill_list;
LIST_HEAD(net_exit_list);
unsigned write;
/* Atomically snapshot the list of namespaces to cleanup */
- spin_lock_irq(&cleanup_list_lock);
- list_replace_init(&cleanup_list, &net_kill_list);
- spin_unlock_irq(&cleanup_list_lock);
+ net_kill_list = llist_del_all(&cleanup_list);
again:
write = READ_ONCE(nr_sync_pernet_ops);
if (write)
@@ -510,7 +507,7 @@ static void cleanup_net(struct work_struct *work)
/* Don't let anyone else find us. */
rtnl_lock();
- list_for_each_entry(net, &net_kill_list, cleanup_list)
+ llist_for_each_entry(net, net_kill_list, cleanup_list)
list_del_rcu(&net->list);
/* Cache last net. After we unlock rtnl, no one new net
* added to net_namespace_list can assign nsid pointer
@@ -525,7 +522,7 @@ static void cleanup_net(struct work_struct *work)
last = list_last_entry(&net_namespace_list, struct net, list);
rtnl_unlock();
- list_for_each_entry(net, &net_kill_list, cleanup_list) {
+ llist_for_each_entry(net, net_kill_list, cleanup_list) {
unhash_nsid(net, last);
list_add_tail(&net->exit_list, &net_exit_list);
}
@@ -585,12 +582,7 @@ static DECLARE_WORK(net_cleanup_work, cleanup_net);
void __put_net(struct net *net)
{
/* Cleanup the network namespace in process context */
- unsigned long flags;
-
- spin_lock_irqsave(&cleanup_list_lock, flags);
- list_add(&net->cleanup_list, &cleanup_list);
- spin_unlock_irqrestore(&cleanup_list_lock, flags);
-
+ llist_add(&net->cleanup_list, &cleanup_list);
queue_work(netns_wq, &net_cleanup_work);
}
EXPORT_SYMBOL_GPL(__put_net);
next prev parent reply other threads:[~2018-02-19 9:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-19 9:58 [PATCH 0/3] net: Get rid of net_mutex and simplify cleanup_list queueing Kirill Tkhai
2018-02-19 9:58 ` [PATCH 1/3] net: Kill net_mutex Kirill Tkhai
2018-02-20 23:18 ` Stephen Hemminger
2018-02-21 10:16 ` Kirill Tkhai
2018-02-19 9:58 ` Kirill Tkhai [this message]
2018-02-20 19:42 ` [PATCH 2/3] net: Make cleanup_list and net::cleanup_list of llist type Cong Wang
2018-02-21 8:30 ` Kirill Tkhai
2018-02-19 9:58 ` [PATCH 3/3] net: Queue net_cleanup_work only if there is first net added Kirill Tkhai
2018-02-19 13:52 ` [PATCH 0/3] net: Get rid of net_mutex and simplify cleanup_list queueing Kirill Tkhai
2018-02-20 18:24 ` David Miller
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=151903432575.8021.5189428113212356710.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.com \
--cc=avagin@virtuozzo.com \
--cc=davem@davemloft.net \
--cc=fw@strlen.de \
--cc=gregkh@linuxfoundation.org \
--cc=leonro@mellanox.com \
--cc=mark.rutland@arm.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=roman.kapl@sysgo.com \
--cc=vyasevic@redhat.com \
--cc=vyasevich@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