From: Peter Zijlstra <peterz@infradead.org>
To: oleg@redhat.com, paulmck@linux.vnet.ibm.com, tj@kernel.org,
mingo@redhat.com, linux-kernel@vger.kernel.org, der.herr@hofr.at,
peterz@infradead.org, dave@stgolabs.net, riel@redhat.com,
viro@ZenIV.linux.org.uk, torvalds@linux-foundation.org,
wagi@monom.org
Subject: [PATCH 3/7] fs/locks: Replace lg_local with a per-cpu spinlock
Date: Mon, 05 Sep 2016 21:40:57 +0200 [thread overview]
Message-ID: <20160905194127.199886988@infradead.org> (raw)
In-Reply-To: <20160905194054.369038779@infradead.org>
[-- Attachment #1: peter_zijlstra-fs_locks-replace_lg_local_with_a_per-cpu_spinlock.patch --]
[-- Type: text/plain, Size: 4582 bytes --]
As Oleg suggested, replace file_lock_list with a structure containing
the hlist head and a spinlock.
This completely removes the lglock from fs/locks.
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: oleg@redhat.com
Cc: paulmck@linux.vnet.ibm.com
Cc: tj@kernel.org
Cc: mingo@redhat.com
Cc: der.herr@hofr.at
Cc: dave@stgolabs.net
Cc: riel@redhat.com
Cc: torvalds@linux-foundation.org
Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
fs/Kconfig | 1 +
fs/locks.c | 47 +++++++++++++++++++++++++++++------------------
2 files changed, 30 insertions(+), 18 deletions(-)
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -62,6 +62,7 @@ config EXPORTFS
config FILE_LOCKING
bool "Enable POSIX file locking API" if EXPERT
default y
+ select PERCPU_RWSEM
help
This option enables standard file locking support, required
for filesystems like NFS and for the flock() system
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -128,7 +128,6 @@
#include <linux/pid_namespace.h>
#include <linux/hashtable.h>
#include <linux/percpu.h>
-#include <linux/lglock.h>
#define CREATE_TRACE_POINTS
#include <trace/events/filelock.h>
@@ -159,12 +158,17 @@ int lease_break_time = 45;
/*
* The global file_lock_list is only used for displaying /proc/locks, so we
- * keep a list on each CPU, with each list protected by its own spinlock via
- * the file_lock_lglock. Note that alterations to the list also require that
- * the relevant flc_lock is held.
+ * keep a list on each CPU, with each list protected by its own spinlock.
+ * Global serialization is done using file_rwsem.
+ *
+ * Note that alterations to the list also require that the relevant flc_lock is
+ * held.
*/
-DEFINE_STATIC_LGLOCK(file_lock_lglock);
-static DEFINE_PER_CPU(struct hlist_head, file_lock_list);
+struct file_lock_list_struct {
+ spinlock_t lock;
+ struct hlist_head hlist;
+};
+static DEFINE_PER_CPU(struct file_lock_list_struct, file_lock_list);
DEFINE_STATIC_PERCPU_RWSEM(file_rwsem);
/*
@@ -557,17 +561,21 @@ static int posix_same_owner(struct file_
/* Must be called with the flc_lock held! */
static void locks_insert_global_locks(struct file_lock *fl)
{
+ struct file_lock_list_struct *fll = this_cpu_ptr(&file_lock_list);
+
percpu_rwsem_assert_held(&file_rwsem);
- lg_local_lock(&file_lock_lglock);
+ spin_lock(&fll->lock);
fl->fl_link_cpu = smp_processor_id();
- hlist_add_head(&fl->fl_link, this_cpu_ptr(&file_lock_list));
- lg_local_unlock(&file_lock_lglock);
+ hlist_add_head(&fl->fl_link, &fll->hlist);
+ spin_unlock(&fll->lock);
}
/* Must be called with the flc_lock held! */
static void locks_delete_global_locks(struct file_lock *fl)
{
+ struct file_lock_list_struct *fll;
+
percpu_rwsem_assert_held(&file_rwsem);
/*
@@ -577,9 +585,11 @@ static void locks_delete_global_locks(st
*/
if (hlist_unhashed(&fl->fl_link))
return;
- lg_local_lock_cpu(&file_lock_lglock, fl->fl_link_cpu);
+
+ fll = per_cpu_ptr(&file_lock_list, fl->fl_link_cpu);
+ spin_lock(&fll->lock);
hlist_del_init(&fl->fl_link);
- lg_local_unlock_cpu(&file_lock_lglock, fl->fl_link_cpu);
+ spin_unlock(&fll->lock);
}
static unsigned long
@@ -2653,9 +2663,8 @@ static void *locks_start(struct seq_file
iter->li_pos = *pos + 1;
percpu_down_write(&file_rwsem);
- lg_global_lock(&file_lock_lglock);
spin_lock(&blocked_lock_lock);
- return seq_hlist_start_percpu(&file_lock_list, &iter->li_cpu, *pos);
+ return seq_hlist_start_percpu(&file_lock_list.hlist, &iter->li_cpu, *pos);
}
static void *locks_next(struct seq_file *f, void *v, loff_t *pos)
@@ -2663,14 +2672,13 @@ static void *locks_next(struct seq_file
struct locks_iterator *iter = f->private;
++iter->li_pos;
- return seq_hlist_next_percpu(v, &file_lock_list, &iter->li_cpu, pos);
+ return seq_hlist_next_percpu(v, &file_lock_list.hlist, &iter->li_cpu, pos);
}
static void locks_stop(struct seq_file *f, void *v)
__releases(&blocked_lock_lock)
{
spin_unlock(&blocked_lock_lock);
- lg_global_unlock(&file_lock_lglock);
percpu_up_write(&file_rwsem);
}
@@ -2712,10 +2720,13 @@ static int __init filelock_init(void)
filelock_cache = kmem_cache_create("file_lock_cache",
sizeof(struct file_lock), 0, SLAB_PANIC, NULL);
- lg_lock_init(&file_lock_lglock, "file_lock_lglock");
- for_each_possible_cpu(i)
- INIT_HLIST_HEAD(per_cpu_ptr(&file_lock_list, i));
+ for_each_possible_cpu(i) {
+ struct file_lock_list_struct *fll = per_cpu_ptr(&file_lock_list, i);
+
+ spin_lock_init(&fll->lock);
+ INIT_HLIST_HEAD(&fll->hlist);
+ }
return 0;
}
next prev parent reply other threads:[~2016-09-05 19:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-05 19:40 [PATCH 0/7] perpcu rwsem, fs/locks and killing lglocks Peter Zijlstra
2016-09-05 19:40 ` [PATCH 1/7] percpu-rwsem: DEFINE_STATIC_PERCPU_RWSEM Peter Zijlstra
2016-09-05 19:40 ` [PATCH 2/7] fs/locks: Replace lg_global with a percpu-rwsem Peter Zijlstra
2016-09-05 19:40 ` Peter Zijlstra [this message]
2016-09-05 19:40 ` [PATCH 4/7] percpu-rwsem: Add down_read_preempt_disable() Peter Zijlstra
2016-09-05 19:40 ` [PATCH 5/7] fs/locks: Use percpu_down_read_preempt_disable Peter Zijlstra
2016-09-05 19:41 ` [PATCH 6/7] stop_machine: Remove stop_cpus_lock and lg_double_lock/unlock() Peter Zijlstra
2016-09-05 19:41 ` [PATCH 7/7] locking: Remove lglock Peter Zijlstra
2016-09-06 4:45 ` [PATCH 0/7] perpcu rwsem, fs/locks and killing lglocks Mike Galbraith
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=20160905194127.199886988@infradead.org \
--to=peterz@infradead.org \
--cc=dave@stgolabs.net \
--cc=der.herr@hofr.at \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=riel@redhat.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=wagi@monom.org \
/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
all inboxes | Powered by JetHome®