brintos

brintos / linux-shallow public Read only

0
0
Text · 14.9 KiB · de1f325 Raw
349 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3==========================4General Filesystem Caching5==========================6 7Overview8========9 10This facility is a general purpose cache for network filesystems, though it11could be used for caching other things such as ISO9660 filesystems too.12 13FS-Cache mediates between cache backends (such as CacheFiles) and network14filesystems::15 16	+---------+17	|         |                                    +--------------+18	|   NFS   |--+                                 |              |19	|         |  |                             +-->|   CacheFS    |20	+---------+  |               +----------+  |   |  /dev/hda5   |21	             |               |          |  |   +--------------+22	+---------+  +-------------->|          |  |23	|         |      +-------+   |          |--+24	|   AFS   |----->|       |   | FS-Cache |25	|         |      | netfs |-->|          |--+26	+---------+  +-->|  lib  |   |          |  |27	             |   |       |   |          |  |   +--------------+28	+---------+  |   +-------+   +----------+  |   |              |29	|         |  |                             +-->|  CacheFiles  |30	|   9P    |--+                                 |  /var/cache  |31	|         |                                    +--------------+32	+---------+33 34Or to look at it another way, FS-Cache is a module that provides a caching35facility to a network filesystem such that the cache is transparent to the36user::37 38	+---------+39	|         |40	| Server  |41	|         |42	+---------+43	     |                  NETWORK44	~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~45	     |46	     |           +----------+47	     V           |          |48	+---------+      |          |49	|         |      |          |50	|   NFS   |----->| FS-Cache |51	|         |      |          |--+52	+---------+      |          |  |   +--------------+   +--------------+53	     |           |          |  |   |              |   |              |54	     V           +----------+  +-->|  CacheFiles  |-->|  Ext3        |55	+---------+                        |  /var/cache  |   |  /dev/sda6   |56	|         |                        +--------------+   +--------------+57	|   VFS   |                                ^                     ^58	|         |                                |                     |59	+---------+                                +--------------+      |60	     |                  KERNEL SPACE                      |      |61	~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~62	     |                  USER SPACE                        |      |63	     V                                                    |      |64	+---------+                                           +--------------+65	|         |                                           |              |66	| Process |                                           | cachefilesd  |67	|         |                                           |              |68	+---------+                                           +--------------+69 70 71FS-Cache does not follow the idea of completely loading every netfs file72opened in its entirety into a cache before permitting it to be accessed and73then serving the pages out of that cache rather than the netfs inode because:74 75 (1) It must be practical to operate without a cache.76 77 (2) The size of any accessible file must not be limited to the size of the78     cache.79 80 (3) The combined size of all opened files (this includes mapped libraries)81     must not be limited to the size of the cache.82 83 (4) The user should not be forced to download an entire file just to do a84     one-off access of a small portion of it (such as might be done with the85     "file" program).86 87It instead serves the cache out in chunks as and when requested by the netfs88using it.89 90 91FS-Cache provides the following facilities:92 93   * More than one cache can be used at once.  Caches can be selected94     explicitly by use of tags.95 96   * Caches can be added / removed at any time, even whilst being accessed.97 98   * The netfs is provided with an interface that allows either party to99     withdraw caching facilities from a file (required for (2)).100 101   * The interface to the netfs returns as few errors as possible, preferring102     rather to let the netfs remain oblivious.103 104   * There are three types of cookie: cache, volume and data file cookies.105     Cache cookies represent the cache as a whole and are not normally visible106     to the netfs; the netfs gets a volume cookie to represent a collection of107     files (typically something that a netfs would get for a superblock); and108     data file cookies are used to cache data (something that would be got for109     an inode).110 111   * Volumes are matched using a key.  This is a printable string that is used112     to encode all the information that might be needed to distinguish one113     superblock, say, from another.  This would be a compound of things like114     cell name or server address, volume name or share path.  It must be a115     valid pathname.116 117   * Cookies are matched using a key.  This is a binary blob and is used to118     represent the object within a volume (so the volume key need not form119     part of the blob).  This might include things like an inode number and120     uniquifier or a file handle.121 122   * Cookie resources are set up and pinned by marking the cookie in-use.123     This prevents the backing resources from being culled.  Timed garbage124     collection is employed to eliminate cookies that haven't been used for a125     short while, thereby reducing resource overload.  This is intended to be126     used when a file is opened or closed.127 128     A cookie can be marked in-use multiple times simultaneously; each mark129     must be unused.130 131   * Begin/end access functions are provided to delay cache withdrawal for the132     duration of an operation and prevent structs from being freed whilst133     we're looking at them.134 135   * Data I/O is done by asynchronous DIO to/from a buffer described by the136     netfs using an iov_iter.137 138   * An invalidation facility is available to discard data from the cache and139     to deal with I/O that's in progress that is accessing old data.140 141   * Cookies can be "retired" upon release, thereby causing the object to be142     removed from the cache.143 144 145The netfs API to FS-Cache can be found in:146 147	Documentation/filesystems/caching/netfs-api.rst148 149The cache backend API to FS-Cache can be found in:150 151	Documentation/filesystems/caching/backend-api.rst152 153 154Statistical Information155=======================156 157If FS-Cache is compiled with the following options enabled::158 159	CONFIG_FSCACHE_STATS=y160 161then it will gather certain statistics and display them through:162 163	/proc/fs/fscache/stats164 165This shows counts of a number of events that can happen in FS-Cache:166 167+--------------+-------+-------------------------------------------------------+168|CLASS         |EVENT  |MEANING                                                |169+==============+=======+=======================================================+170|Cookies       |n=N    |Number of data storage cookies allocated               |171+              +-------+-------------------------------------------------------+172|              |v=N    |Number of volume index cookies allocated               |173+              +-------+-------------------------------------------------------+174|              |vcol=N |Number of volume index key collisions                  |175+              +-------+-------------------------------------------------------+176|              |voom=N |Number of OOM events when allocating volume cookies    |177+--------------+-------+-------------------------------------------------------+178|Acquire       |n=N    |Number of acquire cookie requests seen                 |179+              +-------+-------------------------------------------------------+180|              |ok=N   |Number of acq reqs succeeded                           |181+              +-------+-------------------------------------------------------+182|              |oom=N  |Number of acq reqs failed on ENOMEM                    |183+--------------+-------+-------------------------------------------------------+184|LRU           |n=N    |Number of cookies currently on the LRU                 |185+              +-------+-------------------------------------------------------+186|              |exp=N  |Number of cookies expired off of the LRU               |187+              +-------+-------------------------------------------------------+188|              |rmv=N  |Number of cookies removed from the LRU                 |189+              +-------+-------------------------------------------------------+190|              |drp=N  |Number of LRU'd cookies relinquished/withdrawn         |191+              +-------+-------------------------------------------------------+192|              |at=N   |Time till next LRU cull (jiffies)                      |193+--------------+-------+-------------------------------------------------------+194|Invals        |n=N    |Number of invalidations                                |195+--------------+-------+-------------------------------------------------------+196|Updates       |n=N    |Number of update cookie requests seen                  |197+              +-------+-------------------------------------------------------+198|              |rsz=N  |Number of resize requests                              |199+              +-------+-------------------------------------------------------+200|              |rsn=N  |Number of skipped resize requests                      |201+--------------+-------+-------------------------------------------------------+202|Relinqs       |n=N    |Number of relinquish cookie requests seen              |203+              +-------+-------------------------------------------------------+204|              |rtr=N  |Number of rlq reqs with retire=true                    |205+              +-------+-------------------------------------------------------+206|              |drop=N |Number of cookies no longer blocking re-acquisition    |207+--------------+-------+-------------------------------------------------------+208|NoSpace       |nwr=N  |Number of write requests refused due to lack of space  |209+              +-------+-------------------------------------------------------+210|              |ncr=N  |Number of create requests refused due to lack of space |211+              +-------+-------------------------------------------------------+212|              |cull=N |Number of objects culled to make space                 |213+--------------+-------+-------------------------------------------------------+214|IO            |rd=N   |Number of read operations in the cache                 |215+              +-------+-------------------------------------------------------+216|              |wr=N   |Number of write operations in the cache                |217+--------------+-------+-------------------------------------------------------+218 219Netfslib will also add some stats counters of its own.220 221 222Cache List223==========224 225FS-Cache provides a list of cache cookies:226 227	/proc/fs/fscache/cookies228 229This will look something like::230 231	# cat /proc/fs/fscache/caches232	CACHE    REF   VOLS  OBJS  ACCES S NAME233	======== ===== ===== ===== ===== = ===============234	00000001     2     1  2123     1 A default235 236where the columns are:237 238	=======	===============================================================239	COLUMN	DESCRIPTION240	=======	===============================================================241	CACHE	Cache cookie debug ID (also appears in traces)242	REF	Number of references on the cache cookie243	VOLS	Number of volumes cookies in this cache244	OBJS	Number of cache objects in use245	ACCES	Number of accesses pinning the cache246	S	State247	NAME	Name of the cache.248	=======	===============================================================249 250The state can be (-) Inactive, (P)reparing, (A)ctive, (E)rror or (W)ithdrawing.251 252 253Volume List254===========255 256FS-Cache provides a list of volume cookies:257 258	/proc/fs/fscache/volumes259 260This will look something like::261 262	VOLUME   REF   nCOOK ACC FL CACHE           KEY263	======== ===== ===== === == =============== ================264	00000001    55    54   1 00 default         afs,example.com,100058265 266where the columns are:267 268	=======	===============================================================269	COLUMN	DESCRIPTION270	=======	===============================================================271	VOLUME	The volume cookie debug ID (also appears in traces)272	REF	Number of references on the volume cookie273	nCOOK	Number of cookies in the volume274	ACC	Number of accesses pinning the cache275	FL	Flags on the volume cookie276	CACHE	Name of the cache or "-"277	KEY	The indexing key for the volume278	=======	===============================================================279 280 281Cookie List282===========283 284FS-Cache provides a list of cookies:285 286	/proc/fs/fscache/cookies287 288This will look something like::289 290	# head /proc/fs/fscache/cookies291	COOKIE   VOLUME   REF ACT ACC S FL DEF292	======== ======== === === === = == ================293	00000435 00000001   1   0  -1 - 08 0000000201d080070000000000000000, 0000000000000000294	00000436 00000001   1   0  -1 - 00 0000005601d080080000000000000000, 0000000000000051295	00000437 00000001   1   0  -1 - 08 00023b3001d0823f0000000000000000, 0000000000000000296	00000438 00000001   1   0  -1 - 08 0000005801d0807b0000000000000000, 0000000000000000297	00000439 00000001   1   0  -1 - 08 00023b3201d080a10000000000000000, 0000000000000000298	0000043a 00000001   1   0  -1 - 08 00023b3401d080a30000000000000000, 0000000000000000299	0000043b 00000001   1   0  -1 - 08 00023b3601d080b30000000000000000, 0000000000000000300	0000043c 00000001   1   0  -1 - 08 00023b3801d080b40000000000000000, 0000000000000000301 302where the columns are:303 304	=======	===============================================================305	COLUMN	DESCRIPTION306	=======	===============================================================307	COOKIE	The cookie debug ID (also appears in traces)308	VOLUME	The parent volume cookie debug ID309	REF	Number of references on the volume cookie310	ACT	Number of times the cookie is marked for in use311	ACC	Number of access pins in the cookie312	S	State of the cookie313	FL	Flags on the cookie314	DEF	Key, auxiliary data315	=======	===============================================================316 317 318Debugging319=========320 321If CONFIG_NETFS_DEBUG is enabled, the FS-Cache facility and NETFS support can322have runtime debugging enabled by adjusting the value in::323 324	/sys/module/netfs/parameters/debug325 326This is a bitmask of debugging streams to enable:327 328	=======	=======	===============================	=======================329	BIT	VALUE	STREAM				POINT330	=======	=======	===============================	=======================331	0	1	Cache management		Function entry trace332	1	2					Function exit trace333	2	4					General334	3	8	Cookie management		Function entry trace335	4	16					Function exit trace336	5	32					General337	6-8						(Not used)338	9	512	I/O operation management	Function entry trace339	10	1024					Function exit trace340	11	2048					General341	=======	=======	===============================	=======================342 343The appropriate set of values should be OR'd together and the result written to344the control file.  For example::345 346	echo $((1|8|512)) >/sys/module/netfs/parameters/debug347 348will turn on all function entry debugging.349