I'm confused because all dentries have pointers to inode objects. As far as I know, you always look through dentries to find your inode. Then, why is there an inode cache?


You're asking about the inode cache implemented as part of the Linux Virtual File System (VFS). Caches, including the inode cache are not just used to provide functionality, like accessing inode entries, as there are other mechanisms for this as you point out.

Caches can be used to improve performance and in this case looking up inode data from an io device such as a disk is very slow, so storing previously accessed inode data in memory makes file system access much quicker.


Directory entries and inodes are different objects, so they get separate caches: the dentry cache in dcache.c, the inode cache in inode_hashtable in inode.c. But the inode cache is a slave to the dcache:

The dcache is a master of the icache — whenever a dcache entry exists, the inode will always exist.

As you no doubt know already, the point of these caches is to increase performance and avoid constant disk accesses, especially for the inode which can be updated many times while a file is open.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.