6

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?

2 Answers 2

5

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.

2
  • So if the file is frequently accessed (read/write) it is very likely if some process asks for the file inode it will be in the cache and not disk I/O required. Correct? Commented Mar 1, 2020 at 18:25
  • 1
    Yes, the file inode is highly likely to be in the cache (which also helps with metadata updates — they don’t all get written to disk). Commented Mar 1, 2020 at 21:57
2

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.