1LVMCACHE(7)                                                        LVMCACHE(7)
2
3
4

NAME

6       lvmcache — LVM caching
7
8

DESCRIPTION

10       The  cache  logical volume type uses a small and fast LV to improve the
11       performance of a large and slow LV.  It does this by storing  the  fre‐
12       quently  used blocks on the faster LV.  LVM refers to the small fast LV
13       as a cache pool LV.  The large slow LV is called the origin LV.  Due to
14       requirements  from dm-cache (the kernel driver), LVM further splits the
15       cache pool LV into two devices - the cache data LV and  cache  metadata
16       LV.  The cache data LV is where copies of data blocks are kept from the
17       origin LV to increase speed.  The cache metadata LV holds the  account‐
18       ing  information  that specifies where data blocks are stored (e.g.  on
19       the origin LV or on the cache data LV).  Users should be familiar  with
20       these  LVs if they wish to create the best and most robust cached logi‐
21       cal volumes.  All of these associated LVs must be in the same VG.
22
23

Cache Terms

25       origin LV           OriginLV      large slow LV
26       cache data LV       CacheDataLV   small fast LV for cache pool data
27       cache metadata LV   CacheMetaLV   small fast LV for cache pool metadata
28       cache pool LV       CachePoolLV   CacheDataLV + CacheMetaLV
29       cache LV            CacheLV       OriginLV + CachePoolLV
30
31

Cache Usage

33       The primary method for using a cache type logical volume:
34
35
36
37   0. create OriginLV
38       Create an LV or identify an existing LV to be the origin LV.
39
40       lvcreate -n OriginLV -L LargeSize VG SlowPVs
41
42       Example
43       # lvcreate -n lvol0 -L 100G vg
44
45
46
47   1. create CacheDataLV
48       Create the cache data LV.  This LV  will  hold  data  blocks  from  the
49       OriginLV.   The  size  of  this LV is the size of the cache and will be
50       reported as the size of the cache pool LV.
51
52       lvcreate -n CacheDataLV -L CacheSize VG FastPVs
53
54       Example
55       # lvcreate -n cache0 -L 10G vg /dev/fast
56
57
58
59   2. create CacheMetaLV
60       Create the cache metadata LV.  This LV will hold cache  pool  metadata.
61       The  size  of  this LV should be 1000 times smaller than the cache data
62       LV, with a minimum size of 8MiB.
63
64       lvcreate -n CacheMetaLV -L MetaSize VG FastPVs
65
66       Example
67       # lvcreate -n cache0meta -L 12M vg /dev/fast
68
69       # lvs -a vg
70         LV         VG   Attr       LSize   Pool Origin
71         cache0     vg   -wi-a-----  10.00g
72         cache0meta vg   -wi-a-----  12.00m
73         lvol0      vg   -wi-a----- 100.00g
74
75
76
77   3. create CachePoolLV
78       Combine the data and metadata LVs into a cache pool LV.   The  behavior
79       of the cache pool LV can be set in this step.
80       CachePoolLV takes the name of CacheDataLV.
81       CacheDataLV is renamed CachePoolLV_cdata and becomes hidden.
82       CacheMetaLV is renamed CachePoolLV_cmeta and becomes hidden.
83
84       lvconvert --type cache-pool --poolmetadata VG/CacheMetaLV
85              VG/CacheDataLV
86
87       Example
88       # lvconvert --type cache-pool --poolmetadata vg/cache0meta vg/cache0
89
90       # lvs -a vg
91         LV              VG   Attr       LSize   Pool Origin
92         cache0          vg   Cwi---C---  10.00g
93         [cache0_cdata]  vg   Cwi-------  10.00g
94         [cache0_cmeta]  vg   ewi-------  12.00m
95         lvol0           vg   -wi-a----- 100.00g
96
97
98
99   4. create CacheLV
100       Create  a  cache LV by linking the cache pool LV to the origin LV.  The
101       user accessible cache LV takes the name of the  origin  LV,  while  the
102       origin  LV  becomes a hidden LV with the name OriginLV_corig.  This can
103       be done while the origin LV is in use.
104       CacheLV takes the name of OriginLV.
105       OriginLV is renamed OriginLV_corig and becomes hidden.
106
107       lvconvert --type cache --cachepool VG/CachePoolLV VG/OriginLV
108
109       Example
110       # lvconvert --type cache --cachepool vg/cache0 vg/lvol0
111
112       # lvs -a vg
113         LV              VG   Attr       LSize   Pool   Origin
114         cache0          vg   Cwi---C---  10.00g
115         [cache0_cdata]  vg   Cwi-ao----  10.00g
116         [cache0_cmeta]  vg   ewi-ao----  12.00m
117         lvol0           vg   Cwi-a-C--- 100.00g cache0 [lvol0_corig]
118         [lvol0_corig]   vg   -wi-ao---- 100.00g
119
120
121

Cache Removal

123   Split a cache pool LV off of a cache LV
124
125
126       A cache pool LV can be disconnected from a cache LV, leaving an  unused
127       cache  pool  LV,  and  an uncached origin LV.  This command writes back
128       data from the cache pool to the origin LV when necessary.
129
130       lvconvert --splitcache VG/CacheLV
131
132
133   Removing a cache pool LV without removing its linked origin LV
134
135
136       This writes back data from the cache pool to the origin LV when  neces‐
137       sary, then removes the cache pool LV, leaving the uncached origin LV.
138
139       lvremove VG/CachePoolLV
140
141       An  alternative  command  that also disconnects the cache pool from the
142       cache LV, and deletes the cache pool:
143
144       lvconvert --uncache VG/CacheLV
145
146       Example
147       # lvs vg
148         LV     VG   Attr       LSize   Pool   Origin
149         cache0 vg   Cwi---C---  10.00g
150         lvol0  vg   Cwi-a-C--- 100.00g cache0 [lvol0_corig]
151
152       # lvremove vg/cache0
153
154       # lvs vg
155         LV    VG   Attr       LSize   Pool Origin
156         lvol0 vg   -wi-a----- 100.00g
157
158
159   Removing a cache LV: both origin LV and the cache pool LV
160
161
162       Removing a cache LV removes both the origin LV  and  the  linked  cache
163       pool LV.
164
165       lvremove VG/CacheLV
166
167
168

Cache Topics

170   Tolerate device failures in a cache pool LV
171
172
173       Users who are concerned about the possibility of failures in their fast
174       devices that could lead to data loss might consider making their  cache
175       pool sub-LVs redundant.
176
177       Example
178       0. Create an origin LV we wish to cache
179       # lvcreate -L 10G -n lv1 vg /dev/slow_devs
180
181       1. Create a 2-way RAID1 cache data LV
182       # lvcreate --type raid1 -m 1 -L 1G -n cache1 vg \
183            /dev/fast1 /dev/fast2
184
185       2. Create a 2-way RAID1 cache metadata LV
186       # lvcreate --type raid1 -m 1 -L 8M -n cache1meta vg \
187            /dev/fast1 /dev/fast2
188
189       3. Create a cache pool LV combining cache data LV and cache metadata LV
190       # lvconvert --type cache-pool --poolmetadata vg/cache1meta vg/cache1
191
192       4. Create a cached LV by combining the cache pool LV and origin LV
193       # lvconvert --type cache --cachepool vg/cache1 vg/lv1
194
195
196   Cache mode
197
198
199       The  default  cache  mode is "writethrough".  Writethrough ensures that
200       any data written will be stored both in the cache pool LV  and  on  the
201       origin  LV.   The loss of a device associated with the cache pool LV in
202       this case would not mean the loss of any data.
203
204       A second cache mode is  "writeback".   Writeback  delays  writing  data
205       blocks  from  the  cache  pool  back  to the origin LV.  This mode will
206       increase performance, but the loss of  a  device  associated  with  the
207       cache pool LV can result in lost data.
208
209       With  the --cachemode option, the cache mode can be set when creating a
210       cache LV, or changed on an existing cache LV.  The current  cache  mode
211       of a cache LV can be displayed with the cache_mode reporting option:
212
213       lvs -o+cache_mode VG/CacheLV
214
215       lvm.conf(5) allocation/cache_mode
216       defines the default cache mode.
217
218       Example
219       0. Create an origin LV we wish to cache (yours may already exist)
220       # lvcreate -L 10G -n lv1 vg /dev/slow
221
222       1. Create a cache data LV
223       # lvcreate -L 1G -n cache1 vg /dev/fast
224
225       2. Create a cache metadata LV
226       # lvcreate -L 8M -n cache1meta vg /dev/fast
227
228       3. Create a cache pool LV
229       # lvconvert --type cache-pool --poolmetadata vg/cache1meta vg/cache1
230
231       4. Create a cache LV by combining the cache pool LV and origin LV,
232          and use the writethrough cache mode.
233       # lvconvert --type cache --cachepool vg/cache1 \
234            --cachemode writethrough vg/lv1
235
236
237
238   Cache policy
239
240
241       The  cache subsystem has additional per-LV parameters: the cache policy
242       to use, and possibly tunable parameters for the  cache  policy.   Three
243       policies  are currently available: "smq" is the default policy, "mq" is
244       an older implementation, and "cleaner" is used to force  the  cache  to
245       write back (flush) all cached writes to the origin LV.
246
247       The  "mq"  policy  has a number of tunable parameters. The defaults are
248       chosen to be suitable for the majority of systems, but in special  cir‐
249       cumstances, changing the settings can improve performance.
250
251       With  the  --cachepolicy  and --cachesettings options, the cache policy
252       and settings can be set when creating a cache  LV,  or  changed  on  an
253       existing  cache  LV  (both  options can be used together).  The current
254       cache policy and settings of a cache  LV  can  be  displayed  with  the
255       cache_policy and cache_settings reporting options:
256
257       lvs -o+cache_policy,cache_settings VG/CacheLV
258
259       Example
260       Change the cache policy and settings of an existing cache LV.
261       # lvchange --cachepolicy mq --cachesettings \
262            'migration_threshold=2048 random_threshold=4' vg/lv1
263
264       lvm.conf(5) allocation/cache_policy
265       defines the default cache policy.
266
267       lvm.conf(5) allocation/cache_settings
268       defines the default cache settings.
269
270
271
272   Chunk size
273
274
275       The  size  of data blocks managed by a cache pool can be specified with
276       the --chunksize option when the cache LV is created.  The default  unit
277       is KiB. The value must be a multiple of 32KiB between 32KiB and 1GiB.
278
279       Using  a chunk size that is too large can result in wasteful use of the
280       cache, where small reads and writes can cause large sections of  an  LV
281       to  be  mapped  into the cache.  However, choosing a chunk size that is
282       too small can result in more overhead trying  to  manage  the  numerous
283       chunks  that  become  mapped into the cache.  Overhead can include both
284       excessive CPU time searching for chunks, and excessive memory  tracking
285       chunks.
286
287       Command to display the cache pool LV chunk size:
288       lvs -o+chunksize VG/CacheLV
289
290       lvm.conf(5) cache_pool_chunk_size
291       controls the default chunk size used when creating a cache LV.
292
293       The default value is shown by:
294       lvmconfig --type default allocation/cache_pool_chunk_size
295
296
297
298   Spare metadata LV
299
300
301       See  lvmthin(7) for a description of the "pool metadata spare" LV.  The
302       same concept is used for cache pools.
303
304
305   Automatic pool metadata LV
306
307
308       A cache data LV can be converted to cache pool LV without specifying  a
309       cache  pool  metadata  LV.  LVM will automatically create a metadata LV
310       from the same VG.
311
312       lvcreate -n CacheDataLV -L CacheSize VG
313       lvconvert --type cache-pool VG/CacheDataLV
314
315
316
317   Create a new cache LV without an existing origin LV
318
319
320       A cache LV can be created using  an  existing  cache  pool  without  an
321       existing origin LV.  A new origin LV is created and linked to the cache
322       pool in a single step.
323
324       lvcreate --type cache -L LargeSize -n CacheLV
325              --cachepool VG/CachePoolLV VG SlowPVs
326
327
328
329   Single step cache pool LV creation
330
331
332       A cache pool LV can be created with a single lvcreate  command,  rather
333       than using lvconvert on existing LVs.  This one command creates a cache
334       data LV, a cache metadata LV, and combines the two into  a  cache  pool
335       LV.
336
337       lvcreate --type cache-pool -L CacheSize -n CachePoolLV VG FastPVs
338
339
340
341   Convert existing LVs to cache types
342
343
344       When  an  existing  origin LV is converted to a cache LV, the specified
345       cache pool may be a normal LV, rather than a cache pool  LV.   In  this
346       case,  lvm will first convert the normal LV to a cache pool LV.  A pool
347       metadata LV may optionally be specified.
348
349       lvcreate -n OriginLV -L LargeSize VG
350       lvcreate -n CacheDataLV -L CacheSize VG
351       lvconvert --type cache --cachepool VG/CataDataLV VG/OriginLV
352
353       This is equivalent to:
354
355       lvcreate -n OriginLV -L LargeSize VG
356       lvcreate -n CacheDataLV -L CacheSize VG
357       lvconvert --type cache-pool VG/CacheDataLV
358       lvconvert --type cache --cachepool VG/CachePoolLV VG/OriginLV
359
360
361

SEE ALSO

363       lvm.conf(5), lvchange(8), lvcreate(8), lvdisplay(8), lvextend(8), lvre‐
364       move(8),  lvrename(8),  lvresize(8),  lvs(8),  vgchange(8), vgmerge(8),
365       vgreduce(8), vgsplit(8)
366
367
368
369Red Hat, Inc       LVM TOOLS 2.02.143(2)-RHEL6 (2016-12-13)        LVMCACHE(7)
Impressum