← Documents Documentation/filesystems/caching/fscache.rst GitHub 원문 ↗

Linux 6.18.37 · Filesystems

General Filesystem Caching

FS-Cache의 netfs-backend 중재 구조, cookie 수명과 procfs 통계·목록·debug interface 전문 번역입니다.

Source pathDocumentation/filesystems/caching/fscache.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

fscache.rst:1-348

FS-Cache는 NFS·AFS·9P와 같은 netfs가 CacheFiles 같은 backend를 투명하게 사용하도록 중재합니다. 전체 파일을 선취하지 않고 요청된 chunk만 비동기 DIO로 다루므로 캐시 없이도 동작하고 파일 크기나 열린 파일 총량이 캐시 용량에 묶이지 않습니다.

cache·volume·data cookie와 key가 객체 계층을 모델링하고, in-use 표시와 access pin이 culling·withdrawal 경쟁을 막습니다. procfs의 stats, cache, volume, cookie 목록과 NETFS debug mask로 수명·LRU·I/O 상태를 관찰할 수 있습니다.

FS-Cache 데이터와 수명 흐름
netfs가 volume·data cookie 획득cookie를 in-use로 표시하고 access pin 획득요청 range를 `iov_iter` 기반 비동기 DIO로 처리FS-Cache가 선택한 backend에 chunk 저장·조회미사용 cookie를 timed GC와 LRU로 회수invalidation·retire·withdrawal로 오래된 데이터 제거

netfs 요청부터 backend 저장과 cookie 회수까지의 핵심 경로입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ==========================
4 General Filesystem Caching
5 ==========================
6
7 Overview
8 ========
9
10 This facility is a general purpose cache for network filesystems, though it
11 could be used for caching other things such as ISO9660 filesystems too.
12
13 FS-Cache mediates between cache backends (such as CacheFiles) and network
14 filesystems::
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
34 Or to look at it another way, FS-Cache is a module that provides a caching
35 facility to a network filesystem such that the cache is transparent to the
36 user::
37
38 +---------+
39 | |
40 | Server |
41 | |
42 +---------+
43 | NETWORK
44 ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
71 FS-Cache does not follow the idea of completely loading every netfs file
72 opened in its entirety into a cache before permitting it to be accessed and
73 then 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 the
78 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 a
84 one-off access of a small portion of it (such as might be done with the
85 "file" program).
86
87 It instead serves the cache out in chunks as and when requested by the netfs
88 using it.
89
90
91 FS-Cache provides the following facilities:
92
93 * More than one cache can be used at once. Caches can be selected
94 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 to
99 withdraw caching facilities from a file (required for (2)).
100
101 * The interface to the netfs returns as few errors as possible, preferring
102 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 visible
106 to the netfs; the netfs gets a volume cookie to represent a collection of
107 files (typically something that a netfs would get for a superblock); and
108 data file cookies are used to cache data (something that would be got for
109 an inode).
110
111 * Volumes are matched using a key. This is a printable string that is used
112 to encode all the information that might be needed to distinguish one
113 superblock, say, from another. This would be a compound of things like
114 cell name or server address, volume name or share path. It must be a
115 valid pathname.
116
117 * Cookies are matched using a key. This is a binary blob and is used to
118 represent the object within a volume (so the volume key need not form
119 part of the blob). This might include things like an inode number and
120 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 garbage
124 collection is employed to eliminate cookies that haven't been used for a
125 short while, thereby reducing resource overload. This is intended to be
126 used when a file is opened or closed.
127
128 A cookie can be marked in-use multiple times simultaneously; each mark
129 must be unused.
130
131 * Begin/end access functions are provided to delay cache withdrawal for the
132 duration of an operation and prevent structs from being freed whilst
133 we're looking at them.
134
135 * Data I/O is done by asynchronous DIO to/from a buffer described by the
136 netfs using an iov_iter.
137
138 * An invalidation facility is available to discard data from the cache and
139 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 be
142 removed from the cache.
143
144
145 The netfs API to FS-Cache can be found in:
146
147 Documentation/filesystems/caching/netfs-api.rst
148
149 The cache backend API to FS-Cache can be found in:
150
151 Documentation/filesystems/caching/backend-api.rst
152
153
154 Statistical Information
155 =======================
156
157 If FS-Cache is compiled with the following options enabled::
158
159 CONFIG_FSCACHE_STATS=y
160
161 then it will gather certain statistics and display them through:
162
163 /proc/fs/fscache/stats
164
165 This 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
219 Netfslib will also add some stats counters of its own.
220
221
222 Cache List
223 ==========
224
225 FS-Cache provides a list of cache cookies:
226
227 /proc/fs/fscache/cookies
228
229 This will look something like::
230
231 # cat /proc/fs/fscache/caches
232 CACHE REF VOLS OBJS ACCES S NAME
233 ======== ===== ===== ===== ===== = ===============
234 00000001 2 1 2123 1 A default
235
236 where the columns are:
237
238 ======= ===============================================================
239 COLUMN DESCRIPTION
240 ======= ===============================================================
241 CACHE Cache cookie debug ID (also appears in traces)
242 REF Number of references on the cache cookie
243 VOLS Number of volumes cookies in this cache
244 OBJS Number of cache objects in use
245 ACCES Number of accesses pinning the cache
246 S State
247 NAME Name of the cache.
248 ======= ===============================================================
249
250 The state can be (-) Inactive, (P)reparing, (A)ctive, (E)rror or (W)ithdrawing.
251
252
253 Volume List
254 ===========
255
256 FS-Cache provides a list of volume cookies:
257
258 /proc/fs/fscache/volumes
259
260 This will look something like::
261
262 VOLUME REF nCOOK ACC FL CACHE KEY
263 ======== ===== ===== === == =============== ================
264 00000001 55 54 1 00 default afs,example.com,100058
265
266 where the columns are:
267
268 ======= ===============================================================
269 COLUMN DESCRIPTION
270 ======= ===============================================================
271 VOLUME The volume cookie debug ID (also appears in traces)
272 REF Number of references on the volume cookie
273 nCOOK Number of cookies in the volume
274 ACC Number of accesses pinning the cache
275 FL Flags on the volume cookie
276 CACHE Name of the cache or "-"
277 KEY The indexing key for the volume
278 ======= ===============================================================
279
280
281 Cookie List
282 ===========
283
284 FS-Cache provides a list of cookies:
285
286 /proc/fs/fscache/cookies
287
288 This will look something like::
289
290 # head /proc/fs/fscache/cookies
291 COOKIE VOLUME REF ACT ACC S FL DEF
292 ======== ======== === === === = == ================
293 00000435 00000001 1 0 -1 - 08 0000000201d080070000000000000000, 0000000000000000
294 00000436 00000001 1 0 -1 - 00 0000005601d080080000000000000000, 0000000000000051
295 00000437 00000001 1 0 -1 - 08 00023b3001d0823f0000000000000000, 0000000000000000
296 00000438 00000001 1 0 -1 - 08 0000005801d0807b0000000000000000, 0000000000000000
297 00000439 00000001 1 0 -1 - 08 00023b3201d080a10000000000000000, 0000000000000000
298 0000043a 00000001 1 0 -1 - 08 00023b3401d080a30000000000000000, 0000000000000000
299 0000043b 00000001 1 0 -1 - 08 00023b3601d080b30000000000000000, 0000000000000000
300 0000043c 00000001 1 0 -1 - 08 00023b3801d080b40000000000000000, 0000000000000000
301
302 where the columns are:
303
304 ======= ===============================================================
305 COLUMN DESCRIPTION
306 ======= ===============================================================
307 COOKIE The cookie debug ID (also appears in traces)
308 VOLUME The parent volume cookie debug ID
309 REF Number of references on the volume cookie
310 ACT Number of times the cookie is marked for in use
311 ACC Number of access pins in the cookie
312 S State of the cookie
313 FL Flags on the cookie
314 DEF Key, auxiliary data
315 ======= ===============================================================
316
317
318 Debugging
319 =========
320
321 If CONFIG_NETFS_DEBUG is enabled, the FS-Cache facility and NETFS support can
322 have runtime debugging enabled by adjusting the value in::
323
324 /sys/module/netfs/parameters/debug
325
326 This is a bitmask of debugging streams to enable:
327
328 ======= ======= =============================== =======================
329 BIT VALUE STREAM POINT
330 ======= ======= =============================== =======================
331 0 1 Cache management Function entry trace
332 1 2 Function exit trace
333 2 4 General
334 3 8 Cookie management Function entry trace
335 4 16 Function exit trace
336 5 32 General
337 6-8 (Not used)
338 9 512 I/O operation management Function entry trace
339 10 1024 Function exit trace
340 11 2048 General
341 ======= ======= =============================== =======================
342
343 The appropriate set of values should be OR'd together and the result written to
344 the control file. For example::
345
346 echo $((1|8|512)) >/sys/module/netfs/parameters/debug
347
348 will turn on all function entry debugging.
349

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

개요와 투명한 캐시 경로

1-90

FS-Cache는 네트워크 파일시스템용 범용 캐시이지만 ISO9660 파일시스템 같은 다른 대상의 caching에도 사용할 수 있습니다.

FS-Cache는 NFS, AFS, 9P 같은 네트워크 파일시스템 및 netfs library와 CacheFS, CacheFiles 같은 cache backend 사이를 중재합니다. 네트워크 파일시스템은 FS-Cache에 객체와 I/O를 요청하고, FS-Cache는 선택된 backend를 통해 실제 backing store를 사용합니다.

사용자 관점에서 캐시는 투명합니다. 예를 들어 원격 server의 데이터를 NFS가 제공하고, NFS는 VFS에 파일을 노출하는 동시에 FS-Cache를 통해 CacheFiles에 데이터를 저장합니다. CacheFiles는 Ext3 같은 로컬 파일시스템을 backing store로 사용하고 사용자 공간 `cachefilesd`가 관리 작업을 돕습니다. 프로세스는 이 중간 경로를 직접 다루지 않습니다.

FS-Cache는 netfs 파일을 열 때 전체 파일을 캐시에 먼저 내려받은 뒤 cache inode에서 page를 제공하는 방식을 사용하지 않습니다.

그 이유는 캐시 없이도 실용적으로 동작해야 하고, 접근 가능한 파일 크기가 캐시 크기에 제한되면 안 되며, mapping된 library를 포함한 열린 파일 전체 크기도 캐시 크기에 제한되면 안 되기 때문입니다.

또한 사용자가 `file` 명령처럼 파일의 작은 부분을 한 번 확인하려고 전체 파일을 내려받도록 강제해서는 안 됩니다. 대신 FS-Cache는 netfs가 요청할 때 필요한 chunk만 제공합니다.

FS-Cache 중재 구조
NFS·AFS·9P가 객체와 I/O 요청 생성일부 netfs는 `netfs lib`를 통해 요청FS-Cache가 cookie·상태·backend 선택을 중재CacheFS 또는 CacheFiles backend로 전달backend가 block device나 로컬 cache directory에 저장

원문의 첫 번째 ASCII 구조도를 계층별 흐름으로 정리했습니다.

사용자에게 투명한 데이터 경로
Process가 VFS를 통해 NFS 파일 접근NFS가 server에서 필요한 range를 가져옴동시에 FS-Cache가 CacheFiles에 chunk 저장·조회CacheFiles가 로컬 Ext3 backing store 사용`cachefilesd`는 사용자 공간에서 CacheFiles 관리

원문의 kernel/user-space 구조도를 요청과 관리 경로로 분리했습니다.

.. SPDX-License-Identifier: GPL-2.0

==========================
General Filesystem Caching
==========================

Overview
========

This facility is a general purpose cache for network filesystems, though it
could be used for caching other things such as ISO9660 filesystems too.

FS-Cache mediates between cache backends (such as CacheFiles) and network
filesystems::

        +---------+
        |         |                                    +--------------+
        |   NFS   |--+                                 |              |
        |         |  |                             +-->|   CacheFS    |
        +---------+  |               +----------+  |   |  /dev/hda5   |
                     |               |          |  |   +--------------+
        +---------+  +-------------->|          |  |
        |         |      +-------+   |          |--+
        |   AFS   |----->|       |   | FS-Cache |
        |         |      | netfs |-->|          |--+
        +---------+  +-->|  lib  |   |          |  |
                     |   |       |   |          |  |   +--------------+
        +---------+  |   +-------+   +----------+  |   |              |
        |         |  |                             +-->|  CacheFiles  |
        |   9P    |--+                                 |  /var/cache  |
        |         |                                    +--------------+
        +---------+

Or to look at it another way, FS-Cache is a module that provides a caching
facility to a network filesystem such that the cache is transparent to the
user::

        +---------+
        |         |
        | Server  |
        |         |
        +---------+
             |                  NETWORK
        ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             |
             |           +----------+
             V           |          |
        +---------+      |          |
        |         |      |          |
        |   NFS   |----->| FS-Cache |
        |         |      |          |--+
        +---------+      |          |  |   +--------------+   +--------------+
             |           |          |  |   |              |   |              |
             V           +----------+  +-->|  CacheFiles  |-->|  Ext3        |
        +---------+                        |  /var/cache  |   |  /dev/sda6   |
        |         |                        +--------------+   +--------------+
        |   VFS   |                                ^                     ^
        |         |                                |                     |
        +---------+                                +--------------+      |
             |                  KERNEL SPACE                      |      |
        ~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~|~~~~
             |                  USER SPACE                        |      |
             V                                                    |      |
        +---------+                                           +--------------+
        |         |                                           |              |
        | Process |                                           | cachefilesd  |
        |         |                                           |              |
        +---------+                                           +--------------+


FS-Cache does not follow the idea of completely loading every netfs file
opened in its entirety into a cache before permitting it to be accessed and
then serving the pages out of that cache rather than the netfs inode because:

 (1) It must be practical to operate without a cache.

 (2) The size of any accessible file must not be limited to the size of the
     cache.

 (3) The combined size of all opened files (this includes mapped libraries)
     must not be limited to the size of the cache.

 (4) The user should not be forced to download an entire file just to do a
     one-off access of a small portion of it (such as might be done with the
     "file" program).

It instead serves the cache out in chunks as and when requested by the netfs
using it.

FS-Cache가 제공하는 기능

91-153

여러 캐시를 동시에 사용할 수 있으며 tag로 캐시를 명시적으로 선택할 수 있습니다. 접근 중인 경우에도 캐시를 언제든 추가하거나 제거할 수 있습니다.

netfs interface는 netfs와 backend 어느 쪽이든 파일의 caching 기능을 철회할 수 있게 합니다. netfs에는 가능한 한 오류를 적게 반환하고, 캐시의 내부 실패를 netfs가 알지 못한 채 계속 동작하게 하는 방식을 선호합니다.

cookie는 cache, volume, data file의 세 종류입니다. cache cookie는 캐시 전체를 나타내며 보통 netfs에 보이지 않습니다. netfs는 파일 모음, 일반적으로 superblock에 해당하는 volume cookie를 받고 inode에 해당하는 데이터를 caching할 때 data file cookie를 사용합니다.

volume은 key로 매칭합니다. 이 key는 한 superblock을 다른 것과 구별하는 데 필요한 모든 정보를 encode한 출력 가능한 문자열이고 유효한 pathname이어야 합니다. cell name, server address, volume name, share path 등을 조합할 수 있습니다.

data cookie도 key로 매칭하지만 이 key는 volume 안의 객체를 나타내는 binary blob입니다. volume key를 blob에 다시 넣을 필요는 없습니다. inode number와 uniquifier 또는 file handle 등이 들어갈 수 있습니다.

cookie를 in-use로 표시하면 backing resource를 설정하고 pin하여 culling을 막습니다. 짧은 시간 사용되지 않은 cookie는 timed garbage collection으로 제거해 resource 부하를 줄입니다. 이 동작은 파일 open과 close에 맞춰 사용하도록 의도되었습니다.

하나의 cookie는 동시에 여러 번 in-use로 표시할 수 있으며 각 mark는 대응하는 unuse가 필요합니다.

begin/end access 함수는 operation 동안 cache withdrawal을 지연하고 구조체를 보고 있는 동안 해제되지 않게 합니다.

data I/O는 netfs가 `iov_iter`로 설명한 buffer와 cache 사이의 비동기 DIO로 수행합니다. invalidation 기능은 캐시 데이터를 버리고 오래된 데이터에 접근 중인 I/O를 처리합니다. cookie를 release할 때 retire하면 객체를 캐시에서 제거합니다.

netfs용 FS-Cache API는 `Documentation/filesystems/caching/netfs-api.rst`, cache backend API는 `Documentation/filesystems/caching/backend-api.rst`에 있습니다.

Cookie와 key 모델
Cookie대표 범위Key
Cachebackend 캐시 전체이름·tag로 선택
Volume보통 netfs superblock출력 가능한 유효 pathname
Data file보통 inode·file handlevolume 내부 binary blob

cache 전체에서 inode 데이터까지 식별 범위를 좁힙니다.

FS-Cache provides the following facilities:

   * More than one cache can be used at once.  Caches can be selected
     explicitly by use of tags.

   * Caches can be added / removed at any time, even whilst being accessed.

   * The netfs is provided with an interface that allows either party to
     withdraw caching facilities from a file (required for (2)).

   * The interface to the netfs returns as few errors as possible, preferring
     rather to let the netfs remain oblivious.

   * There are three types of cookie: cache, volume and data file cookies.
     Cache cookies represent the cache as a whole and are not normally visible
     to the netfs; the netfs gets a volume cookie to represent a collection of
     files (typically something that a netfs would get for a superblock); and
     data file cookies are used to cache data (something that would be got for
     an inode).

   * Volumes are matched using a key.  This is a printable string that is used
     to encode all the information that might be needed to distinguish one
     superblock, say, from another.  This would be a compound of things like
     cell name or server address, volume name or share path.  It must be a
     valid pathname.

   * Cookies are matched using a key.  This is a binary blob and is used to
     represent the object within a volume (so the volume key need not form
     part of the blob).  This might include things like an inode number and
     uniquifier or a file handle.

   * Cookie resources are set up and pinned by marking the cookie in-use.
     This prevents the backing resources from being culled.  Timed garbage
     collection is employed to eliminate cookies that haven't been used for a
     short while, thereby reducing resource overload.  This is intended to be
     used when a file is opened or closed.

     A cookie can be marked in-use multiple times simultaneously; each mark
     must be unused.

   * Begin/end access functions are provided to delay cache withdrawal for the
     duration of an operation and prevent structs from being freed whilst
     we're looking at them.

   * Data I/O is done by asynchronous DIO to/from a buffer described by the
     netfs using an iov_iter.

   * An invalidation facility is available to discard data from the cache and
     to deal with I/O that's in progress that is accessing old data.

   * Cookies can be "retired" upon release, thereby causing the object to be
     removed from the cache.


The netfs API to FS-Cache can be found in:

        Documentation/filesystems/caching/netfs-api.rst

The cache backend API to FS-Cache can be found in:

        Documentation/filesystems/caching/backend-api.rst

`/proc/fs/fscache/stats`

154-221

`CONFIG_FSCACHE_STATS=y`로 FS-Cache를 빌드하면 통계를 수집해 `/proc/fs/fscache/stats`에 표시합니다.

`Cookies` class에서 `n`은 할당된 data storage cookie 수, `v`는 volume index cookie 수, `vcol`은 volume index key 충돌 수, `voom`은 volume cookie 할당 중 OOM 사건 수입니다.

`Acquire`의 `n`은 acquire cookie 요청 수, `ok`는 성공 수, `oom`은 `ENOMEM`으로 실패한 수입니다.

`LRU`의 `n`은 현재 LRU에 있는 cookie 수, `exp`는 LRU에서 만료된 수, `rmv`는 LRU에서 제거된 수, `drp`는 LRU 상태에서 relinquish 또는 withdraw된 수, `at`은 다음 LRU cull까지의 jiffy입니다.

`Invals n`은 invalidation 횟수입니다. `Updates n`은 update cookie 요청 수, `rsz`는 resize 요청 수, `rsn`은 건너뛴 resize 요청 수입니다.

`Relinqs n`은 relinquish cookie 요청 수, `rtr`은 `retire=true`인 요청 수, `drop`은 재acquire를 더 이상 막지 않는 cookie 수입니다.

`NoSpace nwr`은 공간 부족으로 거부된 write 요청 수, `ncr`은 create 요청 수, `cull`은 공간을 만들기 위해 cull한 객체 수입니다. `IO rd`와 `wr`은 캐시 read 및 write operation 수입니다.

Netfslib도 자체 통계 counter를 추가합니다.

FS-Cache 통계 class
Class주요 event의미
Cookies`n`, `v`, `vcol`, `voom`data·volume cookie와 충돌·OOM
Acquire`n`, `ok`, `oom`cookie 획득 요청과 결과
LRU`n`, `exp`, `rmv`, `drp`, `at`LRU 수명과 다음 cull
Invals / Updates`n`, `rsz`, `rsn`무효화와 resize
Relinqs`n`, `rtr`, `drop`release·retire·재획득 차단
NoSpace`nwr`, `ncr`, `cull`공간 부족과 culling
IO`rd`, `wr`cache read·write operation

원문의 ASCII 표를 운영 영역별 counter로 정리했습니다.

Statistical Information
=======================

If FS-Cache is compiled with the following options enabled::

        CONFIG_FSCACHE_STATS=y

then it will gather certain statistics and display them through:

        /proc/fs/fscache/stats

This shows counts of a number of events that can happen in FS-Cache:

+--------------+-------+-------------------------------------------------------+
|CLASS         |EVENT  |MEANING                                                |
+==============+=======+=======================================================+
|Cookies       |n=N    |Number of data storage cookies allocated               |
+              +-------+-------------------------------------------------------+
|              |v=N    |Number of volume index cookies allocated               |
+              +-------+-------------------------------------------------------+
|              |vcol=N |Number of volume index key collisions                  |
+              +-------+-------------------------------------------------------+
|              |voom=N |Number of OOM events when allocating volume cookies    |
+--------------+-------+-------------------------------------------------------+
|Acquire       |n=N    |Number of acquire cookie requests seen                 |
+              +-------+-------------------------------------------------------+
|              |ok=N   |Number of acq reqs succeeded                           |
+              +-------+-------------------------------------------------------+
|              |oom=N  |Number of acq reqs failed on ENOMEM                    |
+--------------+-------+-------------------------------------------------------+
|LRU           |n=N    |Number of cookies currently on the LRU                 |
+              +-------+-------------------------------------------------------+
|              |exp=N  |Number of cookies expired off of the LRU               |
+              +-------+-------------------------------------------------------+
|              |rmv=N  |Number of cookies removed from the LRU                 |
+              +-------+-------------------------------------------------------+
|              |drp=N  |Number of LRU'd cookies relinquished/withdrawn         |
+              +-------+-------------------------------------------------------+
|              |at=N   |Time till next LRU cull (jiffies)                      |
+--------------+-------+-------------------------------------------------------+
|Invals        |n=N    |Number of invalidations                                |
+--------------+-------+-------------------------------------------------------+
|Updates       |n=N    |Number of update cookie requests seen                  |
+              +-------+-------------------------------------------------------+
|              |rsz=N  |Number of resize requests                              |
+              +-------+-------------------------------------------------------+
|              |rsn=N  |Number of skipped resize requests                      |
+--------------+-------+-------------------------------------------------------+
|Relinqs       |n=N    |Number of relinquish cookie requests seen              |
+              +-------+-------------------------------------------------------+
|              |rtr=N  |Number of rlq reqs with retire=true                    |
+              +-------+-------------------------------------------------------+
|              |drop=N |Number of cookies no longer blocking re-acquisition    |
+--------------+-------+-------------------------------------------------------+
|NoSpace       |nwr=N  |Number of write requests refused due to lack of space  |
+              +-------+-------------------------------------------------------+
|              |ncr=N  |Number of create requests refused due to lack of space |
+              +-------+-------------------------------------------------------+
|              |cull=N |Number of objects culled to make space                 |
+--------------+-------+-------------------------------------------------------+
|IO            |rd=N   |Number of read operations in the cache                 |
+              +-------+-------------------------------------------------------+
|              |wr=N   |Number of write operations in the cache                |
+--------------+-------+-------------------------------------------------------+

Netfslib will also add some stats counters of its own.

Cache cookie 목록

222-252

FS-Cache는 cache cookie 목록을 procfs로 제공합니다. 원문 경로 표기에는 `/proc/fs/fscache/cookies`가 나오지만 예시 명령은 `/proc/fs/fscache/caches`를 읽습니다.

출력의 `CACHE`는 trace에도 표시되는 cache cookie debug ID, `REF`는 cookie reference 수, `VOLS`는 이 캐시의 volume cookie 수, `OBJS`는 사용 중인 cache object 수, `ACCES`는 캐시를 pin하는 access 수입니다.

`S`는 상태, `NAME`은 캐시 이름입니다. 상태는 inactive `-`, preparing `P`, active `A`, error `E`, withdrawing `W` 중 하나입니다.

Cache 목록 열
설명
`CACHE`cache cookie debug ID
`REF`reference 수
`VOLS`volume cookie 수
`OBJS`사용 중인 cache object 수
`ACCES`cache access pin 수
`S``-`, `P`, `A`, `E`, `W` 상태
`NAME`캐시 이름

cache cookie의 수명과 하위 객체 사용량을 보여 줍니다.

Cache List
==========

FS-Cache provides a list of cache cookies:

        /proc/fs/fscache/cookies

This will look something like::

        # cat /proc/fs/fscache/caches
        CACHE    REF   VOLS  OBJS  ACCES S NAME
        ======== ===== ===== ===== ===== = ===============
        00000001     2     1  2123     1 A default

where the columns are:

        =======        ===============================================================
        COLUMN        DESCRIPTION
        =======        ===============================================================
        CACHE        Cache cookie debug ID (also appears in traces)
        REF        Number of references on the cache cookie
        VOLS        Number of volumes cookies in this cache
        OBJS        Number of cache objects in use
        ACCES        Number of accesses pinning the cache
        S        State
        NAME        Name of the cache.
        =======        ===============================================================

The state can be (-) Inactive, (P)reparing, (A)ctive, (E)rror or (W)ithdrawing.

Volume cookie 목록

253-280

FS-Cache는 `/proc/fs/fscache/volumes`에 volume cookie 목록을 제공합니다.

`VOLUME`은 trace에도 표시되는 volume cookie debug ID, `REF`는 volume cookie reference 수, `nCOOK`은 volume 안의 cookie 수, `ACC`는 캐시를 pin하는 access 수입니다.

`FL`은 volume cookie flag, `CACHE`는 캐시 이름 또는 `-`, `KEY`는 volume indexing key입니다.

Volume 목록 열
설명
`VOLUME`volume cookie debug ID
`REF`volume reference 수
`nCOOK`volume 안 cookie 수
`ACC`access pin 수
`FL`volume flag
`CACHE`cache 이름 또는 `-`
`KEY`volume indexing key

volume별 cookie 수와 cache 연결, indexing key를 표시합니다.

Volume List
===========

FS-Cache provides a list of volume cookies:

        /proc/fs/fscache/volumes

This will look something like::

        VOLUME   REF   nCOOK ACC FL CACHE           KEY
        ======== ===== ===== === == =============== ================
        00000001    55    54   1 00 default         afs,example.com,100058

where the columns are:

        =======        ===============================================================
        COLUMN        DESCRIPTION
        =======        ===============================================================
        VOLUME        The volume cookie debug ID (also appears in traces)
        REF        Number of references on the volume cookie
        nCOOK        Number of cookies in the volume
        ACC        Number of accesses pinning the cache
        FL        Flags on the volume cookie
        CACHE        Name of the cache or "-"
        KEY        The indexing key for the volume
        =======        ===============================================================

NETFS runtime debugging

318-348

`CONFIG_NETFS_DEBUG`를 활성화하면 `/sys/module/netfs/parameters/debug` 값을 조정해 FS-Cache와 NETFS runtime debugging을 켤 수 있습니다.

bitmask의 bit 0~2, 값 1·2·4는 cache management의 function entry, function exit, general stream입니다. bit 3~5, 값 8·16·32는 cookie management의 같은 세 stream입니다. bit 6~8은 사용하지 않습니다. bit 9~11, 값 512·1024·2048은 I/O operation management의 entry, exit, general stream입니다.

필요한 값을 OR로 결합해 control file에 씁니다. `echo $((1|8|512)) > /sys/module/netfs/parameters/debug`는 세 영역의 function entry debugging을 모두 켭니다.

NETFS debug bitmask
영역EntryExitGeneral
Cache management124
Cookie management81632
I/O operation management51210242048

관리 영역마다 entry·exit·general bit가 따로 있습니다.

Debugging
=========

If CONFIG_NETFS_DEBUG is enabled, the FS-Cache facility and NETFS support can
have runtime debugging enabled by adjusting the value in::

        /sys/module/netfs/parameters/debug

This is a bitmask of debugging streams to enable:

        =======        =======        ===============================        =======================
        BIT        VALUE        STREAM                                POINT
        =======        =======        ===============================        =======================
        0        1        Cache management                Function entry trace
        1        2                                        Function exit trace
        2        4                                        General
        3        8        Cookie management                Function entry trace
        4        16                                        Function exit trace
        5        32                                        General
        6-8                                                (Not used)
        9        512        I/O operation management        Function entry trace
        10        1024                                        Function exit trace
        11        2048                                        General
        =======        =======        ===============================        =======================

The appropriate set of values should be OR'd together and the result written to
the control file.  For example::

        echo $((1|8|512)) >/sys/module/netfs/parameters/debug

will turn on all function entry debugging.