1 ================================
2 RBD Persistent Write-back Cache
3 ================================
5 .. index:: Ceph Block Device; Persistent Write-back Cache
7 Persistent Write-back Cache
8 ===========================
10 The persistent write-back cache provides a persistent, fault-tolerant write-back
11 cache for librbd-based RBD clients.
13 This cache uses a log-ordered write-back design which maintains checkpoints
14 internally so that writes that get flushed back to the cluster are always
15 crash consistent. Even if the client cache is lost entirely, the disk image is
16 still consistent but the data will appear to be stale.
18 This cache can be used with PMEM or SSD as a cache device.
23 The persistent write-back cache manages the cache data in a persistent device.
24 It looks for and creates cache files in a configured directory, and then caches
27 The persistent write-back cache can't be enabled without the exclusive-lock
28 feature. It tries to enable the write-back cache only when the exclusive lock
31 The cache provides two different persistence modes. In persistent-on-write mode,
32 the writes are completed only when they are persisted to the cache device and
33 will be readable after a crash. In persistent-on-flush mode, the writes are
34 completed as soon as it no longer needs the caller's data buffer to complete
35 the writes, but does not guarantee that writes will be readable after a crash.
36 The data is persisted to the cache device when a flush request is received.
38 Initially it defaults to the persistent-on-write mode and it switches to
39 persistent-on-flush mode after the first flush request is received.
41 Enable Persistent Write-back Cache
42 ========================================
44 To enable the persistent write-back cache, the following Ceph settings
47 rbd persistent cache mode = {cache-mode}
48 rbd plugins = pwl_cache
50 Value of {cache-mode} can be ``rwl``, ``ssd`` or ``disabled``. By default the
53 Here are some cache configuration settings:
55 - ``rbd_persistent_cache_path`` A file folder to cache data. This folder must
56 have DAX enabled (see `DAX`_) when using ``rwl`` mode to avoid performance
59 - ``rbd_persistent_cache_size`` The cache size per image. The minimum cache
62 - ``rbd_persistent_cache_log_periodic_stats`` This is a debug option. It is
63 used to emit periodic perf stats to the debug log if ``debug rbd pwl`` is
64 set to ``1`` or higher.
66 The above configurations can be set per-host, per-pool, per-image etc. Eg, to
67 set per-host, add the overrides to the appropriate `section`_ in the host's
68 ``ceph.conf`` file. To set per-pool, per-image, etc, please refer to the
69 ``rbd config`` `commands`_.
74 The persistent write-back cache is enabled when the exclusive lock is acquired,
75 and it is closed when the exclusive lock is released. To check the cache status,
76 users may use the command ``rbd status``. ::
78 rbd status {pool-name}/{image-name}
80 The status of the cache is shown, including present, clean, cache size and the
81 location. Currently the status is updated only at the time the cache is opened
82 and closed and therefore may appear to be out of date (e.g. show that the cache
83 is clean when it is actually dirty).
89 Image cache state: {"present":"true","empty":"false","clean":"true","cache_type":"ssd","pwl_host":"sceph9","pwl_path":"/tmp/rbd-pwl.rbd.abcdef123456.pool","pwl_size":1073741824}
94 To discard a cache file with ``rbd``, specify the ``image-cache invalidate``
95 option, the pool name and the image name. ::
97 rbd image-cache invalidate {pool-name}/{image-name}
99 The command removes the cache metadata of the corresponding image, disable
100 the cache feature and deletes the local cache file if it exists.
104 $ rbd image-cache invalidate rbd/foo
106 .. _section: ../../rados/configuration/ceph-conf/#configuration-sections
107 .. _commands: ../../man/8/rbd#commands
108 .. _DAX: https://www.kernel.org/doc/Documentation/filesystems/dax.txt