|
|
Log in / Subscribe / Register

Are negative dentries the right abstraction in the first place?

Are negative dentries the right abstraction in the first place?

Posted Jul 4, 2026 20:56 UTC (Sat) by NYKevin (subscriber, #129325)
Parent article: Limiting negative dentries

Whenever I hear about negative dentries, the first thing I think of is a bloom filter. A bloom filter isn't quite the right data structure for this problem, or at least I don't think it is, but it's surprisingly close.

A bloom filter is a probabilistic data structure with two operations: insert and query. You insert keys (usually strings), and can later query for whether a given key was inserted. The filter will return either "maybe" or "no." This isn't useful as a direct substitute for negative dentries, because (assuming the keys represent non-existing dentries) both answers require us to take the slow path. We would need a data structure that returns "maybe" or "yes" (so that we can skip the slow path on a "yes").

Unfortunately, all of the materials I found on the web suggest that the closest equivalent to such an "inverse Bloom filter" is some kind of cache, which is exactly what negative dentries already are.

So then the question is whether we're allowed to make more substantial refactors. For example, we might give each directory a lazily-initialized bloom filter. Initially, the directory would use negative dentries as in the current design. If the directory is ever fully scanned, however, we would take the opportunity to initialize the bloom filter with all of the *positive* dentries we find on disk, then delete all of its negative dentries and consult the bloom filter instead of looking for negative dentries. We would then need to keep the bloom filter up to date by inserting newly created dentries as we go. If the filter gets too full, we would erase it and go back to using negative dentries until it can be re-initialized. As a bonus, newly-created directories are initially empty, and can be initialized with an empty bloom filter immediately.

Obviously, there are serious concurrency hazards to this approach. My assumption is that the filesystem is capable of guarding against those hazards without a serious performance penalty (because it already must do so for regular read-write conflicts anyway). But I might be wrong about that.


to post comments

Are negative dentries the right abstraction in the first place?

Posted Jul 5, 2026 6:43 UTC (Sun) by fraetor (subscriber, #161147) [Link]

I'd be somewhat concerned about potential impact on reading positive dentries, especially given that should be the common case. The cost of a bloom filter lookup should be small. but without looking at the code I assume the reading of dentries is already very optimised.

The other problem I see is how to delete a dentrie, as you can't remove something from a bloom filter without rebuilding it entirely. While the probabilistic nature of a bloom filter means you would need to handle that case anyway (its the maybe), a common use case for a negative dentrie would be for a small number of entries queried very frequently, which would lose the performance benefit if deleted. But perhaps these frequently queried files wouldn't have existed in the first place.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds