From: Miklos Szeredi <miklos@szeredi.hu>
To: viro@ZenIV.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
mgorman@suse.de, gregkh@suse.de, hch@infradead.org,
akpm@linux-foundation.org, torvalds@linux-foundation.org
Subject: [RFC PATCH] shrink_dcache_parent() deadlock
Date: Mon, 09 Jan 2012 11:58:54 +0100 [thread overview]
Message-ID: <87ipkl87m9.fsf@tucsk.pomaz.szeredi.hu> (raw)
Two (or more) concurrent calls of shrink_dcache_parent() on the same
dentry with the right timing may cause shrink_dcache_parent() to loop
forever.
Here's what appears to happen:
1 - CPU0: select_parent(P) finds C and puts it on sb->s_dentry_lru, returns 1
2 - CPU0: __shrink_dcache_sb() moves C from sb->s_dentry_lru to tmp
3 - CPU1: select_parent(P) locks P->d_lock
4 - CPU0: shrink_dentry_list() locks C->d_lock
dentry_kill(C) tries to lock P->d_lock but fails, unlocks C->d_lock
5 - CPU1: select_parent(P) locks C->d_lock,
moves C from tmp to sb->s_dentry_lru, returns 1
6 - CPU0: shrink_dentry_list() finds tmp empty, returns
7 - Goto 2 with CPU0 and CPU1 switched
So basically select_parent() steals the dentry from shrink_dentry_list()
and thinks it found a new one, causing shrink_dentry_list() to think
it's making progress and loop over and over.
This was actually triggered by a combination of the bonding driver
removing a directory in sysfs and a udev rule causing udev to do stat
multiple times on the just removed directory.
One fix would be to check all callers and prevent concurrent calls to
shrink_dcache_parent(). But I think a better solution is to stop the
stealing behavior.
This patch adds a new dentry flag that is set when the dentry is removed
from the lru and put on the list being processed by
shrink_dentry_list(). The flag is cleared in dentry_lru_del() which is
called if the dentry gets a new reference just before it's pruned.
Thoughts?
diff --git a/fs/dcache.c b/fs/dcache.c
index 89509b5..09805eb 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -242,6 +242,7 @@ static void dentry_lru_add(struct dentry *dentry)
static void __dentry_lru_del(struct dentry *dentry)
{
list_del_init(&dentry->d_lru);
+ dentry->d_flags &= ~DCACHE_SHRINK_LIST;
dentry->d_sb->s_nr_dentry_unused--;
dentry_stat.nr_unused--;
}
@@ -807,6 +808,7 @@ relock:
spin_unlock(&dentry->d_lock);
} else {
list_move_tail(&dentry->d_lru, &tmp);
+ dentry->d_flags |= DCACHE_SHRINK_LIST;
spin_unlock(&dentry->d_lock);
if (!--count)
break;
@@ -1117,11 +1119,11 @@ resume:
* move only zero ref count dentries to the end
* of the unused list for prune_dcache
*/
- if (!dentry->d_count) {
+ if (dentry->d_count) {
+ dentry_lru_del(dentry);
+ } else if(!(dentry->d_flags & DCACHE_SHRINK_LIST)) {
dentry_lru_move_tail(dentry);
found++;
- } else {
- dentry_lru_del(dentry);
}
/*
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index ed9f74f..4eb8c80 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -203,6 +203,7 @@ struct dentry_operations {
#define DCACHE_CANT_MOUNT 0x0100
#define DCACHE_GENOCIDE 0x0200
+#define DCACHE_SHRINK_LIST 0x0400
#define DCACHE_NFSFS_RENAMED 0x1000
/* this dentry has been "silly renamed" and has to be deleted on the last
next reply other threads:[~2012-01-09 10:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-09 10:58 Miklos Szeredi [this message]
2012-01-09 16:43 ` [RFC PATCH] shrink_dcache_parent() deadlock Linus Torvalds
2012-01-09 17:05 ` Miklos Szeredi
2012-01-09 17:16 ` Greg KH
2012-01-09 17:16 ` Christoph Hellwig
2012-01-09 17:30 ` Al Viro
2012-01-09 18:30 ` Linus Torvalds
2012-01-09 18:46 ` Linus Torvalds
2012-01-09 19:04 ` Christoph Hellwig
2012-01-09 19:18 ` Linus Torvalds
2012-01-09 20:59 ` Dave Chinner
2012-01-09 21:21 ` Linus Torvalds
2012-01-10 1:34 ` Al Viro
2012-01-10 2:02 ` Linus Torvalds
2012-01-10 10:05 ` Miklos Szeredi
2012-01-10 16:00 ` Linus Torvalds
2012-01-10 16:15 ` Al Viro
2012-01-10 16:22 ` Miklos Szeredi
2012-01-10 16:33 ` Linus Torvalds
2012-01-10 16:50 ` Miklos Szeredi
2012-01-10 18:04 ` Al Viro
2012-01-10 21:52 ` Dave Chinner
2012-01-09 21:26 ` Al Viro
2012-01-09 17: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=87ipkl87m9.fsf@tucsk.pomaz.szeredi.hu \
--to=miklos@szeredi.hu \
--cc=akpm@linux-foundation.org \
--cc=gregkh@suse.de \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).