[Next] [Previous] [Up] [Top] [Contents]
CHAPTER 5 File System Management
5.6 Setting up a Cache File System
The cache file system, cachefs, is available on Sun's starting with Solaris 2.3. It is intended to reduce access time to NFS or slow media (e.g. CDROM) file systems by storing the files on local disk when they're accessed the first time. Subsequent calls for that file will access the cache on the local disk. The original file system is the back file system and it's files are the back files. The file system used by cachefs is the front file system and it's files are the front files. You set up a cachefs using all or part of an existing file system, or a new partition. This front file system must be a UFS file system. It has to be writable, as a read-only file system would not allow caching. Also, quotas should not be set on this file system as they interfere with the control mechanisms of cachefs.
You create the cache with the cfsadmin command, specifying the local cache directory and the resource parameters to use for the cache. You then mount the file system you want cached using the -F cachefs option. By default cfsadmin uses the following resource parameters:
Cache Parameter Default Value
maxblocks 90%
minblocks 0%
threshblocks 85%
maxfiles 90%
minfiles 0%
threshfiles 85%
where maxblocks sets the maximum number of blocks (in percentage) allowed for cachefs, and maxfiles sets the maximum number of inodes (in percentage) that can be used by cachefs in the front file system. These percentages refer to total available on the front file system, before reduction due to reserving free space for root-only write access. If the front file system is used for purposes in addition to cachefs you may not be able to achieve these maximum values, as there may be fewer resources available. The minblocks and minfiles parameters set minimum values for blocks and files, respectively, and when these minimum values have been reached on the front file system then threshblocks and threshfiles will be checked. Cachefs can only claim more than the minimum when the percentage of available resources remaining is greater than the threshold values. If the minimum, maximum, and threshold values are identical, cachefs is allowed to grow to the maximum, so long as the resources are available in the front file system.
So to set up a cachefs file system:
- 1. Use cfsadmin to create the cache directory and set the cache file system parameters. The cache directory should not exist prior to executing this command. Create the cache directory and set starting parameters with:
# cfsadmin -c -o maxblocks=80,minblocks=30,threshblocks=60 /local/cache
- Modify cache parameters with cfsadmin. You can only increase the cache size. To decrease it you need to remove and recreate the cache. To modify parameters, e.g.:
# cfsadmin -u -o parameter1=value1,parameter2=value2 /local/cache
- Mount the UFS back file system from the command line, e.g.:
# mount -F cachefs -o backfstype=nfs,cachedir=/local/cache server:/export/home /home
- Mount a CDROM back file system, from the command line. If the file system is already mounted, as is will be if you're running the volume manager daemon, you need to specify the backpath options, e.g.:
mount -F cachefs -o backfstype=hsfs,cachedir=/local/cache,ro,backpath=/cdrom/cd_name \ /cdrom/cd_name /mount/point
- To mount a file system from /etc/vfstab use entries similar to:
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
server:/export/home /local/cache /home cachefs 2 yes rw,backfstype=nfs
- Display cachefs information, including caching parameters and back file systems, after specifying the cache directory, e.g.:
# cfsadmin -l /local/cache
cfsadmin: list cache FS information
maxblocks 90%
minblocks 0%
threshblocks 85%
maxfiles 90%
minfiles 0%
threshfiles 85%
maxfilesize 3MB
server:_export_home
_cdrom_cd_name
- Delete a cached file system with cfsadmin, specifying the cache_id (or all) and the cache directory. First unmount the directory (umount), second delete the cachefs entry (cfsadmin -d), third update the resource counts for the cache (fsck), e.g.:
# umount /home
# cfsadmin -d server:_export_home /local/cache
# fsck -F cachefs /local/cache
The fsck command above will automatically correct consistency problems without user intervention. This is run automatically for you at boot time or when you mount the file system.
To delete all file systems in a cache directory, and the directory itself, use:
# cfsadmin -d all /local/cache
/home auto_home -fstype=cachefs, cache=/local/cache
The cachefsstat command will report the statistics for the Cache File System. It will display information about the hit rate, consistency checks, and number of modifications to files in the cache.
Unix System Administration - 8 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]