From: Leon Yang <leon.gh.yang@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
infrastructure)), linux-kernel@vger.kernel.org (open list)
Cc: Leon Yang <leon.gh.yang@gmail.com>
Subject: [PATCH] Batch unmount cleanup
Date: Mon, 16 Oct 2017 13:52:16 -0500 [thread overview]
Message-ID: <1508179936-15591-1-git-send-email-leon.gh.yang@gmail.com> (raw)
From: Leon Yang <leon.gh.yang@gmail.com>
Each time the unmounted list is cleanup, synchronize_rcu() is
called, which is relatively costly. Scheduling the cleanup in a
workqueue, similar to what is being done in
net/core/net_namespace.c:cleanup_net, makes unmounting faster
without adding too much overhead. This is useful especially for
servers with many containers where mounting/unmounting happens a
lot.
Signed-off-by: Leon Yang <leon.gh.yang@gmail.com>
---
fs/namespace.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 3b601f1..864ce7e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -68,6 +68,7 @@ static int mnt_group_start = 1;
static struct hlist_head *mount_hashtable __read_mostly;
static struct hlist_head *mountpoint_hashtable __read_mostly;
static struct kmem_cache *mnt_cache __read_mostly;
+static struct workqueue_struct *unmounted_wq;
static DECLARE_RWSEM(namespace_sem);
/* /sys/fs */
@@ -1409,22 +1410,29 @@ EXPORT_SYMBOL(may_umount);
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
-static void namespace_unlock(void)
+static void cleanup_unmounted(struct work_struct *work)
{
struct hlist_head head;
+ down_write(&namespace_sem);
hlist_move_list(&unmounted, &head);
up_write(&namespace_sem);
- if (likely(hlist_empty(&head)))
- return;
-
synchronize_rcu();
group_pin_kill(&head);
}
+static DECLARE_WORK(unmounted_cleanup_work, cleanup_unmounted);
+
+static void namespace_unlock(void)
+{
+ if (!likely(hlist_empty(&unmounted)))
+ queue_work(unmounted_wq, &unmounted_cleanup_work);
+ up_write(&namespace_sem);
+}
+
static inline void namespace_lock(void)
{
down_write(&namespace_sem);
@@ -3276,6 +3284,17 @@ void __init mnt_init(void)
init_mount_tree();
}
+static int __init unmounted_wq_init(void)
+{
+ /* Create workqueue for cleanup */
+ unmounted_wq = create_singlethread_workqueue("unmounted");
+ if (!unmounted_wq)
+ panic("Could not create unmounted workq");
+ return 0;
+}
+
+pure_initcall(unmounted_wq_init);
+
void put_mnt_ns(struct mnt_namespace *ns)
{
if (!atomic_dec_and_test(&ns->count))
--
2.7.4
next reply other threads:[~2017-10-16 18:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 18:52 Leon Yang [this message]
2017-10-16 22:19 ` Al Viro
2017-10-18 1:38 ` Eric W. Biederman
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=1508179936-15591-1-git-send-email-leon.gh.yang@gmail.com \
--to=leon.gh.yang@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
Powered by JetHome