Skip to content

Commit ca0d620

Browse files
mjguzikbrauner
authored andcommitted
dcache: touch up predicts in __d_lookup_rcu()
Rationale is that if the parent dentry is the same and the length is the same, then you have to be unlucky for the name to not match. At the same time the dentry was literally just found on the hash, so you have to be even more unlucky to determine it is unhashed. While here add commentary while d_unhashed() is necessary. It was already removed once and brought back in: 2e32180 ("Revert "vfs: remove unnecessary d_unhashed() check from __d_lookup_rcu"") Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20251127131526.4137768-1-mjguzik@gmail.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 003a660 commit ca0d620

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

fs/dcache.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,11 +2300,20 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
23002300
seq = raw_seqcount_begin(&dentry->d_seq);
23012301
if (dentry->d_parent != parent)
23022302
continue;
2303-
if (d_unhashed(dentry))
2304-
continue;
23052303
if (dentry->d_name.hash_len != hashlen)
23062304
continue;
2307-
if (dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0)
2305+
if (unlikely(dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0))
2306+
continue;
2307+
/*
2308+
* Check for the dentry being unhashed.
2309+
*
2310+
* As tempting as it is, we *can't* skip it because of a race window
2311+
* between us finding the dentry before it gets unhashed and loading
2312+
* the sequence counter after unhashing is finished.
2313+
*
2314+
* We can at least predict on it.
2315+
*/
2316+
if (unlikely(d_unhashed(dentry)))
23082317
continue;
23092318
*seqp = seq;
23102319
return dentry;

0 commit comments

Comments
 (0)