Skip to content

Commit 06c86e6

Browse files
committed
Merge branch 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull dcache updates from Al Viro: "This is the first part of dealing with livelocks etc around shrink_dcache_parent()." * 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: restore cond_resched() in shrink_dcache_parent() dput(): turn into explicit while() loop dcache: move cond_resched() into the end of __dentry_kill() d_walk(): kill 'finish' callback d_invalidate(): unhash immediately
2 parents f459c34 + 4fb4887 commit 06c86e6

File tree

1 file changed

+43
-79
lines changed

1 file changed

+43
-79
lines changed

fs/dcache.c

Lines changed: 43 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ static void __dentry_kill(struct dentry *dentry)
580580
spin_unlock(&dentry->d_lock);
581581
if (likely(can_free))
582582
dentry_free(dentry);
583+
cond_resched();
583584
}
584585

585586
static struct dentry *__lock_parent(struct dentry *dentry)
@@ -827,30 +828,24 @@ static inline bool fast_dput(struct dentry *dentry)
827828
*/
828829
void dput(struct dentry *dentry)
829830
{
830-
if (unlikely(!dentry))
831-
return;
831+
while (dentry) {
832+
might_sleep();
832833

833-
repeat:
834-
might_sleep();
834+
rcu_read_lock();
835+
if (likely(fast_dput(dentry))) {
836+
rcu_read_unlock();
837+
return;
838+
}
835839

836-
rcu_read_lock();
837-
if (likely(fast_dput(dentry))) {
840+
/* Slow case: now with the dentry lock held */
838841
rcu_read_unlock();
839-
return;
840-
}
841842

842-
/* Slow case: now with the dentry lock held */
843-
rcu_read_unlock();
844-
845-
if (likely(retain_dentry(dentry))) {
846-
spin_unlock(&dentry->d_lock);
847-
return;
848-
}
843+
if (likely(retain_dentry(dentry))) {
844+
spin_unlock(&dentry->d_lock);
845+
return;
846+
}
849847

850-
dentry = dentry_kill(dentry);
851-
if (dentry) {
852-
cond_resched();
853-
goto repeat;
848+
dentry = dentry_kill(dentry);
854849
}
855850
}
856851
EXPORT_SYMBOL(dput);
@@ -1052,8 +1047,6 @@ static void shrink_dentry_list(struct list_head *list)
10521047
while (!list_empty(list)) {
10531048
struct dentry *dentry, *parent;
10541049

1055-
cond_resched();
1056-
10571050
dentry = list_entry(list->prev, struct dentry, d_lru);
10581051
spin_lock(&dentry->d_lock);
10591052
rcu_read_lock();
@@ -1230,13 +1223,11 @@ enum d_walk_ret {
12301223
* @parent: start of walk
12311224
* @data: data passed to @enter() and @finish()
12321225
* @enter: callback when first entering the dentry
1233-
* @finish: callback when successfully finished the walk
12341226
*
1235-
* The @enter() and @finish() callbacks are called with d_lock held.
1227+
* The @enter() callbacks are called with d_lock held.
12361228
*/
12371229
static void d_walk(struct dentry *parent, void *data,
1238-
enum d_walk_ret (*enter)(void *, struct dentry *),
1239-
void (*finish)(void *))
1230+
enum d_walk_ret (*enter)(void *, struct dentry *))
12401231
{
12411232
struct dentry *this_parent;
12421233
struct list_head *next;
@@ -1325,8 +1316,6 @@ static void d_walk(struct dentry *parent, void *data,
13251316
if (need_seqretry(&rename_lock, seq))
13261317
goto rename_retry;
13271318
rcu_read_unlock();
1328-
if (finish)
1329-
finish(data);
13301319

13311320
out_unlock:
13321321
spin_unlock(&this_parent->d_lock);
@@ -1375,7 +1364,7 @@ int path_has_submounts(const struct path *parent)
13751364
struct check_mount data = { .mnt = parent->mnt, .mounted = 0 };
13761365

13771366
read_seqlock_excl(&mount_lock);
1378-
d_walk(parent->dentry, &data, path_check_mount, NULL);
1367+
d_walk(parent->dentry, &data, path_check_mount);
13791368
read_sequnlock_excl(&mount_lock);
13801369

13811370
return data.mounted;
@@ -1483,11 +1472,16 @@ void shrink_dcache_parent(struct dentry *parent)
14831472
data.start = parent;
14841473
data.found = 0;
14851474

1486-
d_walk(parent, &data, select_collect, NULL);
1475+
d_walk(parent, &data, select_collect);
1476+
1477+
if (!list_empty(&data.dispose)) {
1478+
shrink_dentry_list(&data.dispose);
1479+
continue;
1480+
}
1481+
1482+
cond_resched();
14871483
if (!data.found)
14881484
break;
1489-
1490-
shrink_dentry_list(&data.dispose);
14911485
}
14921486
}
14931487
EXPORT_SYMBOL(shrink_dcache_parent);
@@ -1518,7 +1512,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
15181512
static void do_one_tree(struct dentry *dentry)
15191513
{
15201514
shrink_dcache_parent(dentry);
1521-
d_walk(dentry, dentry, umount_check, NULL);
1515+
d_walk(dentry, dentry, umount_check);
15221516
d_drop(dentry);
15231517
dput(dentry);
15241518
}
@@ -1542,78 +1536,48 @@ void shrink_dcache_for_umount(struct super_block *sb)
15421536
}
15431537
}
15441538

1545-
struct detach_data {
1546-
struct select_data select;
1547-
struct dentry *mountpoint;
1548-
};
1549-
static enum d_walk_ret detach_and_collect(void *_data, struct dentry *dentry)
1539+
static enum d_walk_ret find_submount(void *_data, struct dentry *dentry)
15501540
{
1551-
struct detach_data *data = _data;
1552-
1541+
struct dentry **victim = _data;
15531542
if (d_mountpoint(dentry)) {
15541543
__dget_dlock(dentry);
1555-
data->mountpoint = dentry;
1544+
*victim = dentry;
15561545
return D_WALK_QUIT;
15571546
}
1558-
1559-
return select_collect(&data->select, dentry);
1560-
}
1561-
1562-
static void check_and_drop(void *_data)
1563-
{
1564-
struct detach_data *data = _data;
1565-
1566-
if (!data->mountpoint && list_empty(&data->select.dispose))
1567-
__d_drop(data->select.start);
1547+
return D_WALK_CONTINUE;
15681548
}
15691549

15701550
/**
15711551
* d_invalidate - detach submounts, prune dcache, and drop
15721552
* @dentry: dentry to invalidate (aka detach, prune and drop)
1573-
*
1574-
* no dcache lock.
1575-
*
1576-
* The final d_drop is done as an atomic operation relative to
1577-
* rename_lock ensuring there are no races with d_set_mounted. This
1578-
* ensures there are no unhashed dentries on the path to a mountpoint.
15791553
*/
15801554
void d_invalidate(struct dentry *dentry)
15811555
{
1582-
/*
1583-
* If it's already been dropped, return OK.
1584-
*/
1556+
bool had_submounts = false;
15851557
spin_lock(&dentry->d_lock);
15861558
if (d_unhashed(dentry)) {
15871559
spin_unlock(&dentry->d_lock);
15881560
return;
15891561
}
1562+
__d_drop(dentry);
15901563
spin_unlock(&dentry->d_lock);
15911564

15921565
/* Negative dentries can be dropped without further checks */
1593-
if (!dentry->d_inode) {
1594-
d_drop(dentry);
1566+
if (!dentry->d_inode)
15951567
return;
1596-
}
15971568

1569+
shrink_dcache_parent(dentry);
15981570
for (;;) {
1599-
struct detach_data data;
1600-
1601-
data.mountpoint = NULL;
1602-
INIT_LIST_HEAD(&data.select.dispose);
1603-
data.select.start = dentry;
1604-
data.select.found = 0;
1605-
1606-
d_walk(dentry, &data, detach_and_collect, check_and_drop);
1607-
1608-
if (!list_empty(&data.select.dispose))
1609-
shrink_dentry_list(&data.select.dispose);
1610-
else if (!data.mountpoint)
1571+
struct dentry *victim = NULL;
1572+
d_walk(dentry, &victim, find_submount);
1573+
if (!victim) {
1574+
if (had_submounts)
1575+
shrink_dcache_parent(dentry);
16111576
return;
1612-
1613-
if (data.mountpoint) {
1614-
detach_mounts(data.mountpoint);
1615-
dput(data.mountpoint);
16161577
}
1578+
had_submounts = true;
1579+
detach_mounts(victim);
1580+
dput(victim);
16171581
}
16181582
}
16191583
EXPORT_SYMBOL(d_invalidate);
@@ -3134,7 +3098,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
31343098

31353099
void d_genocide(struct dentry *parent)
31363100
{
3137-
d_walk(parent, parent, d_genocide_kill, NULL);
3101+
d_walk(parent, parent, d_genocide_kill);
31383102
}
31393103

31403104
EXPORT_SYMBOL(d_genocide);

0 commit comments

Comments
 (0)