From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 12/15] parallel lookups machinery, part 2
Date: Sat, 16 Apr 2016 01:55:24 +0100 [thread overview]
Message-ID: <1460768127-31822-12-git-send-email-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20160416005232.GV25498@ZenIV.linux.org.uk>
From: Al Viro <viro@zeniv.linux.org.uk>
We'll need to verify that there's neither a hashed nor in-lookup
dentry with desired parent/name before adding to in-lookup set.
One possible solution would be to hold the parent's ->d_lock through
both checks, but while the in-lookup set is relatively small at any
time, dcache is not. And holding the parent's ->d_lock through
something like __d_lookup_rcu() would suck too badly.
So we leave the parent's ->d_lock alone, which means that we watch
out for the following scenario:
* we verify that there's no hashed match
* existing in-lookup match gets hashed by another process
* we verify that there's no in-lookup matches and decide
that everything's fine.
Solution: per-directory kinda-sorta seqlock, bumped around the times
we hash something that used to be in-lookup or move (and hash)
something in place of in-lookup. Then the above would turn into
* read the counter
* do dcache lookup
* if no matches found, check for in-lookup matches
* if there had been none of those either, check if the
counter has changed; repeat if it has.
The "kinda-sorta" part is due to the fact that we don't have much spare
space in inode. There is a spare word (shared with i_bdev/i_cdev/i_pipe),
so the counter part is not a problem, but spinlock is a different story.
We could use the parent's ->d_lock, and it would be less painful in
terms of contention, for __d_add() it would be rather inconvenient to
grab; we could do that (using lock_parent()), but...
Fortunately, we can get serialization on the counter itself, and it
might be a good idea in general; we can use cmpxchg() in a loop to
get from even to odd and smp_store_release() from odd to even.
This commit adds the counter and updating logics; the readers will be
added in the next commit.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/dcache.c | 34 ++++++++++++++++++++++++++++++++--
fs/inode.c | 1 +
include/linux/fs.h | 1 +
3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 5cea3cb..3959f18 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2361,6 +2361,22 @@ void d_rehash(struct dentry * entry)
}
EXPORT_SYMBOL(d_rehash);
+static inline unsigned start_dir_add(struct inode *dir)
+{
+
+ for (;;) {
+ unsigned n = dir->i_dir_seq;
+ if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
+ return n;
+ cpu_relax();
+ }
+}
+
+static inline void end_dir_add(struct inode *dir, unsigned n)
+{
+ smp_store_release(&dir->i_dir_seq, n + 2);
+}
+
void __d_not_in_lookup(struct dentry *dentry)
{
dentry->d_flags &= ~DCACHE_PAR_LOOKUP;
@@ -2371,9 +2387,14 @@ void __d_not_in_lookup(struct dentry *dentry)
static inline void __d_add(struct dentry *dentry, struct inode *inode)
{
+ struct inode *dir = NULL;
+ unsigned n;
spin_lock(&dentry->d_lock);
- if (unlikely(dentry->d_flags & DCACHE_PAR_LOOKUP))
+ if (unlikely(dentry->d_flags & DCACHE_PAR_LOOKUP)) {
+ dir = dentry->d_parent->d_inode;
+ n = start_dir_add(dir);
__d_not_in_lookup(dentry);
+ }
if (inode) {
unsigned add_flags = d_flags_for_inode(inode);
hlist_add_head(&dentry->d_u.d_alias, &inode->i_dentry);
@@ -2383,6 +2404,8 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode)
__fsnotify_d_instantiate(dentry);
}
_d_rehash(dentry);
+ if (dir)
+ end_dir_add(dir, n);
spin_unlock(&dentry->d_lock);
if (inode)
spin_unlock(&inode->i_lock);
@@ -2612,6 +2635,8 @@ static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target)
static void __d_move(struct dentry *dentry, struct dentry *target,
bool exchange)
{
+ struct inode *dir = NULL;
+ unsigned n;
if (!dentry->d_inode)
printk(KERN_WARNING "VFS: moving negative dcache entry\n");
@@ -2619,8 +2644,11 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
BUG_ON(d_ancestor(target, dentry));
dentry_lock_for_move(dentry, target);
- if (unlikely(target->d_flags & DCACHE_PAR_LOOKUP))
+ if (unlikely(target->d_flags & DCACHE_PAR_LOOKUP)) {
+ dir = target->d_parent->d_inode;
+ n = start_dir_add(dir);
__d_not_in_lookup(target);
+ }
write_seqcount_begin(&dentry->d_seq);
write_seqcount_begin_nested(&target->d_seq, DENTRY_D_LOCK_NESTED);
@@ -2670,6 +2698,8 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
write_seqcount_end(&target->d_seq);
write_seqcount_end(&dentry->d_seq);
+ if (dir)
+ end_dir_add(dir, n);
dentry_unlock_for_move(dentry, target);
}
diff --git a/fs/inode.c b/fs/inode.c
index 4202aac..4b884f7 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -151,6 +151,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
inode->i_bdev = NULL;
inode->i_cdev = NULL;
inode->i_link = NULL;
+ inode->i_dir_seq = 0;
inode->i_rdev = 0;
inode->dirtied_when = 0;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1b5fcae..0a32045 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -684,6 +684,7 @@ struct inode {
struct block_device *i_bdev;
struct cdev *i_cdev;
char *i_link;
+ unsigned i_dir_seq;
};
__u32 i_generation;
--
2.8.0.rc3
next prev parent reply other threads:[~2016-04-16 0:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-16 0:52 [PATCHSET][RFC][CFT] parallel lookups Al Viro
2016-04-16 0:55 ` [PATCH 01/15] security_d_instantiate(): move to the point prior to attaching dentry to inode Al Viro
2016-04-16 0:55 ` [PATCH 02/15] kernfs: use lookup_one_len_unlocked() Al Viro
2016-04-16 0:55 ` [PATCH 03/15] configfs_detach_prep(): make sure that wait_mutex won't go away Al Viro
2016-04-16 0:55 ` [PATCH 04/15] ocfs2: don't open-code inode_lock/inode_unlock Al Viro
2016-04-16 0:55 ` [PATCH 05/15] orangefs: " Al Viro
2016-04-16 0:55 ` [PATCH 06/15] reiserfs: open-code reiserfs_mutex_lock_safe() in reiserfs_unpack() Al Viro
2016-04-16 0:55 ` [PATCH 07/15] reconnect_one(): use lookup_one_len_unlocked() Al Viro
2016-04-18 19:23 ` J. Bruce Fields
2016-04-16 0:55 ` [PATCH 08/15] ovl_lookup_real(): " Al Viro
2016-04-16 0:55 ` [PATCH 09/15] lookup_slow(): bugger off on IS_DEADDIR() from the very beginning Al Viro
2016-04-16 0:55 ` [PATCH 10/15] __d_add(): don't drop/regain ->d_lock Al Viro
2016-04-24 18:09 ` Jeff Layton
2016-04-24 19:21 ` Al Viro
2016-04-16 0:55 ` [PATCH 11/15] beginning of transition to parallel lookups - marking in-lookup dentries Al Viro
2016-04-16 0:55 ` Al Viro [this message]
2016-04-16 0:55 ` [PATCH 13/15] parallel lookups machinery, part 3 Al Viro
2016-04-18 20:45 ` J. Bruce Fields
2016-04-16 0:55 ` [PATCH 14/15] parallel lookups machinery, part 4 (and last) Al Viro
2016-04-16 0:55 ` [PATCH 15/15] parallel lookups: actual switch to rwsem Al Viro
2016-04-16 3:02 ` Andreas Dilger
2016-04-16 3:31 ` Al Viro
2016-04-16 3:02 ` [PATCHSET][RFC][CFT] parallel lookups Andreas Dilger
2016-04-16 3:27 ` Al Viro
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=1460768127-31822-12-git-send-email-viro@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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®