内に含ま
その他のドキュメント
サポート リソース
| PDF 文書ファイルをダウンロードする
The Cache File System
5
- This chapter contains the following sections:
-
Cache File System Concepts
- A cache is a temporary storage area for data. The Cache File System (CacheFS) enables you to use disk drives on local workstations to store frequently used data from a remote file system or CD-ROM. The data stored on the local disk is the cache.
- When a file system is cached, the data is read from the original file system and stored on the local disk. The reduction in network traffic improves performance and, if the remote file system is on a storage medium with slower response time than the local disk (such as CD-ROM), caching provides an additional performance gain.
- CacheFS can use all or part of a local disk to store data from one or more remote file systems. A user accessing a file does not need to know whether the file is stored in a cache or is being read from the original file system. The user opens, reads, and writes files as usual.
- The original file system, which may require network traffic to access, is called the back file system and files in it are back files. The cached file system resides on the local disk and files in it are cached files. The cache directory is a directory on the local disk where the data for the cached file system is stored. The file system in which the cache directory resides is called the front file system and its files are front files.
Resource Management
- When you set up a cache, you can use all or part of an existing file system. You can also set up a new slice to be used by CacheFS.
- In addition, when you create a cache, you can specify the percentage of resources, such as number of files or blocks, that CacheFS can use in the front file system. The configurable cache parameters are discussed in the section "Cache Parameters" on page 81.
Front File System Requirements
- CacheFS requires a UFS file system for the front file system. The front file system can be on a metadevice, which is a grouping of two or more physical devices accessed as a single device.
- You can use an existing UFS file system for the front file system or you can create a new one. Using an existing file system is the quickest way to set up a cache. Dedicating a file system exclusively to CacheFS gives you the greatest control over the file system space available for caching. For information on creating and mounting UFS file systems, see Chapter 3, "Mounting and Unmounting File Systems."
-
Caution - Do not make the front file system read-only and do not set quotas on it. A read-only front file system prevents caching and file system quotas interfere with control mechanisms built into CacheFS.
Setting Up a Cached File System
- There are two steps to setting up a cached file system:
-
-
You must create the cache with the cfsadmin command. See "Creating a Cache" on page 81.
-
You must mount the file system you want cached using the -F cachefs option to the mount command. See "Mounting a Cached File System" on page 86.
Administering a Cache
- You use the cfsadmin command to perform the following tasks:
-
- Create a cache
- Set or modify cache parameters
- Display information about a cache and the cached file systems
- Delete a cache
- The following sections describe how to perform each of these tasks.
Creating a Cache
- To create a cache:
-
* Type cfsadmin -c directory_name and press Return.
- The following example creates a cache and creates the cache directory /local/mycache. You must make sure the cache directory does not already exist.
-
# cfsadmin -c /local/mycache
|
- This example uses the default cache parameter values. The CacheFS parameters are described in the section "Setting Cache Parameters" on page 83. See the cfsadmin(1M) manual page for more information on cfsadmin options.
Cache Parameters
- The default values for the cache parameters are for a cache that uses the entire front file system for caching. To limit the cache to only a portion of the front file system, you should change the parameter values.
-
Table 5-1 shows the parameters for space and file allocation.
-
Table 5-1
| Parameters for Space Allocation | Parameters for File Allocation |
| maxblocks | maxfiles |
| minblocks | minfiles |
| threshblocks | threshfiles |
-
Table 5-2 shows the default values for the cache parameters. The default values for parameters devote the full resources of the front file system to caching.
-
Table 5-2
| Cache Parameter | Default Value |
| maxblocks | 90 % |
| minblocks | 0 % |
| threshblocks | 85 % |
| maxfiles | 90 % |
| minfiles | 0 % |
| threshfiles | 85 % |
- The maxblocks parameter sets the maximum number of blocks, expressed as a percentage, that CacheFS is allowed to claim within the front file system. The maxfiles parameter sets the maximum percentage of available inodes (number of files) CacheFS can claim.
-
Note - The maxblocks and maxfiles parameters do not guarantee the resources will be available for CacheFS--they set maximums. If you allow the front file system to be used for other purposes than CacheFS, there may be fewer blocks or files available to CacheFS than you intend.
- The minblocks parameter does not guarantee availability of a minimum level of resources. The minblocks and threshblocks parameters work together. CacheFS can claim more than the percentage of blocks specified by minblocks
- only if the percentage of available blocks in the front file system is greater than threshblocks. The minfiles and threshfiles parameters work together in the same fashion.
- The threshfiles and threshblocks values apply to the entire front file system, not file systems you have cached under the front file system. The threshblocks and threshfiles values are ignored until the minblocks and minfiles values have been reached.
-
Note - Using the whole front file system solely for caching eliminates the need to change the maxblocks, maxfiles, minblocks, minfiles, threshblocks, or threshfiles parameters.
- When the minimum, maximum, and threshold values are identical, CacheFS allows the cache to grow to the maximum size specified--if you have not reduced available resources by using part of the front file system for other storage purposes.
Setting Cache Parameters
- To set parameters for a cache:
-
* Type cfsadmin -c -o parameter_list cache_directory and press Return.
- The parameter_list has the following form:
-
parameter_name1=value,parameter_name2=value,...
- The parameter names are listed in Table 5-1 on page 82. You must separate multiple arguments to the -o option with commas.
-
Note - The maximum size of the cache is by default 90% of the front file system resources. Performance deteriorates significantly if a UFS file system exceeds 90% capacity.
- The following example creates a cache named /local/cache1 that can use up to 80% of the disk blocks in the front file system and can grow to use 55% of the front file system blocks without restriction unless 60% (or more) of the front file system blocks are already in use.
-
# cfsadmin -c -o maxblocks=80,minblocks=55,threshblocks=60 /local/cache1
|
- The following example creates a cache named /local/cache2 that can use up to 75% of the files available in the front file system.
-
# cfsadmin -c -o maxfiles=75 /local/cache2
|
- The following example creates a cache named /local/cache3 that can use 75% of the blocks in the front file system, that can use 50% of the files in the front file system without restriction unless total file usage already exceeds 60%, and that has 70% of the files in the front file system as an absolute limit.
-
# cfsadmin -c -o maxblocks=75,minfiles=50,threshfiles=60,maxfiles=70 /local/cache3
|
Modifying Parameters
-
Note - Before changing parameters for a cache, you must unmount all file systems in the cache directory with the umount command.
- To change the value of one or more parameters:
-
* Type cfsadmin -u -o parameter_list cache_directory and press Return.
-
Note - You can only increase the size of a cache, either by number of blocks or number of inodes. If you want to make a cache smaller, you must remove it and re-create it with new values.
- The following example unmounts /local/cache3 and changes the threshfiles parameter to 65 percent:
-
# umount mount_point
# cfsadmin -u -o threshfiles=65 /local/cache3
|
Displaying Information About Cached File Systems
- To display information about all file systems cached under the specified cache directory:
-
* Type cfsadmin -l cache_directory and press Return.
- The following example shows information about the cache directory named /local/cache1:
-
# cfsadmin -l /local/cache1
maxblocks 90%
minblocks 90%
threshblocks 90%
maxfiles 90%
minfiles 90%
threshfiles 90%
maxfilesize 3MB
mnt_c0t1d0s7
mnt1_man
#
|
- In this example, two file systems are cached in /local/cache1. The last two lines display the cache IDs of the two cached file systems.
Deleting Cached File Systems
-
Note - Before deleting a cached file system, you must unmount all the cached files systems for that cache directory.
- To delete a file system in a cache:
-
-
* Type cfsadmin -d cache_id cache_directory and press Return.
- The cache ID is part of the information returned by cfsadmin -l. After deleting one or more of the cached file systems, you must run the fsck_cachefs command to correct the resource counts for the cache.
- The following example unmounts a cached file system, deletes it from the cache, and runs fsck_cachefs.
-
# umount /usr/work
# cfsadmin -d _dev_dsk_c0t1d0s7 /local/cache1
# fsck -F cachefs /local/cache1
|
- You can delete all file systems in a particular cache by using all as an argument to the -d option. The following command deletes all file systems cached under /local/cache1:
-
# cfsadmin -d all /local/cache1
|
- The all argument to -d also deletes the specified cache directory.
Mounting a Cached File System
- There are three ways to mount a file system in a cache:
-
- Using the mount command
- Creating an entry for the file system in the /etc/vfstab file
- Using autofs
- See NFS Administration Guide for more information on mounting a cached file system with autofs.
Using mount to Mount a Cached File System
- To mount a file system in a cache:
-
* Type mount -F cachefs -o backfstype=type,cachedir=cache_directory back_filesystem mount_point and press Return.
- The arguments used with the -o option are described in Table 5-3 on page 89. See the mount_cachefs(1M) manual page for more information about the arguments used when mounting a cached file system.
- For example, the following command makes the file system merlin:/docs available as a cached file system named /docs:
-
# mount -F cachefs -o backfstype=nfs,cachedir=/local/cache1 merlin:/docs /docs
|
Mounting a Cached File System That Is Already Mounted
- You use the backpath argument when the file system you want to cache has already been mounted. backpath specifies the mount point of the mounted file system. When the backpath argument is used, the back file system must be read-only. If you want to write to the back file system, you must unmount it before mounting it as a cached file system.
- For example, if the file system merlin:/doc is already NFS-mounted on /nfsdocs, you can cache that file system by giving that path name as the argument to backpath, as shown in the following example:
-
# mount -F cachefs -o backfstype=nfs,cachedir=/local/cache1,backpath=/nfsdocs merlin:/doc
/doc
|
-
Note - There is no performance gain in caching a local UFS disk file system.
Mounting a CD-ROM as a Cached File System
- So far, examples have illustrated back file systems that are NFS-mounted, and the device argument to the mount command has taken the form server:file_system. If the back file system is a High Sierra or Rockridge file system, the device argument is the CD-ROM device in the /cdrom directory. The file system type is either hsfs or rockridge.
- The following example illustrates caching a High Sierra back file system on the device /cdrom/cdrom_name as /doc in the cache /local/cache1:
-
# mount -F cachefs -o backfstype=hsfs,cachedir=/local/cache1,ro, backpath=/cdrom/cdrom_name \
/cdrom/cdrom_name /doc
|
- Because you cannot write to the CD-ROM, the ro argument is specified to make the cached file system read-only. The arguments to the -o option are explained in Table 5-3.
- You must specify the backpath argument because Volume Management automatically mounts the CD-ROM when it is inserted. The mount point is in the /cdrom directory and is determined by the name of the CD-ROM. The special device to mount is the same as the value for the backpath argument.
Consistency Checking
- To ensure that the cached directories and files are kept up to date, CacheFS periodically checks consistency of files stored in the cache. To check consistency, CacheFS compares the current modification time to the previous modification time; if the modification times are different, all data and attributes for the directory or file are purged from the cache and new data and attributes are retrieved from the back file system.
- When an operation on a directory or file is requested, CacheFS checks to see if it is time to verify consistency. If so, CacheFS obtains the modification time from the back file system and performs the comparison.
- CacheFS calculates the next time to perform a consistency check for directories as follows:
- X = time-of-day -- current-modification-time Y = MAX(X, acdirmin)
- Z = MIN (Y, acdirmax) time-of-next-check = Z + time-of-day
- The same calculation is performed to determine the next time to check consistency for files, except that acregmin is substituted for acdirmin in the MAX calculation and acregmax is substituted for acdirmax in the MIN calculation.
- The default value for acdirmin, acdirmax, acregmin, and acregmax is 30 seconds. acdirmin, acdirmax, acregmin, and acregmax are parameters to the mount command and can be changed when the file system is mounted. See Table 5-3 for more information on mount parameters.
Additional mount Arguments
-
Table 5-3 describes the arguments that can be used with the -o option of mount.
-
Table 5-3 -o mount
| Parameter | Description |
| acdirmax=n | Used in determining the next time to consistency. See "Consistency Checking" on page 88. The default is 30 seconds. |
| acdirmin=n | Used in determining the next time to consistency. See "Consistency Checking" on page 88. The default is 30 seconds. |
| acregmax=n | Used in determining the next time to consistency. See "Consistency Checking" on page 88. The default is 30 seconds. |
| acregmin=n | Used in determining the next time to consistency. See "Consistency Checking" on page 88. The default is 30 seconds. |
| actimeo=n | Sets acregmin, acregmax, acdirmin, and acdirmax to n. |
| backfstype | Specifies the file system type of the back file system. |
| backpath | Specifies the mount point of the back file system. Use only if the back file system is already mounted. |
| cachedir | Specifies the name of the cache directory. |
| cacheid | Allows you to assign a string to identify each separate cached file system. If you do not specify a cacheid, CacheFS generates one. You need the cacheid when you delete a cached file system with cfsadmin -d. A cacheid you choose will be easier to remember than one automatically generated. The cfsadmin command with the -l option includes the cacheid in its display. |
-
Table 5-3 -o mount
| Parameter | Description |
| local-access | Improves performance by having CacheFS check the mode bits. By default, the back file system interprets the mode bits used for access checking to ensure data integrity. Do not use this argument if you are running secure NFS. |
| noconst | Disables consistency checking between the front and back file systems. Use noconst when the back file system and cache file system are read-only. Otherwise, always allow consistency checking. The default is to enable consistency checking. If none of the files in the back file system will be modified, you can use the noconst option to mount when mounting the cached file system. Changes to the back file system may not be reflected in the cached file system.
|
| rw | ro | Make the cached file system read-write or read-only. The default is read-write. |
suid |
nosuid | Allow or disallow setuid execution. The suid argument is the default. For an explanation of
setuid execution, see Security, Performance, and Accounting Administration. |
| write-around | non-shared | Prevents inconsistencies resulting from someone else writing to the back file system while a user is working with the same files in a cache. In this mode, each write is made directly to the back file, and the front file is purged from the cache. You bypass, or "write around," the cache. The file can be brought back into the cache, but writing directly to the back file ensures that no one opens a file that is out-of-date because it was changed while it was in the cache. write-around mode also protects against the reverse situation: opening a cached file right before someone writes to the back file and thus starting with an out-of-date version. Like NFS, CacheFS enforces consistency by checking at regular intervals to see if any cached file has been changed in the back file system. If it has, it is purged from the cache, so that the next time a user accesses the file, the current version is retrieved from the back file system. write-around mode is the default. Use non-shared mode when only one user at a time is writing to a particular set of files in the cache. Because it is assumed that no one else will write concurrently to the same file, or concurrently modify directories, writes are made to both the front and back files, and the files the user is working with remain active in the cache.
|
Creating a vfstab Entry for Cached File Systems
- As with other file system types, you can put an entry in the /etc/vfstab file for a cached file system to mount the cached file system automatically every time the system boots. The /etc/vfstab file has the following seven fields:
-
- Device to mount
- Device to fsck
- Mount point
- File system type
-
fsck pass
- Mount at boot
- Mount options
- Enter the special device name of the back file system as the device to mount. For NFS file systems, the entry takes the form server:path. The device to fsck is the cache directory path. The mount point is the mount point of the cached file system. The following example shows an entry for a cached file system (the lines beginning with hash marks (#) are comments):
-
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
server1:/usr/abc /cache1 /mydocs cachefs2 yes rw,backfstype=nfs,cachedir=/cache1
|
- See "The Virtual File System Table" on page 26 for more information on vfstab entries.
Checking a Cached File System
- The fsck command is used to check the integrity of cached file systems. The CacheFS version of fsck automatically corrects problems without requiring user interaction.
- To check a cached file system:
-
* Type fsck -F cachefs cache_directory and press Return.
- The following example checks the cache directory /local/cache1:
-
# fsck -F cachefs /local/cache1
|
- You should not need to run fsck manually for cached file systems; fsck is run automatically at boot time or when the file system is mounted.
- Two options are available for the CacheFS version of fsck: -m and -o noclean. The -m option causes fsck to check the specified file system without making any repairs. The -o noclean option forces a check of the file system. See the fsck_cachefs(1M) man page for more information.
|
|