On Tue, Jan 14, 2025 at 09:08:38AM +0530, Shyam Prasad N wrote: > The VFS layer maintains a dentry cache which gets populated during > access of dentries (either during readdir/getdents or during lookup). > This dentries within a directory actually forms the address space for > the directory, which is read sequentially during getdents. For network > filesystems, the dentries are also looked up during revalidate. > > During sequential getdents, it makes sense to perform a readahead > similar to file reads. Even for revalidations and dentry lookups, > there can be some heuristics that can be maintained to know if the > lookups within the directory are sequential in nature. With this, the > dentry cache can be pre-populated for a directory, even before the > dentries are accessed, thereby boosting the performance. This could > give even more benefits for network filesystems by avoiding costly > round trips to the server. > > NFS client already does a simplistic form of this readahead by > maintaining an address space for the directory inode and storing the > dentry records returned by the server in this space. However, this > dentry access mechanism is so generic that I feel that this can be a > part of the VFS/VM layer, similar to buffered reads of a file. Also, > VFS layer is better equipped to store heuristics about dentry access > patterns. You do realize that for local filesystems it'll actually hurt anything that does *not* stat() or open() everything it runs across, right? Directories do not contain inode metadata; on lookup you do want that - for given object. So you need to get the on-disk inode read, so that in-core inode could be set up. Adding that on readdir for every directory entry you run across can be thoroughly unpleasant. It should be up to filesystem. It's not just the access pattern. Imagine the joy of doing that on e.g. NFSv2; would you agree that "I'd have to send a bleeding GETATTR for every entry in READDIR response" is an important detail when deciding whether we want to do dcache prepopulation? Ideas regarding better infrastructure filesystems could use would be interesting, but decision whether to use that or not in any given case belongs in filesystem itself, *not* in upper layers.