fscache.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. Updates n=N Number of update cookie requests seen
  191. nul=N Number of upd reqs given a NULL parent
  192. run=N Number of upd reqs granted CPU time
  193. Relinqs n=N Number of relinquish cookie requests seen
  194. nul=N Number of rlq reqs given a NULL parent
  195. wcr=N Number of rlq reqs waited on completion of creation
  196. AttrChg n=N Number of attribute changed requests seen
  197. ok=N Number of attr changed requests queued
  198. nbf=N Number of attr changed rejected -ENOBUFS
  199. oom=N Number of attr changed failed -ENOMEM
  200. run=N Number of attr changed ops given CPU time
  201. Allocs n=N Number of allocation requests seen
  202. ok=N Number of successful alloc reqs
  203. wt=N Number of alloc reqs that waited on lookup completion
  204. nbf=N Number of alloc reqs rejected -ENOBUFS
  205. ops=N Number of alloc reqs submitted
  206. owt=N Number of alloc reqs waited for CPU time
  207. Retrvls n=N Number of retrieval (read) requests seen
  208. ok=N Number of successful retr reqs
  209. wt=N Number of retr reqs that waited on lookup completion
  210. nod=N Number of retr reqs returned -ENODATA
  211. nbf=N Number of retr reqs rejected -ENOBUFS
  212. int=N Number of retr reqs aborted -ERESTARTSYS
  213. oom=N Number of retr reqs failed -ENOMEM
  214. ops=N Number of retr reqs submitted
  215. owt=N Number of retr reqs waited for CPU time
  216. Stores n=N Number of storage (write) requests seen
  217. ok=N Number of successful store reqs
  218. agn=N Number of store reqs on a page already pending storage
  219. nbf=N Number of store reqs rejected -ENOBUFS
  220. oom=N Number of store reqs failed -ENOMEM
  221. ops=N Number of store reqs submitted
  222. run=N Number of store reqs granted CPU time
  223. Ops pend=N Number of times async ops added to pending queues
  224. run=N Number of times async ops given CPU time
  225. enq=N Number of times async ops queued for processing
  226. dfr=N Number of async ops queued for deferred release
  227. rel=N Number of async ops released
  228. gc=N Number of deferred-release async ops garbage collected
  229. (*) /proc/fs/fscache/histogram
  230. cat /proc/fs/fscache/histogram
  231. JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS
  232. ===== ===== ========= ========= ========= ========= =========
  233. This shows the breakdown of the number of times each amount of time
  234. between 0 jiffies and HZ-1 jiffies a variety of tasks took to run. The
  235. columns are as follows:
  236. COLUMN TIME MEASUREMENT
  237. ======= =======================================================
  238. OBJ INST Length of time to instantiate an object
  239. OP RUNS Length of time a call to process an operation took
  240. OBJ RUNS Length of time a call to process an object event took
  241. RETRV DLY Time between an requesting a read and lookup completing
  242. RETRIEVLS Time between beginning and end of a retrieval
  243. Each row shows the number of events that took a particular range of times.
  244. Each step is 1 jiffy in size. The JIFS column indicates the particular
  245. jiffy range covered, and the SECS field the equivalent number of seconds.
  246. =========
  247. DEBUGGING
  248. =========
  249. If CONFIG_FSCACHE_DEBUG is enabled, the FS-Cache facility can have runtime
  250. debugging enabled by adjusting the value in:
  251. /sys/module/fscache/parameters/debug
  252. This is a bitmask of debugging streams to enable:
  253. BIT VALUE STREAM POINT
  254. ======= ======= =============================== =======================
  255. 0 1 Cache management Function entry trace
  256. 1 2 Function exit trace
  257. 2 4 General
  258. 3 8 Cookie management Function entry trace
  259. 4 16 Function exit trace
  260. 5 32 General
  261. 6 64 Page handling Function entry trace
  262. 7 128 Function exit trace
  263. 8 256 General
  264. 9 512 Operation management Function entry trace
  265. 10 1024 Function exit trace
  266. 11 2048 General
  267. The appropriate set of values should be OR'd together and the result written to
  268. the control file. For example:
  269. echo $((1|8|64)) >/sys/module/fscache/parameters/debug
  270. will turn on all function entry debugging.