- 论坛徽章:
- 0
|
找了好久都没有cachefs的资料,9,10里面好像没这东西,最后还是在8里面找到
The Cache File System (CacheFS) is a client-side service that provides the ability to cache a
remotely accessed NFS resource locally on the NFS client. Doing so not only speeds up client
access to the data but also decreases network traffic and load on the NFS server.
After you create a cache, a remote NFS resource can be mounted “in” the cache. The first time the
NFS resource is accessed, data is copied from the remote NFS server into the local cache.
Subsequent accesses are from the local cache instead of the remote NFS server. Like other types
of file systems, the remote NFS resource can be mounted manually using the mount command, at
system boot, by adding it to the /etc/vfstab file, or as needed using the AutoFS mechanism
(described in the previous section).
Note
The root (/) and /usr file systems cannot be cached using the CacheFS mechanism.
However, these two file systems can be cached using the AutoClient configuration, which is
briefly described in Chapter 13.
Configuring a Cache
The cfsadmin(1M) command is used to create, check, tune, and delete caches. The
cachefsstat(1M) command can also be used to display cache statistics.
You specify the -c command-line argument to create a cache, followed by the full pathname of a
directory to be used for the cache. In addition, multiple options (separated by commas) can be
specified using the -o command-line argument. The following listing uses the cfsadmin command
to create a cache under the /cache directory. The size of the largest file that can be cached is set
to 10MB:
# cfsadmin -c -o maxfilesize=10 /cache
351
#
To list the file systems mounted in the cache and the cache status, use the -l command-line
argument. Additional command-line arguments include -s to perform a consistency check, -u to
update cache parameters, and -d to delete a cache. All of these command-line arguments should
be followed by the full pathname of the cache directory.
Mounting a remote NFS resource in the cache using the mount command requires specifying the
remote file system, the local cache, and a local mount point.
The -F command-line argument should be used to identify the file system type as CacheFS. In
addition, at least two cache-specific mount options need to be specified using the -o
command-line argument: backfstype, which is used to identify the type of file system being
mounted (typically NFS); and cachedir, which is used to identify the cache directory. The following
listing uses the mount command to mount the /export/home file system from the host sparc20 on
the /home mount point (referred to as the front file system) using /cache as the cache directory.
The line is wrapped to improve readability:
# mount -F cachefs -o backfstype=nfs,cachedir=/cache
sparc20:/export/home /home
#
Checking the Status of a Cache
To display the status of a cached file system, use the cfsadmin command and specify the -l
command-line argument followed by the name of the cache.
The following information about the cache is displayed:
· maxblocks—The maximum amount of storage space the cache can use (expressed as a
percentage of blocks in the front file system).
· minblocks—The minimum amount of storage space the cache can use (expressed as a
percentage of blocks in the front file system).
· threshblocks—The threshold at which additional resources cannot be claimed after
minblocks is reached (expressed as a percentage of blocks in the front file system).
· maxfiles—The maximum number of files the cache can use (expressed as a percentage of
blocks in the front file system).
· minfiles—The minimum number of files the cache can use (expressed as a percentage of
blocks in the front file system).
· threshfiles—The threshold at which additional inodes cannot be claimed after minfiles is
reached (expressed as a percentage of inodes in the front file system).
· maxfilesize—Size of the largest file allowed in the cache.
352
· mount info—The resource being mounted and its local mount point. The slash (/) characters
are displayed as underscore (_) characters.
The maximum, minimum, and threshold parameters can be modified using the cfsadmin -u
command. The following listing uses the cfsadmin -l command to display the cache status:
# cfsadmin -l /cache
cfsadmin: list cache FS information
maxblocks 90%
minblocks 0%
threshblocks 85%
maxfiles 90%
minfiles 0%
threshfiles 85%
maxfilesize 3MB
sparc20:_export_home:_home
#
Displaying Cache Statistics
To display statistical information about the performance of the cached file system, use the
cachefsstat(1M) command and specify the mount point of the cached file system.
The following statistics about the cached file are displayed:
· cache hit rate—Percentage of attempts to locate files or directories in the cached file system
that were successful, followed by a count of the actual hits and misses
· consistency checks—Number of consistency checks performed, followed by the count of
passed and failed checks
· modifies—Number of modify operations
· garbage collection—Number of attempts to reclaim resources that are no longer used
The following listing uses the cachefsstat command to display the cached file system statistics:
# cachefsstat /home
/home
cache hit rate: 57% (8 hits, 6 misses)
consistency checks: 14 (14 pass, 0 fail)
modifies: 0
garbage collection: 0
#
353
Exam Alert
Note that the cfsadmin -l command reports on the configuration status (tunable
parameters) of the cache, whereas the cachefsstat reports on the contents of the
cache (cached file system statistics).
Checking the Consistency of a Cache
To be certain that the information in a cache is up to date, periodic consistency checks are
performed automatically. These checks may create a large amount of network activity. To reduce
the amount of network traffic, you can disable the automatic consistency checking and check the
consistency manually (on demand).
To disable automatic consistency checking (that is, to request on-demand consistency checking),
specify the demandconst option when the file system is mounted. The line is wrapped to improve
readability:
# mount -F cachefs -o backfstype=nfs,cachedir=/cache,demandconst
sparc20:/export/home /home
#
To perform a consistency check on demand, use cfsadmin -s followed by a mount point of the
cached files system as a command-line argument:
# cfsadmin -s /home
#
Managing a Cache Log
The cachefslog(1M) command is used to set up, verify, and halt CacheFS logging. The
cachefswssize(1M) command is used to analyze the log to determine a recommended working
set size for the cache. A cache that’s too small will cause access delays and higher network traffic
(a low cache hit rate). A cache that’s too large will waste file system space.
To set up a CacheFS log, use the cachefslog command with the -f command-line argument
followed by the file name to be used for the log and the name of directory where the cached file
system is mounted (not the name of the cache itself). For example, to setup a log named
/var/tmp/home_log on a cached file system mounted at /home, use the following cachefslog
command:
# cachefslog -f /var/tmp/home_log /home
/var/tmp/home_log: /home
#
354
To verify cache logging, use the cachefslog command and specify only the mount point of the
cached file system as a command-line argument:
# cachefslog /home
/var/tmp/home_log: /home
#
To halt logging, use the cachefslog command with the -h command-line argument followed by the
mount point of the cached file system:
# cachefslog -h /home
not logged: /home
#
To determine the appropriate size for the cache, set up CacheFS logging and allow it to run for an
appropriate time period (such as a day or week) to provide a snapshot of the representative work
load. Then, stop logging and use the cachefswssize with the file name of the log as a
command-line argument:
# cachefswssize /var/tmp/home_log
/home
end size: 72k
high water size: 72k
total for cache
initial size: 53888k
end size: 72k
high water size: 72k
#
The end size (cache working set size when logging was halted) and high water size (largest
cache working set size) are displayed for each file system mounted in the cache. In this example,
only one file system (/home) is mounted.
The total for cache summary includes the initial size of the cache. If the high water size is the
same as the initial size, then the cache is probably too small. If the high water size is much
smaller than the initial size, then the cache is probably too large.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/26090/showart_334750.html |
|