fscache.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. ==========================
  2. General Filesystem Caching
  3. ==========================
  4. ========
  5. OVERVIEW
  6. ========
  7. This facility is a general purpose cache for network filesystems, though it
  8. could be used for caching other things such as ISO9660 filesystems too.
  9. FS-Cache mediates between cache backends (such as CacheFS) and network
  10. filesystems:
  11. +---------+
  12. | | +--------------+
  13. | NFS |--+ | |
  14. | | | +-->| CacheFS |
  15. +---------+ | +----------+ | | /dev/hda5 |
  16. | | | | +--------------+
  17. +---------+ +-->| | |
  18. | | | |--+
  19. | AFS |----->| FS-Cache |
  20. | | | |--+
  21. +---------+ +-->| | |
  22. | | | | +--------------+
  23. +---------+ | +----------+ | | |
  24. | | | +-->| CacheFiles |
  25. | ISOFS |--+ | /var/cache |
  26. | | +--------------+
  27. +---------+
  28. Or to look at it another way, FS-Cache is a module that provides a caching
  29. facility to a network filesystem such that the cache is transparent to the
  30. user:
  31. +---------+
  32. | |
  33. | Server |
  34. | |
  35. +---------+
  36. | NETWORK
  37. ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. |
  39. | +----------+
  40. V | |
  41. +---------+ | |
  42. | | | |
  43. | NFS |----->| FS-Cache |
  44. | | | |--+
  45. +---------+ | | | +--------------+ +--------------+
  46. | | | | | | | |
  47. V +----------+ +-->| CacheFiles |-->| Ext3 |
  48. +---------+ | /var/cache | | /dev/sda6 |
  49. | | +--------------+ +--------------+
  50. | VFS | ^ ^
  51. | | | |
  52. +---------+ +--------------+ |
  53. | KERNEL SPACE | |
  54. ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~
  55. | USER SPACE | |
  56. V | |
  57. +---------+ +--------------+
  58. | | | |
  59. | Process | | cachefilesd |
  60. | | | |
  61. +---------+ +--------------+
  62. FS-Cache does not follow the idea of completely loading every netfs file
  63. opened in its entirety into a cache before permitting it to be accessed and
  64. then serving the pages out of that cache rather than the netfs inode because:
  65. (1) It must be practical to operate without a cache.
  66. (2) The size of any accessible file must not be limited to the size of the
  67. cache.
  68. (3) The combined size of all opened files (this includes mapped libraries)
  69. must not be limited to the size of the cache.
  70. (4) The user should not be forced to download an entire file just to do a
  71. one-off access of a small portion of it (such as might be done with the
  72. "file" program).
  73. It instead serves the cache out in PAGE_SIZE chunks as and when requested by
  74. the netfs('s) using it.
  75. FS-Cache provides the following facilities:
  76. (1) More than one cache can be used at once. Caches can be selected
  77. explicitly by use of tags.
  78. (2) Caches can be added / removed at any time.
  79. (3) The netfs is provided with an interface that allows either party to
  80. withdraw caching facilities from a file (required for (2)).
  81. (4) The interface to the netfs returns as few errors as possible, preferring
  82. rather to let the netfs remain oblivious.
  83. (5) Cookies are used to represent indices, files and other objects to the
  84. netfs. The simplest cookie is just a NULL pointer - indicating nothing
  85. cached there.
  86. (6) The netfs is allowed to propose - dynamically - any index hierarchy it
  87. desires, though it must be aware that the index search function is
  88. recursive, stack space is limited, and indices can only be children of
  89. indices.
  90. (7) Data I/O is done direct to and from the netfs's pages. The netfs
  91. indicates that page A is at index B of the data-file represented by cookie
  92. C, and that it should be read or written. The cache backend may or may
  93. not start I/O on that page, but if it does, a netfs callback will be
  94. invoked to indicate completion. The I/O may be either synchronous or
  95. asynchronous.
  96. (8) Cookies can be "retired" upon release. At this point FS-Cache will mark
  97. them as obsolete and the index hierarchy rooted at that point will get
  98. recycled.
  99. (9) The netfs provides a "match" function for index searches. In addition to
  100. saying whether a match was made or not, this can also specify that an
  101. entry should be updated or deleted.
  102. (10) As much as possible is done asynchronously.
  103. FS-Cache maintains a virtual indexing tree in which all indices, files, objects
  104. and pages are kept. Bits of this tree may actually reside in one or more
  105. caches.
  106. FSDEF
  107. |
  108. +------------------------------------+
  109. | |
  110. NFS AFS
  111. | |
  112. +--------------------------+ +-----------+
  113. | | | |
  114. homedir mirror afs.org redhat.com
  115. | | |
  116. +------------+ +---------------+ +----------+
  117. | | | | | |
  118. 00001 00002 00007 00125 vol00001 vol00002
  119. | | | | |
  120. +---+---+ +-----+ +---+ +------+------+ +-----+----+
  121. | | | | | | | | | | | | |
  122. PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
  123. | |
  124. PG0 +-------+
  125. | |
  126. 00001 00003
  127. |
  128. +---+---+
  129. | | |
  130. PG0 PG1 PG2
  131. In the example above, you can see two netfs's being backed: NFS and AFS. These
  132. have different index hierarchies:
  133. (*) The NFS primary index contains per-server indices. Each server index is
  134. indexed by NFS file handles to get data file objects. Each data file
  135. objects can have an array of pages, but may also have further child
  136. objects, such as extended attributes and directory entries. Extended
  137. attribute objects themselves have page-array contents.
  138. (*) The AFS primary index contains per-cell indices. Each cell index contains
  139. per-logical-volume indices. Each of volume index contains up to three
  140. indices for the read-write, read-only and backup mirrors of those volumes.
  141. Each of these contains vnode data file objects, each of which contains an
  142. array of pages.
  143. The very top index is the FS-Cache master index in which individual netfs's
  144. have entries.
  145. Any index object may reside in more than one cache, provided it only has index
  146. children. Any index with non-index object children will be assumed to only
  147. reside in one cache.
  148. The netfs API to FS-Cache can be found in:
  149. Documentation/filesystems/caching/netfs-api.txt
  150. The cache backend API to FS-Cache can be found in:
  151. Documentation/filesystems/caching/backend-api.txt
  152. A description of the internal representations and object state machine can be
  153. found in:
  154. Documentation/filesystems/caching/object.txt
  155. =======================
  156. STATISTICAL INFORMATION
  157. =======================
  158. If FS-Cache is compiled with the following options enabled:
  159. CONFIG_FSCACHE_STATS=y
  160. CONFIG_FSCACHE_HISTOGRAM=y
  161. then it will gather certain statistics and display them through a number of
  162. proc files.
  163. (*) /proc/fs/fscache/stats
  164. This shows counts of a number of events that can happen in FS-Cache:
  165. CLASS EVENT MEANING
  166. ======= ======= =======================================================
  167. Cookies idx=N Number of index cookies allocated
  168. dat=N Number of data storage cookies allocated
  169. spc=N Number of special cookies allocated
  170. Objects alc=N Number of objects allocated
  171. nal=N Number of object allocation failures
  172. avl=N Number of objects that reached the available state
  173. ded=N Number of objects that reached the dead state
  174. ChkAux non=N Number of objects that didn't have a coherency check
  175. ok=N Number of objects that passed a coherency check
  176. upd=N Number of objects that needed a coherency data update
  177. obs=N Number of objects that were declared obsolete
  178. Pages mrk=N Number of pages marked as being cached
  179. unc=N Number of uncache page requests seen
  180. Acquire n=N Number of acquire cookie requests seen
  181. nul=N Number of acq reqs given a NULL parent
  182. noc=N Number of acq reqs rejected due to no cache available
  183. ok=N Number of acq reqs succeeded
  184. nbf=N Number of acq reqs rejected due to error
  185. oom=N Number of acq reqs failed on ENOMEM
  186. Lookups n=N Number of lookup calls made on cache backends
  187. neg=N Number of negative lookups made
  188. pos=N Number of positive lookups made
  189. crt=N Number of objects created by lookup
  190. tmo=N Number of lookups timed out and requeued
  191. Updates n=N Number of update cookie requests seen
  192. nul=N Number of upd reqs given a NULL parent
  193. run=N Number of upd reqs granted CPU time
  194. Relinqs n=N Number of relinquish cookie requests seen
  195. nul=N Number of rlq reqs given a NULL parent
  196. wcr=N Number of rlq reqs waited on completion of creation
  197. AttrChg n=N Number of attribute changed requests seen
  198. ok=N Number of attr changed requests queued
  199. nbf=N Number of attr changed rejected -ENOBUFS
  200. oom=N Number of attr changed failed -ENOMEM
  201. run=N Number of attr changed ops given CPU time
  202. Allocs n=N Number of allocation requests seen
  203. ok=N Number of successful alloc reqs
  204. wt=N Number of alloc reqs that waited on lookup completion
  205. nbf=N Number of alloc reqs rejected -ENOBUFS
  206. int=N Number of alloc reqs aborted -ERESTARTSYS
  207. ops=N Number of alloc reqs submitted
  208. owt=N Number of alloc reqs waited for CPU time
  209. abt=N Number of alloc reqs aborted due to object death
  210. Retrvls n=N Number of retrieval (read) requests seen
  211. ok=N Number of successful retr reqs
  212. wt=N Number of retr reqs that waited on lookup completion
  213. nod=N Number of retr reqs returned -ENODATA
  214. nbf=N Number of retr reqs rejected -ENOBUFS
  215. int=N Number of retr reqs aborted -ERESTARTSYS
  216. oom=N Number of retr reqs failed -ENOMEM
  217. ops=N Number of retr reqs submitted
  218. owt=N Number of retr reqs waited for CPU time
  219. abt=N Number of retr reqs aborted due to object death
  220. Stores n=N Number of storage (write) requests seen
  221. ok=N Number of successful store reqs
  222. agn=N Number of store reqs on a page already pending storage
  223. nbf=N Number of store reqs rejected -ENOBUFS
  224. oom=N Number of store reqs failed -ENOMEM
  225. ops=N Number of store reqs submitted
  226. run=N Number of store reqs granted CPU time
  227. pgs=N Number of pages given store req processing time
  228. rxd=N Number of store reqs deleted from tracking tree
  229. olm=N Number of store reqs over store limit
  230. VmScan nos=N Number of release reqs against pages with no pending store
  231. gon=N Number of release reqs against pages stored by time lock granted
  232. bsy=N Number of release reqs ignored due to in-progress store
  233. can=N Number of page stores cancelled due to release req
  234. Ops pend=N Number of times async ops added to pending queues
  235. run=N Number of times async ops given CPU time
  236. enq=N Number of times async ops queued for processing
  237. can=N Number of async ops cancelled
  238. rej=N Number of async ops rejected due to object lookup/create failure
  239. ini=N Number of async ops initialised
  240. dfr=N Number of async ops queued for deferred release
  241. rel=N Number of async ops released (should equal ini=N when idle)
  242. gc=N Number of deferred-release async ops garbage collected
  243. CacheOp alo=N Number of in-progress alloc_object() cache ops
  244. luo=N Number of in-progress lookup_object() cache ops
  245. luc=N Number of in-progress lookup_complete() cache ops
  246. gro=N Number of in-progress grab_object() cache ops
  247. upo=N Number of in-progress update_object() cache ops
  248. dro=N Number of in-progress drop_object() cache ops
  249. pto=N Number of in-progress put_object() cache ops
  250. syn=N Number of in-progress sync_cache() cache ops
  251. atc=N Number of in-progress attr_changed() cache ops
  252. rap=N Number of in-progress read_or_alloc_page() cache ops
  253. ras=N Number of in-progress read_or_alloc_pages() cache ops
  254. alp=N Number of in-progress allocate_page() cache ops
  255. als=N Number of in-progress allocate_pages() cache ops
  256. wrp=N Number of in-progress write_page() cache ops
  257. ucp=N Number of in-progress uncache_page() cache ops
  258. dsp=N Number of in-progress dissociate_pages() cache ops
  259. CacheEv nsp=N Number of object lookups/creations rejected due to lack of space
  260. stl=N Number of stale objects deleted
  261. rtr=N Number of objects retired when relinquished
  262. cul=N Number of objects culled
  263. (*) /proc/fs/fscache/histogram
  264. cat /proc/fs/fscache/histogram
  265. JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS
  266. ===== ===== ========= ========= ========= ========= =========
  267. This shows the breakdown of the number of times each amount of time
  268. between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The
  269. columns are as follows:
  270. COLUMN TIME MEASUREMENT
  271. ======= =======================================================
  272. OBJ INST Length of time to instantiate an object
  273. OP RUNS Length of time a call to process an operation took
  274. OBJ RUNS Length of time a call to process an object event took
  275. RETRV DLY Time between an requesting a read and lookup completing
  276. RETRIEVLS Time between beginning and end of a retrieval
  277. Each row shows the number of events that took a particular range of times.
  278. Each step is 1 jiffy in size. The JIFS column indicates the particular
  279. jiffy range covered, and the SECS field the equivalent number of seconds.
  280. ===========
  281. OBJECT LIST
  282. ===========
  283. If CONFIG_FSCACHE_OBJECT_LIST is enabled, the FS-Cache facility will maintain a
  284. list of all the objects currently allocated and allow them to be viewed
  285. through:
  286. /proc/fs/fscache/objects
  287. This will look something like:
  288. [root@andromeda ~]# head /proc/fs/fscache/objects
  289. OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS EM EV F S | NETFS_COOKIE_DEF TY FL NETFS_DATA OBJECT_KEY, AUX_DATA
  290. ======== ======== ==== ===== === === === == ===== == == = = | ================ == == ================ ================
  291. 17e4b 2 ACTV 0 0 0 0 0 0 7b 4 0 0 | NFS.fh DT 0 ffff88001dd82820 010006017edcf8bbc93b43298fdfbe71e50b57b13a172c0117f38472, e567634700000000000000000000000063f2404a000000000000000000000000c9030000000000000000000063f2404a
  292. 1693a 2 ACTV 0 0 0 0 0 0 7b 4 0 0 | NFS.fh DT 0 ffff88002db23380 010006017edcf8bbc93b43298fdfbe71e50b57b1e0162c01a2df0ea6, 420ebc4a000000000000000000000000420ebc4a0000000000000000000000000e1801000000000000000000420ebc4a
  293. where the first set of columns before the '|' describe the object:
  294. COLUMN DESCRIPTION
  295. ======= ===============================================================
  296. OBJECT Object debugging ID (appears as OBJ%x in some debug messages)
  297. PARENT Debugging ID of parent object
  298. STAT Object state
  299. CHLDN Number of child objects of this object
  300. OPS Number of outstanding operations on this object
  301. OOP Number of outstanding child object management operations
  302. IPR
  303. EX Number of outstanding exclusive operations
  304. READS Number of outstanding read operations
  305. EM Object's event mask
  306. EV Events raised on this object
  307. F Object flags
  308. S Object work item busy state mask (1:pending 2:running)
  309. and the second set of columns describe the object's cookie, if present:
  310. COLUMN DESCRIPTION
  311. =============== =======================================================
  312. NETFS_COOKIE_DEF Name of netfs cookie definition
  313. TY Cookie type (IX - index, DT - data, hex - special)
  314. FL Cookie flags
  315. NETFS_DATA Netfs private data stored in the cookie
  316. OBJECT_KEY Object key } 1 column, with separating comma
  317. AUX_DATA Object aux data } presence may be configured
  318. The data shown may be filtered by attaching the a key to an appropriate keyring
  319. before viewing the file. Something like:
  320. keyctl add user fscache:objlist <restrictions> @s
  321. where <restrictions> are a selection of the following letters:
  322. K Show hexdump of object key (don't show if not given)
  323. A Show hexdump of object aux data (don't show if not given)
  324. and the following paired letters:
  325. C Show objects that have a cookie
  326. c Show objects that don't have a cookie
  327. B Show objects that are busy
  328. b Show objects that aren't busy
  329. W Show objects that have pending writes
  330. w Show objects that don't have pending writes
  331. R Show objects that have outstanding reads
  332. r Show objects that don't have outstanding reads
  333. S Show objects that have work queued
  334. s Show objects that don't have work queued
  335. If neither side of a letter pair is given, then both are implied. For example:
  336. keyctl add user fscache:objlist KB @s
  337. shows objects that are busy, and lists their object keys, but does not dump
  338. their auxiliary data. It also implies "CcWwRrSs", but as 'B' is given, 'b' is
  339. not implied.
  340. By default all objects and all fields will be shown.
  341. =========
  342. DEBUGGING
  343. =========
  344. If CONFIG_FSCACHE_DEBUG is enabled, the FS-Cache facility can have runtime
  345. debugging enabled by adjusting the value in:
  346. /sys/module/fscache/parameters/debug
  347. This is a bitmask of debugging streams to enable:
  348. BIT VALUE STREAM POINT
  349. ======= ======= =============================== =======================
  350. 0 1 Cache management Function entry trace
  351. 1 2 Function exit trace
  352. 2 4 General
  353. 3 8 Cookie management Function entry trace
  354. 4 16 Function exit trace
  355. 5 32 General
  356. 6 64 Page handling Function entry trace
  357. 7 128 Function exit trace
  358. 8 256 General
  359. 9 512 Operation management Function entry trace
  360. 10 1024 Function exit trace
  361. 11 2048 General
  362. The appropriate set of values should be OR'd together and the result written to
  363. the control file. For example:
  364. echo $((1|8|64)) >/sys/module/fscache/parameters/debug
  365. will turn on all function entry debugging.