Less known Solaris Features: CacheFS - Part 4: The Cache

Okay, we have a working CacheFS mount but where and how is the stuff cached by the system. Let´s have a look at the cache.

[root@gandalf:/var/cachefs/cache1]# ls -l
total 6
drwxrwxrwx   5 root     root         512 Aug 18 10:54 0000000000044e30
drwx------   2 root     root         512 Aug 11 08:11 lost+found
lrwxrwxrwx   1 root     root          16 Aug 11 08:18 theoden:_export_files:_files -> 0000000000044e30

To ensure that caches using a single cache directory of the time aren´t mixing up their data, they are divided at this place. At first a special directory is generated and at second a more speaking name is liked to this. It´s pretty obvious how this name is generated.=theoden:_export_files:_files can be easily translated to theoden:/export/files mounted at /files Let´s assume we´ve used the cache for another filesystem (e.g. /export/binaries on theoden</ode> mounted to /binaries):

[root@gandalf:/var/cachefs/cache1]# ls -l
total 10
drwxrwxrwx   5 root     root         512 Aug 18 10:54 0000000000044e30
drwxrwxrwx   3 root     root         512 Aug 18 11:18 0000000000044e41
drwx------   2 root     root         512 Aug 11 08:11 lost+found
lrwxrwxrwx   1 root     root          16 Aug 18 11:18 theoden:_export_binaries:_binaries -> 0000000000044e41
lrwxrwxrwx   1 root     root          16 Aug 11 08:18 theoden:_export_files:_files -> 0000000000044e30

With this mechanism, the caches are seperated in their respective directories … no mixing up. When we dig down a little bit deeper to the directories, we will see an additional layer of directories. This is necessary to prevent a situation where a directory contains too much files and thus slows down.

[root@gandalf:/var/cachefs/cache1/0000000000044e30/0000000000044e00]# ls -l
total 62
-rw-rw-rw-   1 root     root           0 Aug 18 10:54 0000000000044e66
-rw-rw-rw-   1 root     root        1683 Aug 11 08:24 0000000000044eaa
-rw-rw-rw-   1 root     root       29417 Aug 11 08:22 0000000000044eba

When you look in on of this file, you will see, that those files are just a copy of the original files:

[root@gandalf:/var/cachefs/cache1/0000000000044e30/0000000000044e00]# cat 0000000000044eaa 
[...]
This page is part of the PCRE HTML documentation. It was generated automatically
from the original man page. If there is any nonsense in it, please consult the
man page, in case the conversion went wrong.
[...]
[root@gandalf:/var/cachefs/cache1/0000000000044e30/0000000000044e00]#

At last, the structure of CacheFS for storing the cache is pretty simple. The metadata of the cache (what file is stored in which location) is stored in the root directory of the cache in some dot-files:

[root@gandalf:/var/cachefs/cache1]# [root@gandalf:/var/cachefs/cache1]# ls -al .*
-rw-------   1 root     root          48 Aug 11 08:11 .cfs_label
-rw-------   1 root     root          48 Aug 11 08:11 .cfs_label.dup
-rwx------   1 root     root           0 Aug 11 08:11 .cfs_lock
-rw-------   1 root     root     109879296 Aug 18 10:54 .cfs_resource
-rw-r--r--   1 root     root           4 Aug 11 08:11 .cfs_unmnt
-rw-r--r--   1 root     root          22 Aug 11 08:11 .nsr
[root@gandalf:/var/cachefs/cache1]

All this dot-files in conjunction contain all the metadata necessary to manage and controle the cache.