xref: /openbmc/linux/Documentation/admin-guide/device-mapper/writecache.rst (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
16cf2a73cSMauro Carvalho Chehab=================
26cf2a73cSMauro Carvalho ChehabWritecache target
36cf2a73cSMauro Carvalho Chehab=================
46cf2a73cSMauro Carvalho Chehab
56cf2a73cSMauro Carvalho ChehabThe writecache target caches writes on persistent memory or on SSD. It
66cf2a73cSMauro Carvalho Chehabdoesn't cache reads because reads are supposed to be cached in page cache
76cf2a73cSMauro Carvalho Chehabin normal RAM.
86cf2a73cSMauro Carvalho Chehab
96cf2a73cSMauro Carvalho ChehabWhen the device is constructed, the first sector should be zeroed or the
106cf2a73cSMauro Carvalho Chehabfirst sector should contain valid superblock from previous invocation.
116cf2a73cSMauro Carvalho Chehab
126cf2a73cSMauro Carvalho ChehabConstructor parameters:
136cf2a73cSMauro Carvalho Chehab
146cf2a73cSMauro Carvalho Chehab1. type of the cache device - "p" or "s"
156cf2a73cSMauro Carvalho Chehab	- p - persistent memory
166cf2a73cSMauro Carvalho Chehab	- s - SSD
176cf2a73cSMauro Carvalho Chehab2. the underlying device that will be cached
186cf2a73cSMauro Carvalho Chehab3. the cache device
196cf2a73cSMauro Carvalho Chehab4. block size (4096 is recommended; the maximum block size is the page
206cf2a73cSMauro Carvalho Chehab   size)
216cf2a73cSMauro Carvalho Chehab5. the number of optional parameters (the parameters with an argument
226cf2a73cSMauro Carvalho Chehab   count as two)
238b301af4SMauro Carvalho Chehab
246cf2a73cSMauro Carvalho Chehab	start_sector n		(default: 0)
256cf2a73cSMauro Carvalho Chehab		offset from the start of cache device in 512-byte sectors
266cf2a73cSMauro Carvalho Chehab	high_watermark n	(default: 50)
276cf2a73cSMauro Carvalho Chehab		start writeback when the number of used blocks reach this
286cf2a73cSMauro Carvalho Chehab		watermark
296cf2a73cSMauro Carvalho Chehab	low_watermark x		(default: 45)
306cf2a73cSMauro Carvalho Chehab		stop writeback when the number of used blocks drops below
316cf2a73cSMauro Carvalho Chehab		this watermark
326cf2a73cSMauro Carvalho Chehab	writeback_jobs n	(default: unlimited)
336cf2a73cSMauro Carvalho Chehab		limit the number of blocks that are in flight during
346cf2a73cSMauro Carvalho Chehab		writeback. Setting this value reduces writeback
356cf2a73cSMauro Carvalho Chehab		throughput, but it may improve latency of read requests
366cf2a73cSMauro Carvalho Chehab	autocommit_blocks n	(default: 64 for pmem, 65536 for ssd)
376cf2a73cSMauro Carvalho Chehab		when the application writes this amount of blocks without
386cf2a73cSMauro Carvalho Chehab		issuing the FLUSH request, the blocks are automatically
39751d5b27SAndrew Klychkov		committed
406cf2a73cSMauro Carvalho Chehab	autocommit_time ms	(default: 1000)
416cf2a73cSMauro Carvalho Chehab		autocommit time in milliseconds. The data is automatically
42751d5b27SAndrew Klychkov		committed if this time passes and no FLUSH request is
436cf2a73cSMauro Carvalho Chehab		received
446cf2a73cSMauro Carvalho Chehab	fua			(by default on)
456cf2a73cSMauro Carvalho Chehab		applicable only to persistent memory - use the FUA flag
466cf2a73cSMauro Carvalho Chehab		when writing data from persistent memory back to the
476cf2a73cSMauro Carvalho Chehab		underlying device
486cf2a73cSMauro Carvalho Chehab	nofua
496cf2a73cSMauro Carvalho Chehab		applicable only to persistent memory - don't use the FUA
506cf2a73cSMauro Carvalho Chehab		flag when writing back data and send the FLUSH request
516cf2a73cSMauro Carvalho Chehab		afterwards
526cf2a73cSMauro Carvalho Chehab
536cf2a73cSMauro Carvalho Chehab		- some underlying devices perform better with fua, some
546cf2a73cSMauro Carvalho Chehab		  with nofua. The user should test it
55cd039afaSMike Snitzer	cleaner
56cd039afaSMike Snitzer		when this option is activated (either in the constructor
57cd039afaSMike Snitzer		arguments or by a message), the cache will not promote
58cd039afaSMike Snitzer		new writes (however, writes to already cached blocks are
59cd039afaSMike Snitzer		promoted, to avoid data corruption due to misordered
60cd039afaSMike Snitzer		writes) and it will gradually writeback any cached
61cd039afaSMike Snitzer		data. The userspace can then monitor the cleaning
62cd039afaSMike Snitzer		process with "dmsetup status". When the number of cached
63cd039afaSMike Snitzer		blocks drops to zero, userspace can unload the
64cd039afaSMike Snitzer		dm-writecache target and replace it with dm-linear or
65cd039afaSMike Snitzer		other targets.
66cd039afaSMike Snitzer	max_age n
67cd039afaSMike Snitzer		specifies the maximum age of a block in milliseconds. If
68cd039afaSMike Snitzer		a block is stored in the cache for too long, it will be
69cd039afaSMike Snitzer		written to the underlying device and cleaned up.
70611c3e16SMikulas Patocka	metadata_only
71611c3e16SMikulas Patocka		only metadata is promoted to the cache. This option
72611c3e16SMikulas Patocka		improves performance for heavier REQ_META workloads.
735c0de3d7SMikulas Patocka	pause_writeback n	(default: 3000)
745c0de3d7SMikulas Patocka		pause writeback if there was some write I/O redirected to
755c0de3d7SMikulas Patocka		the origin volume in the last n milliseconds
766cf2a73cSMauro Carvalho Chehab
776cf2a73cSMauro Carvalho ChehabStatus:
7811093e6fSBagas Sanjaya
796cf2a73cSMauro Carvalho Chehab1. error indicator - 0 if there was no error, otherwise error number
806cf2a73cSMauro Carvalho Chehab2. the number of blocks
816cf2a73cSMauro Carvalho Chehab3. the number of free blocks
826cf2a73cSMauro Carvalho Chehab4. the number of blocks under writeback
832c6e755bSMikulas Patocka5. the number of read blocks
842c6e755bSMikulas Patocka6. the number of read blocks that hit the cache
85b2676e14SMikulas Patocka7. the number of write blocks
86b2676e14SMikulas Patocka8. the number of write blocks that hit uncommitted block
87b2676e14SMikulas Patocka9. the number of write blocks that hit committed block
88b2676e14SMikulas Patocka10. the number of write blocks that bypass the cache
89b2676e14SMikulas Patocka11. the number of write blocks that are allocated in the cache
90e3a35d03SMikulas Patocka12. the number of write requests that are blocked on the freelist
91e3a35d03SMikulas Patocka13. the number of flush requests
92*2ee73ef6SMikulas Patocka14. the number of discarded blocks
936cf2a73cSMauro Carvalho Chehab
946cf2a73cSMauro Carvalho ChehabMessages:
956cf2a73cSMauro Carvalho Chehab	flush
96e3a35d03SMikulas Patocka		Flush the cache device. The message returns successfully
976cf2a73cSMauro Carvalho Chehab		if the cache device was flushed without an error
986cf2a73cSMauro Carvalho Chehab	flush_on_suspend
99e3a35d03SMikulas Patocka		Flush the cache device on next suspend. Use this message
1006cf2a73cSMauro Carvalho Chehab		when you are going to remove the cache device. The proper
1016cf2a73cSMauro Carvalho Chehab		sequence for removing the cache device is:
1026cf2a73cSMauro Carvalho Chehab
1036cf2a73cSMauro Carvalho Chehab		1. send the "flush_on_suspend" message
1046cf2a73cSMauro Carvalho Chehab		2. load an inactive table with a linear target that maps
1056cf2a73cSMauro Carvalho Chehab		   to the underlying device
1066cf2a73cSMauro Carvalho Chehab		3. suspend the device
1076cf2a73cSMauro Carvalho Chehab		4. ask for status and verify that there are no errors
1086cf2a73cSMauro Carvalho Chehab		5. resume the device, so that it will use the linear
1096cf2a73cSMauro Carvalho Chehab		   target
1106cf2a73cSMauro Carvalho Chehab		6. the cache device is now inactive and it can be deleted
111cd039afaSMike Snitzer	cleaner
112cd039afaSMike Snitzer		See above "cleaner" constructor documentation.
113e3a35d03SMikulas Patocka	clear_stats
114e3a35d03SMikulas Patocka		Clear the statistics that are reported on the status line
115