Update Red Hat Copyright Notices
[nbdkit.git] / filters / cache / nbdkit-cache-filter.pod
blob75b4665944adbd9934629da91aef77db6dd4dd67
1 =head1 NAME
3 nbdkit-cache-filter - nbdkit caching filter
5 =head1 SYNOPSIS
7  nbdkit --filter=cache plugin [plugin-args...]
8                               [cache=writeback|writethrough|unsafe]
9                               [cache-min-block-size=SIZE]
10                               [cache-max-size=SIZE]
11                               [cache-high-threshold=N]
12                               [cache-low-threshold=N]
13                               [cache-on-read=true|false|/PATH]
15 =head1 DESCRIPTION
17 C<nbdkit-cache-filter> is a filter that adds caching on top of a
18 plugin.  This is useful if a plugin is slow or expensive to use,
19 because nbdkit will try to minimize requests to the plugin by caching
20 previous requests.
22 Note that many NBD I<clients> are able to do caching, and because the
23 caching happens on the client side it will usually be more effective
24 than caching inside the server.  This filter can be used if the client
25 does not have effective caching, or (with C<cache=unsafe>) to defeat
26 flush requests from the client (which is unsafe and can cause data
27 loss, as the name suggests).
29 This filter only caches image contents.  To cache image metadata, use
30 L<nbdkit-cacheextents-filter(1)> between this filter and the plugin.
31 To accelerate sequential reads, use L<nbdkit-readahead-filter(1)> or
32 L<nbdkit-scan-filter(1)> on top of this filter.
34 =head1 PARAMETERS
36 =over 4
38 =item B<cache=writeback>
40 Store writes in the cache.  They are not written to the plugin unless
41 an explicit flush is done by the client.
43 This is the default caching mode, and is safe if your client issues
44 flush requests correctly (which is true for modern Linux and other
45 well-written NBD clients).
47 =item B<cache=writethrough>
49 Always force writes through to the plugin.
51 This makes the cache less effective, but is necessary if your client
52 does not issue correct flush requests.
54 =item B<cache=unsafe>
56 Ignore flush requests.  Never write to the plugin unless the cache
57 grows too large.
59 This is dangerous and can cause data loss, but this may be acceptable
60 if you only use it for testing or with data that you don't care about
61 or can cheaply reconstruct.
63 =item B<cache-min-block-size=>SIZE
65 Set the minimum block size used by the cache.  This must be a power of
66 2 and E<ge> 4096.
68 The default is 64K, or the block size of the filesystem which contains
69 the temporary file storing the cache (whichever is larger).
71 =item B<cache-max-size=>SIZE
73 =item B<cache-high-threshold=>N
75 =item B<cache-low-threshold=>N
77 (nbdkit E<ge> 1.10)
79 Limit the size of the cache to C<SIZE>.  See L</CACHE MAXIMUM SIZE> below.
81 =item B<cache-on-read=true>
83 (nbdkit E<ge> 1.10)
85 Cache read requests as well as write and cache requests.  Any time a
86 block is read from the plugin, it is saved in the cache (if there is
87 sufficient space) so the same data can be served more quickly later.
89 Note that if the underlying data served by the plugin can be modified
90 by some other means (eg. something else can write to a file which is
91 being served by L<nbdkit-file-plugin(1)>), this option will cause
92 nbdkit to serve stale data because reads won't always go through to
93 the plugin.
95 =item B<cache-on-read=false>
97 Do not cache read requests (this is the default).
99 =item B<cache-on-read=/PATH>
101 (nbdkit E<ge> 1.28)
103 When F</PATH> (which must be an absolute path) exists, this behaves
104 like C<cache-on-read=true>, and when it does not exist like
105 C<cache-on-read=false>.  This allows you to control the cache-on-read
106 behaviour while nbdkit is running.
108 =back
110 =head1 CACHE MAXIMUM SIZE
112 By default the cache can grow to any size (although not larger than
113 the virtual size of the underlying plugin) and you have to ensure
114 there is sufficient space in C<$TMPDIR> for it.
116 Using the parameters C<cache-max-size>, C<cache-high-threshold> and
117 C<cache-low-threshold> you can limit the maximum size of the cache.
119 This requires kernel and filesystem support (for L<fallocate(2)>
120 C<FALLOC_FL_PUNCH_HOLE>), so it may not work on all platforms.
122 Some examples:
124 =over 4
126 =item C<cache-max-size=1G>
128 The cache is limited to around 1 gigabyte.
130 =item C<cache-max-size=1G cache-high-threshold=95 cache-low-threshold=80>
132 Once the cache size reaches 972M (95% of 1G), blocks are reclaimed
133 from the cache until the size is reduced to 819M (80% of 1G).
135 =back
137 The way this works is once the size of the cache exceeds
138 S<C<SIZE> ✕ the high threshold>, the filter works to reduce the size
139 of the cache until it is less than S<C<SIZE> ✕ the low threshold>.
140 Once the size is below the low threshold, no more reclaim work is done
141 until the size exceeds the high threshold again.
143 The default thresholds are high 95% and low 80%.  You must set
144 S<0 E<lt> low E<lt> high>.  The thresholds are expressed as integer
145 percentages of C<cache-max-size>.
147 Least recently used blocks are discarded first.
149 =head1 ENVIRONMENT VARIABLES
151 =over 4
153 =item C<TMPDIR>
155 The cache is stored in a temporary file located in F</var/tmp> by
156 default.  You can override this location by setting the C<TMPDIR>
157 environment variable before starting nbdkit.
159 =back
161 =head1 FILES
163 =over 4
165 =item F<$filterdir/nbdkit-cache-filter.so>
167 The filter.
169 Use C<nbdkit --dump-config> to find the location of C<$filterdir>.
171 =back
173 =head1 VERSION
175 C<nbdkit-cache-filter> first appeared in nbdkit 1.2.
177 =head1 SEE ALSO
179 L<nbdkit(1)>,
180 L<nbdkit-file-plugin(1)>,
181 L<nbdkit-cacheextents-filter(1)>,
182 L<nbdkit-cow-filter(1)>,
183 L<nbdkit-readahead-filter(1)>,
184 L<nbdkit-filter(3)>,
185 L<qemu-img(1)>.
187 =head1 AUTHORS
189 Eric Blake
191 Richard W.M. Jones
193 =head1 COPYRIGHT
195 Copyright Red Hat