Linux – What are the list of different type of caches in Linux file systems

cachefilesystemslinux

I've been reading this page, http://www.tldp.org/LDP/tlk/fs/filesystem.html, and I have trouble organizing all the different caches it's talking about. Especially, I don't understand the different scenarios of when each are used.

From the way I understood, there are

  1. Buffer cache:
    Used by the VFS. Says that data buffers are put in the cache. I don't know if data buffers are the only thing in the Buffer cache. Also, I'm not sure if it's only used by the VFS.

  2. VFS inode cache: After accessing a file, its inode is put into the cache for faster look up. I'm not sure if having the inode information means that the system no longer needs to go down the file system tree to the location (As in, if a file is under Documents, it will no longer need to reach Documents from root directory).

  3. EXT2 (or other filesystems that use inodes) inode cache: Does this exist? It's never mentioned, but I'm assuming it exists.

  4. VFS directory cache: Stores "directory name to inode" mappings. As the following quote says from the link, apparently you can get a VFS inode just with the VFS cache:

    If there is no entry in the directory cache, the real file system
    gets the VFS inode either from the underlying file system or from the
    inode cache.

    Then why do we even need a directory cache? Is this related to the dentry cache?

  5. Dentry cache: Why is this not mentioned in the above article? Is it not related?

Best Answer

Then why do we even need a directory cache?

It's just another level of caching. Even if all the path components can be found in other caches, it still takes time to traverse them all. So the directory cache provides a way to cache whole paths and avoid looking things up path element by path element from the root each time.

Related Question