1 ==========================
2 General Filesystem Caching
3 ==========================
9 This facility is a general purpose cache for network filesystems, though it
10 could be used for caching other things such as ISO9660 filesystems too.
12 FS-Cache mediates between cache backends (such as CacheFS) and network
19 +---------+ | +----------+ | | /dev/hda5 |
20 | | | | +--------------+
23 | AFS |----->| FS-Cache |
26 | | | | +--------------+
27 +---------+ | +----------+ | | |
28 | | | +-->| CacheFiles |
29 | ISOFS |--+ | /var/cache |
33 Or to look at it another way, FS-Cache is a module that provides a caching
34 facility to a network filesystem such that the cache is transparent to the
43 ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49 | NFS |----->| FS-Cache |
51 +---------+ | | | +--------------+ +--------------+
53 V +----------+ +-->| CacheFiles |-->| Ext3 |
54 +---------+ | /var/cache | | /dev/sda6 |
55 | | +--------------+ +--------------+
58 +---------+ +--------------+ |
60 ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~
63 +---------+ +--------------+
65 | Process | | cachefilesd |
67 +---------+ +--------------+
70 FS-Cache does not follow the idea of completely loading every netfs file
71 opened in its entirety into a cache before permitting it to be accessed and
72 then serving the pages out of that cache rather than the netfs inode because:
74 (1) It must be practical to operate without a cache.
76 (2) The size of any accessible file must not be limited to the size of the
79 (3) The combined size of all opened files (this includes mapped libraries)
80 must not be limited to the size of the cache.
82 (4) The user should not be forced to download an entire file just to do a
83 one-off access of a small portion of it (such as might be done with the
86 It instead serves the cache out in PAGE_SIZE chunks as and when requested by
87 the netfs('s) using it.
90 FS-Cache provides the following facilities:
92 (1) More than one cache can be used at once. Caches can be selected
93 explicitly by use of tags.
95 (2) Caches can be added / removed at any time.
97 (3) The netfs is provided with an interface that allows either party to
98 withdraw caching facilities from a file (required for (2)).
100 (4) The interface to the netfs returns as few errors as possible, preferring
101 rather to let the netfs remain oblivious.
103 (5) Cookies are used to represent indices, files and other objects to the
104 netfs. The simplest cookie is just a NULL pointer - indicating nothing
107 (6) The netfs is allowed to propose - dynamically - any index hierarchy it
108 desires, though it must be aware that the index search function is
109 recursive, stack space is limited, and indices can only be children of
112 (7) Data I/O is done direct to and from the netfs's pages. The netfs
113 indicates that page A is at index B of the data-file represented by cookie
114 C, and that it should be read or written. The cache backend may or may
115 not start I/O on that page, but if it does, a netfs callback will be
116 invoked to indicate completion. The I/O may be either synchronous or
119 (8) Cookies can be "retired" upon release. At this point FS-Cache will mark
120 them as obsolete and the index hierarchy rooted at that point will get
123 (9) The netfs provides a "match" function for index searches. In addition to
124 saying whether a match was made or not, this can also specify that an
125 entry should be updated or deleted.
127 (10) As much as possible is done asynchronously.
130 FS-Cache maintains a virtual indexing tree in which all indices, files, objects
131 and pages are kept. Bits of this tree may actually reside in one or more
136 +------------------------------------+
140 +--------------------------+ +-----------+
142 homedir mirror afs.org redhat.com
144 +------------+ +---------------+ +----------+
146 00001 00002 00007 00125 vol00001 vol00002
148 +---+---+ +-----+ +---+ +------+------+ +-----+----+
149 | | | | | | | | | | | | |
150 PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
160 In the example above, you can see two netfs's being backed: NFS and AFS. These
161 have different index hierarchies:
163 (*) The NFS primary index contains per-server indices. Each server index is
164 indexed by NFS file handles to get data file objects. Each data file
165 objects can have an array of pages, but may also have further child
166 objects, such as extended attributes and directory entries. Extended
167 attribute objects themselves have page-array contents.
169 (*) The AFS primary index contains per-cell indices. Each cell index contains
170 per-logical-volume indices. Each of volume index contains up to three
171 indices for the read-write, read-only and backup mirrors of those volumes.
172 Each of these contains vnode data file objects, each of which contains an
175 The very top index is the FS-Cache master index in which individual netfs's
178 Any index object may reside in more than one cache, provided it only has index
179 children. Any index with non-index object children will be assumed to only
183 The netfs API to FS-Cache can be found in:
185 Documentation/filesystems/caching/netfs-api.txt
187 The cache backend API to FS-Cache can be found in:
189 Documentation/filesystems/caching/backend-api.txt
192 =======================
193 STATISTICAL INFORMATION
194 =======================
196 If FS-Cache is compiled with the following options enabled:
198 CONFIG_FSCACHE_STATS=y
199 CONFIG_FSCACHE_HISTOGRAM=y
201 then it will gather certain statistics and display them through a number of
204 (*) /proc/fs/fscache/stats
206 This shows counts of a number of events that can happen in FS-Cache:
209 ======= ======= =======================================================
210 Cookies idx=N Number of index cookies allocated
211 dat=N Number of data storage cookies allocated
212 spc=N Number of special cookies allocated
213 Objects alc=N Number of objects allocated
214 nal=N Number of object allocation failures
215 avl=N Number of objects that reached the available state
216 ded=N Number of objects that reached the dead state
217 ChkAux non=N Number of objects that didn't have a coherency check
218 ok=N Number of objects that passed a coherency check
219 upd=N Number of objects that needed a coherency data update
220 obs=N Number of objects that were declared obsolete
221 Pages mrk=N Number of pages marked as being cached
222 unc=N Number of uncache page requests seen
223 Acquire n=N Number of acquire cookie requests seen
224 nul=N Number of acq reqs given a NULL parent
225 noc=N Number of acq reqs rejected due to no cache available
226 ok=N Number of acq reqs succeeded
227 nbf=N Number of acq reqs rejected due to error
228 oom=N Number of acq reqs failed on ENOMEM
229 Lookups n=N Number of lookup calls made on cache backends
230 neg=N Number of negative lookups made
231 pos=N Number of positive lookups made
232 crt=N Number of objects created by lookup
233 Updates n=N Number of update cookie requests seen
234 nul=N Number of upd reqs given a NULL parent
235 run=N Number of upd reqs granted CPU time
236 Relinqs n=N Number of relinquish cookie requests seen
237 nul=N Number of rlq reqs given a NULL parent
238 wcr=N Number of rlq reqs waited on completion of creation
239 AttrChg n=N Number of attribute changed requests seen
240 ok=N Number of attr changed requests queued
241 nbf=N Number of attr changed rejected -ENOBUFS
242 oom=N Number of attr changed failed -ENOMEM
243 run=N Number of attr changed ops given CPU time
244 Allocs n=N Number of allocation requests seen
245 ok=N Number of successful alloc reqs
246 wt=N Number of alloc reqs that waited on lookup completion
247 nbf=N Number of alloc reqs rejected -ENOBUFS
248 ops=N Number of alloc reqs submitted
249 owt=N Number of alloc reqs waited for CPU time
250 Retrvls n=N Number of retrieval (read) requests seen
251 ok=N Number of successful retr reqs
252 wt=N Number of retr reqs that waited on lookup completion
253 nod=N Number of retr reqs returned -ENODATA
254 nbf=N Number of retr reqs rejected -ENOBUFS
255 int=N Number of retr reqs aborted -ERESTARTSYS
256 oom=N Number of retr reqs failed -ENOMEM
257 ops=N Number of retr reqs submitted
258 owt=N Number of retr reqs waited for CPU time
259 Stores n=N Number of storage (write) requests seen
260 ok=N Number of successful store reqs
261 agn=N Number of store reqs on a page already pending storage
262 nbf=N Number of store reqs rejected -ENOBUFS
263 oom=N Number of store reqs failed -ENOMEM
264 ops=N Number of store reqs submitted
265 run=N Number of store reqs granted CPU time
266 Ops pend=N Number of times async ops added to pending queues
267 run=N Number of times async ops given CPU time
268 enq=N Number of times async ops queued for processing
269 dfr=N Number of async ops queued for deferred release
270 rel=N Number of async ops released
271 gc=N Number of deferred-release async ops garbage collected
274 (*) /proc/fs/fscache/histogram
276 cat /proc/fs/fscache/histogram
277 JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS
278 ===== ===== ========= ========= ========= ========= =========
280 This shows the breakdown of the number of times each amount of time
281 between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The
282 columns are as follows:
284 COLUMN TIME MEASUREMENT
285 ======= =======================================================
286 OBJ INST Length of time to instantiate an object
287 OP RUNS Length of time a call to process an operation took
288 OBJ RUNS Length of time a call to process an object event took
289 RETRV DLY Time between an requesting a read and lookup completing
290 RETRIEVLS Time between beginning and end of a retrieval
292 Each row shows the number of events that took a particular range of times.
293 Each step is 1 jiffy in size. The JIFS column indicates the particular
294 jiffy range covered, and the SECS field the equivalent number of seconds.
301 If CONFIG_FSCACHE_DEBUG is enabled, the FS-Cache facility can have runtime
302 debugging enabled by adjusting the value in:
304 /sys/module/fscache/parameters/debug
306 This is a bitmask of debugging streams to enable:
308 BIT VALUE STREAM POINT
309 ======= ======= =============================== =======================
310 0 1 Cache management Function entry trace
311 1 2 Function exit trace
313 3 8 Cookie management Function entry trace
314 4 16 Function exit trace
316 6 64 Page handling Function entry trace
317 7 128 Function exit trace
319 9 512 Operation management Function entry trace
320 10 1024 Function exit trace
323 The appropriate set of values should be OR'd together and the result written to
324 the control file. For example:
326 echo $((1|8|64)) >/sys/module/fscache/parameters/debug
328 will turn on all function entry debugging.