Skip to contentSkip to conversation

dcache: predict the name matches if parent and length also match

PATCH In review Mateusz Guzik 2 participants 3 messages Nov 27, 2025 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dcache: predict the name matches if parent and length also match

dentry_cmp() has predicts inside, but they were not enough to convince the compiler.

As for difference in asm, some of the code is reshuffled and there is one less unconditional jump to get there.

---

i know it's late, but given the non-semantic-modifying nature of the change, i think it can still make it for 6.19

 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -1
index 23d1752c29e6..bc84f89156fa 100644
@@ -2346,7 +2346,7 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
 			continue;
 		if (dentry->d_name.hash_len != hashlen)
 			continue;
-		if (dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0)
+		if (unlikely(dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0))
 			continue;
 		*seqp = seq;
 		return dentry;
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Mateusz Guzik

dentry_cmp() has predicts inside, but they were not enough to convince the compiler.

As for difference in asm, some of the code is reshuffled and there is one less unconditional jump to get there.

I've checked and on my laptop the dentry hash table has ~2 million entries. This means we'll be getting hash collisions within a directory for directories on the order of thousands entries. And until we get to hundreds of thousands of entries in a directory, the collisions of entries will be still rare. So I guess that's rare enough. Feel free to add:

Honza

Quoted 24 lines

---

i know it's late, but given the non-semantic-modifying nature of the change, i think it can still make it for 6.19

 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -1
index 23d1752c29e6..bc84f89156fa 100644
@@ -2346,7 +2346,7 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
 			continue;
 		if (dentry->d_name.hash_len != hashlen)
 			continue;
-		if (dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0)
+		if (unlikely(dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0))
 			continue;
 		*seqp = seq;
 		return dentry;
Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 8 lines · Jan Kara
Quoted 6 lines · Mateusz Guzik

dentry_cmp() has predicts inside, but they were not enough to convince the compiler.

As for difference in asm, some of the code is reshuffled and there is one less unconditional jump to get there.

Quoted 8 lines
Quoted 1 line

I've checked and on my laptop the dentry hash table has ~2 million entries. This means we'll be getting hash collisions within a directory for directories on the order of thousands entries. And until we get to hundreds of thousands of entries in a directory, the collisions of entries will be still rare. So I guess that's rare enough. Feel free to add:

collisions with the same parent are a given, but with the same length on top should be rare

Quoted 1 line

thanks, but see v2 :)
https://lore.kernel.org/linux-fsdevel/[email protected]/T/#u

Quoted 30 lines

Honza

Quoted 22 lines

---

i know it's late, but given the non-semantic-modifying nature of the change, i think it can still make it for 6.19

 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -2
index 23d1752c29e6..bc84f89156fa 100644
@@ -2346,7 +2346,7 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
                      continue;
              if (dentry->d_name.hash_len != hashlen)
                      continue;
-             if (dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0)
+             if (unlikely(dentry_cmp(dentry, str, hashlen_len(hashlen)) != 0))
                      continue;
              *seqp = seq;
              return dentry;
--
Quoted 2 lines

2.34.1

--
Jan Kara <[email protected]>
SUSE Labs, CR