Skip to content

Commit 5dd12af

Browse files
committed
Merge branch 'dcache-cleanup'
* dcache-cleanup: vfs: get rid of insane dentry hashing rules
2 parents 8f75446 + dea3667 commit 5dd12af

2 files changed

Lines changed: 18 additions & 28 deletions

File tree

‎fs/dcache.c‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void d_free(struct dentry *dentry)
164164
if (dentry->d_op && dentry->d_op->d_release)
165165
dentry->d_op->d_release(dentry);
166166

167-
/* if dentry was never inserted into hash, immediate free is OK */
168-
if (hlist_bl_unhashed(&dentry->d_hash))
167+
/* if dentry was never visible to RCU, immediate free is OK */
168+
if (!(dentry->d_flags & DCACHE_RCUACCESS))
169169
__d_free(&dentry->d_u.d_rcu);
170170
else
171171
call_rcu(&dentry->d_u.d_rcu, __d_free);
@@ -327,28 +327,19 @@ static struct dentry *d_kill(struct dentry *dentry, struct dentry *parent)
327327
*/
328328
void __d_drop(struct dentry *dentry)
329329
{
330-
if (!(dentry->d_flags & DCACHE_UNHASHED)) {
330+
if (!d_unhashed(dentry)) {
331331
struct hlist_bl_head *b;
332-
if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED)) {
332+
if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED))
333333
b = &dentry->d_sb->s_anon;
334-
spin_lock_bucket(b);
335-
dentry->d_flags |= DCACHE_UNHASHED;
336-
hlist_bl_del_init(&dentry->d_hash);
337-
spin_unlock_bucket(b);
338-
} else {
339-
struct hlist_bl_head *b;
334+
else
340335
b = d_hash(dentry->d_parent, dentry->d_name.hash);
341-
spin_lock_bucket(b);
342-
/*
343-
* We may not actually need to put DCACHE_UNHASHED
344-
* manipulations under the hash lock, but follow
345-
* the principle of least surprise.
346-
*/
347-
dentry->d_flags |= DCACHE_UNHASHED;
348-
hlist_bl_del_rcu(&dentry->d_hash);
349-
spin_unlock_bucket(b);
350-
dentry_rcuwalk_barrier(dentry);
351-
}
336+
337+
spin_lock_bucket(b);
338+
__hlist_bl_del(&dentry->d_hash);
339+
dentry->d_hash.pprev = NULL;
340+
spin_unlock_bucket(b);
341+
342+
dentry_rcuwalk_barrier(dentry);
352343
}
353344
}
354345
EXPORT_SYMBOL(__d_drop);
@@ -1301,7 +1292,7 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
13011292
dname[name->len] = 0;
13021293

13031294
dentry->d_count = 1;
1304-
dentry->d_flags = DCACHE_UNHASHED;
1295+
dentry->d_flags = 0;
13051296
spin_lock_init(&dentry->d_lock);
13061297
seqcount_init(&dentry->d_seq);
13071298
dentry->d_inode = NULL;
@@ -1603,10 +1594,9 @@ struct dentry *d_obtain_alias(struct inode *inode)
16031594
tmp->d_inode = inode;
16041595
tmp->d_flags |= DCACHE_DISCONNECTED;
16051596
list_add(&tmp->d_alias, &inode->i_dentry);
1606-
bit_spin_lock(0, (unsigned long *)&tmp->d_sb->s_anon.first);
1607-
tmp->d_flags &= ~DCACHE_UNHASHED;
1597+
spin_lock_bucket(&tmp->d_sb->s_anon);
16081598
hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon);
1609-
__bit_spin_unlock(0, (unsigned long *)&tmp->d_sb->s_anon.first);
1599+
spin_unlock_bucket(&tmp->d_sb->s_anon);
16101600
spin_unlock(&tmp->d_lock);
16111601
spin_unlock(&inode->i_lock);
16121602
security_d_instantiate(tmp, inode);
@@ -2087,7 +2077,7 @@ static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b)
20872077
{
20882078
BUG_ON(!d_unhashed(entry));
20892079
spin_lock_bucket(b);
2090-
entry->d_flags &= ~DCACHE_UNHASHED;
2080+
entry->d_flags |= DCACHE_RCUACCESS;
20912081
hlist_bl_add_head_rcu(&entry->d_hash, b);
20922082
spin_unlock_bucket(b);
20932083
}

‎include/linux/dcache.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct dentry_operations {
197197
* typically using d_splice_alias. */
198198

199199
#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
200-
#define DCACHE_UNHASHED 0x0010
200+
#define DCACHE_RCUACCESS 0x0010 /* Entry has ever been RCU-visible */
201201
#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020
202202
/* Parent inode is watched by inotify */
203203

@@ -384,7 +384,7 @@ extern struct dentry *dget_parent(struct dentry *dentry);
384384

385385
static inline int d_unhashed(struct dentry *dentry)
386386
{
387-
return (dentry->d_flags & DCACHE_UNHASHED);
387+
return hlist_bl_unhashed(&dentry->d_hash);
388388
}
389389

390390
static inline int d_unlinked(struct dentry *dentry)

0 commit comments

Comments
 (0)