xref: /linux/Documentation/admin-guide/device-mapper/writecache.rst (revision 6cf2a73cb2bc422a03984b285a63632c27f8c4e4)
1*f0ba4377SMauro Carvalho Chehab=================
2*f0ba4377SMauro Carvalho ChehabWritecache target
3*f0ba4377SMauro Carvalho Chehab=================
4*f0ba4377SMauro Carvalho Chehab
548debafeSMikulas PatockaThe writecache target caches writes on persistent memory or on SSD. It
648debafeSMikulas Patockadoesn't cache reads because reads are supposed to be cached in page cache
748debafeSMikulas Patockain normal RAM.
848debafeSMikulas Patocka
948debafeSMikulas PatockaWhen the device is constructed, the first sector should be zeroed or the
1048debafeSMikulas Patockafirst sector should contain valid superblock from previous invocation.
1148debafeSMikulas Patocka
1248debafeSMikulas PatockaConstructor parameters:
13*f0ba4377SMauro Carvalho Chehab
1448debafeSMikulas Patocka1. type of the cache device - "p" or "s"
15*f0ba4377SMauro Carvalho Chehab
16*f0ba4377SMauro Carvalho Chehab	- p - persistent memory
17*f0ba4377SMauro Carvalho Chehab	- s - SSD
1848debafeSMikulas Patocka2. the underlying device that will be cached
1948debafeSMikulas Patocka3. the cache device
2048debafeSMikulas Patocka4. block size (4096 is recommended; the maximum block size is the page
2148debafeSMikulas Patocka   size)
2248debafeSMikulas Patocka5. the number of optional parameters (the parameters with an argument
2348debafeSMikulas Patocka   count as two)
24*f0ba4377SMauro Carvalho Chehab
25d284f824SMikulas Patocka	start_sector n		(default: 0)
26d284f824SMikulas Patocka		offset from the start of cache device in 512-byte sectors
2748debafeSMikulas Patocka	high_watermark n	(default: 50)
2848debafeSMikulas Patocka		start writeback when the number of used blocks reach this
2948debafeSMikulas Patocka		watermark
3048debafeSMikulas Patocka	low_watermark x		(default: 45)
3148debafeSMikulas Patocka		stop writeback when the number of used blocks drops below
3248debafeSMikulas Patocka		this watermark
3348debafeSMikulas Patocka	writeback_jobs n	(default: unlimited)
3448debafeSMikulas Patocka		limit the number of blocks that are in flight during
3548debafeSMikulas Patocka		writeback. Setting this value reduces writeback
3648debafeSMikulas Patocka		throughput, but it may improve latency of read requests
3748debafeSMikulas Patocka	autocommit_blocks n	(default: 64 for pmem, 65536 for ssd)
3848debafeSMikulas Patocka		when the application writes this amount of blocks without
3948debafeSMikulas Patocka		issuing the FLUSH request, the blocks are automatically
4048debafeSMikulas Patocka		commited
4148debafeSMikulas Patocka	autocommit_time ms	(default: 1000)
4248debafeSMikulas Patocka		autocommit time in milliseconds. The data is automatically
4348debafeSMikulas Patocka		commited if this time passes and no FLUSH request is
4448debafeSMikulas Patocka		received
4548debafeSMikulas Patocka	fua			(by default on)
4648debafeSMikulas Patocka		applicable only to persistent memory - use the FUA flag
4748debafeSMikulas Patocka		when writing data from persistent memory back to the
4848debafeSMikulas Patocka		underlying device
4948debafeSMikulas Patocka	nofua
5048debafeSMikulas Patocka		applicable only to persistent memory - don't use the FUA
5148debafeSMikulas Patocka		flag when writing back data and send the FLUSH request
5248debafeSMikulas Patocka		afterwards
53*f0ba4377SMauro Carvalho Chehab
5448debafeSMikulas Patocka		- some underlying devices perform better with fua, some
5548debafeSMikulas Patocka		  with nofua. The user should test it
5648debafeSMikulas Patocka
5748debafeSMikulas PatockaStatus:
5848debafeSMikulas Patocka1. error indicator - 0 if there was no error, otherwise error number
5948debafeSMikulas Patocka2. the number of blocks
6048debafeSMikulas Patocka3. the number of free blocks
6148debafeSMikulas Patocka4. the number of blocks under writeback
6248debafeSMikulas Patocka
6348debafeSMikulas PatockaMessages:
6448debafeSMikulas Patocka	flush
6548debafeSMikulas Patocka		flush the cache device. The message returns successfully
6648debafeSMikulas Patocka		if the cache device was flushed without an error
6748debafeSMikulas Patocka	flush_on_suspend
6848debafeSMikulas Patocka		flush the cache device on next suspend. Use this message
6948debafeSMikulas Patocka		when you are going to remove the cache device. The proper
7048debafeSMikulas Patocka		sequence for removing the cache device is:
71*f0ba4377SMauro Carvalho Chehab
7248debafeSMikulas Patocka		1. send the "flush_on_suspend" message
7348debafeSMikulas Patocka		2. load an inactive table with a linear target that maps
7448debafeSMikulas Patocka		   to the underlying device
7548debafeSMikulas Patocka		3. suspend the device
7648debafeSMikulas Patocka		4. ask for status and verify that there are no errors
7748debafeSMikulas Patocka		5. resume the device, so that it will use the linear
7848debafeSMikulas Patocka		   target
7948debafeSMikulas Patocka		6. the cache device is now inactive and it can be deleted
80