DM: dm-compression: a compressed DM target for SSD
Subsystems (2)
This is a simple DM target supporting compression for SSD only. Under layer SSD must support 512B sector size, the target only supports 4k sector size.
Disk layout:
|super|...meta...|..data...|
Store unit is 4k (a block). Super is 1 block, which stores meta and data size and compression algorithm. Meta is a bitmap. For each data block, there are 5 bits meta.
Data:
Data of a block is compressed. Compressed data is round up to 512B, which is the payload. In disk, payload is stored at the begining of logical sector of the block. Let's look at an example. Say we store data to block A, which is in sector B(A*8), its orginal size is 4k, compressed size is 1500. Compressed data (CD) will use 3 sectors (512B). The 3 sectors are the payload. Payload will be stored at sector B.
---------------------------------------------------
... | CD1 | CD2 | CD3 | | | | | | ...
---------------------------------------------------
^B ^B+1 ^B+2 ^B+7 ^B+8
For this block, we will not use sector B+3 to B+7 (a hole). We use 4 meta bits to present payload size. The compressed size (1500) isn't stored in meta directly. Instead, we store it at the last 32bits of payload. In this example, we store it at the end of sector B+2. If compressed size + sizeof(32bits) crosses a sector, payload size will increase one sector. If payload uses 8 sectors, we store uncompressed data directly.
If IO size is bigger than one block, we can store the data as an extent. Data of the whole extent will compressed and stored in the similar way like above. The first block of the extent is the head, all others are the tail. If extent is 1 block, the block is head. We have 1 bit of meta to present if a block is head or tail. If 4 meta bits of head block can't store extent payload size, we will borrow tail block meta bits to store payload size. Max allowd extent size is 128k, so we don't compress/decompress too big size data.
Meta:
Modifying data will modify meta too. Meta will be written(flush) to disk depending on meta write policy. We support writeback and writethrough mode. In writeback mode, meta will be written to disk in an interval or a FLUSH request. In writethrough mode, data and meta data will be written to disk together.
Advantages:
1. simple. Since we store compressed data in-place, we don't need complicated disk data management.
2. efficient. For each 4k, we only need 5 bits meta. 1T data will use less than 200M meta, so we can load all meta into memory. And actual compression size is in payload. So if IO doesn't need RMW and we use writeback meta flush, we don't need extra IO for meta.
Disadvantages:
1. hole. Since we store compressed data in-place, there are a lot of holes (in above example, B+3 - B+7) Hole can impact IO, because we can't do IO merge.
2. 1:1 size. Compression doesn't change disk size. If disk is 1T, we can only store 1T data even we do compression.
But this is for SSD only. Generally SSD firmware has a FTL layer to map disk sectors to flash nand. High end SSD firmware has filesystem-like FTL.
1. hole. Disk has a lot of holes, but SSD FTL can still store data continuous in nand. Even we can't do IO merge in OS layer, SSD firmware can do it.
2. 1:1 size. On one side, we write compressed data to SSD, which means less data is written to SSD. This will be very helpful to improve SSD garbage collection, and so write speed and life cycle. So even this is a problem, the target is still helpful. On the other side, advanced SSD FTL can easily do thin provision. For example, if nand is 1T and we let SSD report it as 2T, and use the SSD as compressed target. In such SSD, we don't have the 1:1 size issue.
So if SSD FTL can map non-continuous disk sectors to continuous nand and support thin provision, the compressed target will work very well.
--- drivers/md/Kconfig | 6 drivers/md/Makefile | 1 drivers/md/dm-compression.c | 1464 ++++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-compression.h | 140 ++++ 4 files changed, 1611 insertions(+)
drivers/md/Kconfig +6 -0
@@ -290,6 +290,12 @@ config DM_CACHE_CLEANER A simple cache policy that writes back all data to the origin. Used when decommissioning a dm-cache. +config DM_COMPRESSION + tristate "Compression target" + depends on BLK_DEV_DM + ---help--- + Allow volume managers to compress data for SSD. + config DM_MIRROR tristate "Mirror target" depends on BLK_DEV_DM
drivers/md/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_DM_VERITY) += dm-verity.o obj-$(CONFIG_DM_CACHE) += dm-cache.o obj-$(CONFIG_DM_CACHE_MQ) += dm-cache-mq.o obj-$(CONFIG_DM_CACHE_CLEANER) += dm-cache-cleaner.o +obj-$(CONFIG_DM_COMPRESSION) += dm-compression.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-compression.c new file +1464 -0
1,464 lines not on this page · raw message
drivers/md/dm-compression.h new file +140 -0
140 lines not on this page · raw message
Alasdair G Kergon
maintainerI've not looked at this in any depth, but here are some first impressions:
Quoted 1 line · Shaohua Li
This is a simple DM target supporting compression for SSD only.
Presumably there'll be other disk layouts and other types of compression in future, so if you want to grab the generic name "compression" then please make sure the interface to the code supports such extensions. Use of the term "SSD" may also be too narrow as there could be other technologies that are not labelled "SSD" that could benefit from the target. At best, we say "for example, ssd" leaving things open for other uses.
IOW EITHER you should make it modular and supply a name to the ctr that tells it to use this specific combination OR if you don't think there'll need to be shared code with other compression types/disk layouts, rename this particular one to something more specific.
For this naming, focus on the key feature of the code, which seems to me to be the "in-place" or "in situ" nature of the so-called compression.
- If you don't have some form of thin provisioning underneath, why would you use this?
=> dm-compress-inplace / insitu
=> dm-compinsitu
=> dm-compress-thin (sub-module loaded from dm-compress)
=> dm-compressthin (standalone target)
-lzo ?
To use this compression target above dm-thin (likely to prefer larger block sizes), for example, could the block sizes be adapatable / configurable?
Please use dm_ / DM_ prefixes - with underscore - and choose one prefix to use consistently. I see "cp" (makes me think "copy") as well as "comp".
We don't label the fields in the STATUSTYPE_INFO output.
Do write Documentation/device-mapper/<target_name_without_leading_dm>.txt. E.g. what you wrote in the patch header should be moved into that file instead. (Use a recent documentation file as a model for the format of the file, such as verity or thin-provisioning.)
And don't be afraid to include more comments in the code for the benefit of people who are unfamiliar with the nuances of device-mapper targets:)
Alasdair
Alasdair G Kergon
maintainerQuoted 3 lines · Alasdair G Kergon
To use this compression target above dm-thin (likely to prefer larger block sizes), for example, could the block sizes be adapatable / configurable?
So a key feature of the underlying thin provisioning needs to be efficient tracking of a small sector size (which doesn't suit the existing dm-thin target). This compression target could sometimes benefit from a larger block size though, particularly where the data above has large blocks.
(Could we name this something like 'microcompression'?)
Alasdair
Quoted 27 lines · Alasdair G Kergon
I've not looked at this in any depth, but here are some first impressions:
Quoted 1 line · Shaohua Li
This is a simple DM target supporting compression for SSD only.
Presumably there'll be other disk layouts and other types of compression in future, so if you want to grab the generic name "compression" then please make sure the interface to the code supports such extensions. Use of the term "SSD" may also be too narrow as there could be other technologies that are not labelled "SSD" that could benefit from the target. At best, we say "for example, ssd" leaving things open for other uses.
IOW EITHER you should make it modular and supply a name to the ctr that tells it to use this specific combination OR if you don't think there'll need to be shared code with other compression types/disk layouts, rename this particular one to something more specific.
For this naming, focus on the key feature of the code, which seems to me to be the "in-place" or "in situ" nature of the so-called compression.
- If you don't have some form of thin provisioning underneath, why would you use this?
=> dm-compress-inplace / insitu
=> dm-compinsitu
=> dm-compress-thin (sub-module loaded from dm-compress)
=> dm-compressthin (standalone target)
Quoted 1 line
-lzo ?
Thanks for your time! I'll rename it.
Quoted 3 lines
To use this compression target above dm-thin (likely to prefer larger block sizes), for example, could the block sizes be adapatable / configurable?
block size (larger block size) is configurable, but currently I didn't implement yet.
Quoted 10 lines
Please use
dm_/DM_prefixes - with underscore - and choose one prefix to use consistently. I see "cp" (makes me think "copy") as well as "comp".We don't label the fields in the
STATUSTYPE_INFOoutput.Do write Documentation/device-mapper/<target_name_without_leading_dm>.txt. E.g. what you wrote in the patch header should be moved into that file instead. (Use a recent documentation file as a model for the format of the file, such as verity or thin-provisioning.)
ok
Quoted 3 lines
And don't be afraid to include more comments in the code for the benefit of people who are unfamiliar with the nuances of device-mapper targets:)
Sure, I'll add more in next post.
Thanks,
Shaohua