aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2012-01-10 12:22:25 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2012-01-10 13:06:32 -0500
commiteaf5f9073533cde21c7121c136f1c3f072d9cf59 (patch)
treedb9cb9424fbae04decf7a8281a5180f65e5124b9 /fs/dcache.c
parentf4947fbce208990266920d51837e4e7ba9779db1 (diff)
fix shrink_dcache_parent() livelock
Two (or more) concurrent calls of shrink_dcache_parent() on the same dentry 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 dispose list, returns 1 2 - CPU1: select_parent(P) locks P->d_lock 3 - CPU0: shrink_dentry_list() locks C->d_lock dentry_kill(C) tries to lock P->d_lock but fails, unlocks C->d_lock 4 - CPU1: select_parent(P) locks C->d_lock, moves C from dispose list being processed on CPU0 to the new dispose list, returns 1 5 - CPU0: shrink_dentry_list() finds dispose list empty, returns 6 - Goto 2 with CPU0 and CPU1 switched 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. One way to trigger this is to make udev calls stat() on the sysfs file while it is going away. Having a file in /lib/udev/rules.d/ with only this one rule seems to the trick: ATTR{vendor}=="0x8086", ATTR{device}=="0x10ca", ENV{PCI_SLOT_NAME}="%k", ENV{MATCHADDR}="$attr{address}", RUN+="/bin/true" Then execute the following loop: while true; do echo -bond0 > /sys/class/net/bonding_masters echo +bond0 > /sys/class/net/bonding_masters echo -bond1 > /sys/class/net/bonding_masters echo +bond1 > /sys/class/net/bonding_masters done 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 added to the dispose list. The flag is cleared in dentry_lru_del() in case the dentry gets a new reference just before being pruned. If the dentry has this flag, select_parent() will skip it and let shrink_dentry_list() retry pruning it. With select_parent() skipping those dentries there will not be the appearance of progress (new dentries found) when there is none, hence shrink_dcache_parent() will not loop forever. Set the flag is also set in prune_dcache_sb() for consistency as suggested by Linus. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> CC: stable@vger.kernel.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 3c6d3113a255..616fedff011a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -243,6 +243,7 @@ static void dentry_lru_add(struct dentry *dentry)
243static void __dentry_lru_del(struct dentry *dentry) 243static void __dentry_lru_del(struct dentry *dentry)
244{ 244{
245 list_del_init(&dentry->d_lru); 245 list_del_init(&dentry->d_lru);
246 dentry->d_flags &= ~DCACHE_SHRINK_LIST;
246 dentry->d_sb->s_nr_dentry_unused--; 247 dentry->d_sb->s_nr_dentry_unused--;
247 dentry_stat.nr_unused--; 248 dentry_stat.nr_unused--;
248} 249}
@@ -806,6 +807,7 @@ relock:
806 spin_unlock(&dentry->d_lock); 807 spin_unlock(&dentry->d_lock);
807 } else { 808 } else {
808 list_move_tail(&dentry->d_lru, &tmp); 809 list_move_tail(&dentry->d_lru, &tmp);
810 dentry->d_flags |= DCACHE_SHRINK_LIST;
809 spin_unlock(&dentry->d_lock); 811 spin_unlock(&dentry->d_lock);
810 if (!--count) 812 if (!--count)
811 break; 813 break;
@@ -1097,14 +1099,19 @@ resume:
1097 1099
1098 /* 1100 /*
1099 * move only zero ref count dentries to the dispose list. 1101 * move only zero ref count dentries to the dispose list.
1102 *
1103 * Those which are presently on the shrink list, being processed
1104 * by shrink_dentry_list(), shouldn't be moved. Otherwise the
1105 * loop in shrink_dcache_parent() might not make any progress
1106 * and loop forever.
1100 */ 1107 */
1101 if (!dentry->d_count) { 1108 if (dentry->d_count) {
1109 dentry_lru_del(dentry);
1110 } else if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) {
1102 dentry_lru_move_list(dentry, dispose); 1111 dentry_lru_move_list(dentry, dispose);
1112 dentry->d_flags |= DCACHE_SHRINK_LIST;
1103 found++; 1113 found++;
1104 } else {
1105 dentry_lru_del(dentry);
1106 } 1114 }
1107
1108 /* 1115 /*
1109 * We can return to the caller if we have found some (this 1116 * We can return to the caller if we have found some (this
1110 * ensures forward progress). We'll be coming back to find 1117 * ensures forward progress). We'll be coming back to find