dm-compress: introduce the dm-compress target
Subsystems (3)
Mikulas Patocka
maintainerPATCH v2 1/1 dm-compress: introduce the dm-compress target
dm-compress: introduce the dm-compress target
This commit introduces a new target dm-compress that provides transparent compression and decompression of block devices.
Changes since version 1:
- fix bugs found by Sashiko
- use the compression libraries directly as suggested by Eric Biggers
--- Documentation/admin-guide/device-mapper/dm-compress.rst | 61 + Documentation/admin-guide/device-mapper/index.rst | 1 drivers/md/Kconfig | 2 drivers/md/Makefile | 1 drivers/md/dm-bufio.c | 16 drivers/md/dm-compress/Kconfig | 16 drivers/md/dm-compress/Makefile | 11 drivers/md/dm-compress/algorithms.c | 130 ++ drivers/md/dm-compress/alloc.c | 505 ++++++++ drivers/md/dm-compress/cc.c | 214 +++ drivers/md/dm-compress/chunk.c | 440 +++++++ drivers/md/dm-compress/dm-compress.h | 215 +++ drivers/md/dm-compress/io.c | 640 ++++++++++ drivers/md/dm-compress/struct.h | 128 ++ drivers/md/dm-compress/target.c | 934 ++++++++++++++++ include/linux/dm-bufio.h | 14 16 files changed, 3328 insertions(+)
drivers/md/Kconfig +2 -0
@@ -719,4 +719,6 @@ source "drivers/md/dm-vdo/Kconfig" source "drivers/md/dm-pcache/Kconfig" +source "drivers/md/dm-compress/Kconfig" + endif # MD
drivers/md/dm-compress/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# dm-compress configuration +# + +config DM_COMPRESS + tristate "Compression target" + depends on BLK_DEV_DM + select DM_BUFIO + select LZ4_COMPRESS + select LZ4HC_COMPRESS + select LZ4_DECOMPRESS + select ZSTD_COMPRESS + select ZSTD_DECOMPRESS + help + This target stores compressed data.
drivers/md/dm-compress/dm-compress.h new file +215 -0
215 lines not on this page · raw message
drivers/md/dm-compress/target.c new file +934 -0
934 lines not on this page · raw message
drivers/md/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_DM_INTEGRITY) += dm-integri obj-$(CONFIG_DM_ZONED) += dm-zoned.o obj-$(CONFIG_DM_WRITECACHE) += dm-writecache.o obj-$(CONFIG_SECURITY_LOADPIN_VERITY) += dm-verity-loadpin.o +obj-$(CONFIG_DM_COMPRESS) += dm-compress/ ifeq ($(CONFIG_DM_INIT),y) dm-mod-objs += dm-init.o
drivers/md/dm-compress/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DM_COMPRESS) += dm-compress.o + +dm-compress-objs := \ + algorithms.o \ + alloc.o \ + cc.o \ + chunk.o \ + io.o \ + target.o
drivers/md/dm-compress/alloc.c new file +505 -0
505 lines not on this page · raw message
drivers/md/dm-compress/cc.c new file +214 -0
214 lines not on this page · raw message
drivers/md/dm-compress/io.c new file +640 -0
640 lines not on this page · raw message
Documentation/admin-guide/device-mapper/dm-compress.rst new file +61 -0
61 lines not on this page · raw message
drivers/md/dm-compress/chunk.c new file +440 -0
391 lines not on this page · raw message
drivers/md/dm-compress/struct.h new file +128 -0
128 lines not on this page · raw message
Documentation/admin-guide/device-mapper/index.rst +1 -0
Lines of this file are not shown. View the raw message.
drivers/md/dm-compress/algorithms.c new file +130 -0
130 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 13 potential issues to consider: - [High] dm-compress: bio reordering and blocking in dm_compress_pick_dio_for_chunk() - [High] dm-compress…
Thank you for your contribution! Sashiko AI review found 13 potential issues to consider:
- [High] dm-compress: bio reordering and blocking in dm_compress_pick_dio_for_chunk()
- [High] dm-compress: flush bios collide with chunk 0 in dm_compress_setup_flush()
- [Medium] dm-compress: stale c->n_blocks in dm_compress_resize_bitmaps() on small resize
- [Medium] dm-compress: missing vmap cache flush and bv_offset in cc->bio I/O
- [Medium] dm-compress: uninitialized memory written to disk in split sub-blocks
- [Medium] dm-compress: failed or unwritten clean chunks fail waiting writes on eviction
- [Medium] dm-compress: serialized cache eviction on c->lru.prev in process_chunk()
- [Medium] dm-compress: missing upper bound on n_chunks in dm_compress_ctr()
- [Medium] dm-compress: global mutex held across sync I/O in dm_compress_process_chunk()
- [Medium] dm-compress: single-CPU pinning on WQ_PERCPU compress_wq and extra wakeups
- [Medium] dm-compress: polling sleep in dm_compress_postsuspend() and high-order mempool
- [Medium] dm-compress: excessive workspace allocation in dm_compress_alloc_cached_chunk()
- [Low] dm-compress: outdated algorithm list and missing commit_time in dm-compress.rst
--
commit 5efe61997193e272b0ef53f7013815a0776520a4
Author: Mikulas Patocka <[email protected]>
dm-compress: introduce the dm-compress target
This commit introduces the dm-compress device-mapper target for transparent block device compression and decompression, along with a dm_bufio_forget_buffers_forced() helper in dm-bufio.
Quoted 5 lines
Documentation/admin-guide/device-mapper/dm-compress.rst new file +0
-0
[ ... ]
Quoted 1 line
Documentation/admin-guide/device-mapper/dm-compress.rst new file +0
-0@@ -0,0 +1,61 @@
[ ... ]
Quoted 4 lines
+6. the compression algorithm - the supported algorithms are:
Documentation/admin-guide/device-mapper/dm-compress.rst new file +3
-0+ deflate, lzo, 842, lz4, lz4hc, zstd + +7. the number of additional arguments
Documentation/admin-guide/device-mapper/dm-compress.rst line 55
Quoted 10 lines
Documentation/admin-guide/device-mapper/dm-compress.rst new file +10
-0+ +Additional arguments: + +meta_device:device + Store metadata on a separate device + +n_cached_chunks:number (default 128) + The number of cached decompressed chunks that is kept in memory. The + cached chunks are preallocated when the target is loaded. The memory + consumption of the target is n_cached_chunks*chunk_size*3.
[Severity: Low]
dm_compress_algorithms[] only implements lz4, lz4hc, and zstd, so passing deflate, lzo, or 842 to dm_compress_ctr() fails with -EINVAL. Also, the optional commit_time:<msec> argument accepted by dm_compress_ctr() is not listed under Additional arguments.
Quoted 5 lines
drivers/md/dm-compress/algorithms.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/algorithms.c new file +0
-0@@ -0,0 +1,130 @@
[ ... ]
drivers/md/dm-compress/algorithms.c line 75
Quoted 9 lines
drivers/md/dm-compress/algorithms.c new file +9
-0+static void *zstd_allocate_context (gfp_t gfp) +{ +zstd_parameters params; +size_t wksp_size; +struct zstd_ctx *ctx; + + params =zstd_get_params (ZSTD_DEF_LEVEL ,ZSTD_MAX_SIZE ); + wksp_size =max (zstd_cstream_workspace_bound (¶ms.cParams), +zstd_dstream_workspace_bound (ZSTD_MAX_SIZE ));
[Severity: Medium]
Should zstd_allocate_context() size the workspace with zstd_cctx_workspace_bound() and zstd_dctx_workspace_bound() for the configured chunk size instead of streaming bounds at a hardcoded 256 KiB ZSTD_MAX_SIZE?
zstd_compress() and zstd_decompress() only use single-pass zstd_init_cctx() and zstd_init_dctx(), so streaming bounds allocate ~512 KiB of unused stream buffers per context, while hardcoding ZSTD_MAX_SIZE over-allocates tables for small chunks and caps windowLog at 256 KiB for 512 KiB and 1 MiB chunks. In addition, dm_compress_alloc_cached_chunk() allocates full workspaces for all three algorithms (~1.9 MiB per cached chunk, or ~243 MiB for the default 128 chunks) even though compression only uses c->algorithm and LZ4 decompression does not use a context.
Quoted 5 lines
drivers/md/dm-compress/alloc.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/alloc.c new file +0
-0@@ -0,0 +1,505 @@
[ ... ]
Quoted 43 lines
drivers/md/dm-compress/alloc.c new file +43
-0+while (current_size < new_size) { +struct dm_buffer *bp; +size_t group_ptr, dir_ptr; +unsigned dir_offset, bmp_offset; +sector_t dir_block, bmp_block; +struct directory *dir; +__u64 *working_copy, *stable_copy; +unsigned need_sectors; + +block_location (c, current_size, &group_ptr, &dir_ptr, &dir_offset, &bmp_offset); + + need_sectors =0 ; +if (!bmp_offset && !dir_offset) + need_sectors =BUFFER_SECTORS *2 ; +else if (!bmp_offset) + need_sectors =BUFFER_SECTORS ; +if (n_allocated_sectors < need_sectors) { +sector_t existing_size; +if (c->meta_dev) { +dm_compress_error (c,"The metadata device is too small" , -ENOSPC ); +return -ENOSPC ; + } + existing_size = current_size; +align_allocated: + allocated_sector = current_size << c->log2_sectors_per_block; + n_allocated_sectors =0 ; +if (allocated_sector & (BUFFER_SECTORS -1 )) { +if (current_size >= new_size) { + current_size = existing_size; + goto finish; + } + current_size++; + goto align_allocated; + } +while (n_allocated_sectors < need_sectors) { +if (current_size >= new_size) { + current_size = existing_size; + goto finish; + } + current_size++; + n_allocated_sectors +=1 << c->log2_sectors_per_block; + } + }
[ ... ]
Quoted 15 lines
drivers/md/dm-compress/alloc.c new file +15
-0+finish: +if (did_something) { +bool b; + *need_sync = true; + b = !CC_VALID (c, &sb->n_cc_txc); +if (unlikely (!CC_CURRENT (c, &sb->n_cc_txc))) { +CC_SET_CURRENT (c, &sb->n_cc_txc); +WARN_ON (b !=CC_VALID (c, &sb->n_cc_txc)); + sb->n_blocks[!b] = sb->n_blocks[b]; + sb->n_chunks[!b] = sb->n_chunks[b]; + sb->n_used_metadata_blocks[!b] = sb->n_used_metadata_blocks[b]; + b = !b; + } + sb->n_blocks[b] =cpu_to_le64 (current_size); +if (c->meta_dev)
drivers/md/dm-compress/alloc.c line 505
Quoted 10 lines
drivers/md/dm-compress/alloc.c new file +10
-0+ sb->n_used_metadata_blocks[b] =cpu_to_le64 (allocated_sector /BUFFER_SECTORS ); + r =dm_compress_sync_rw_metadata (c,REQ_OP_WRITE ,DM_IO_KMEM ,0 , c->sb,SB_SECTORS ); +if (r) { +dm_compress_error (c,"Error writing superblock" , r); +return r; + } + c->n_blocks = current_size; + } +return 0 ; +}
[Severity: Medium]
What happens in dm_compress_resize_bitmaps() when a single-device target at a bitmap boundary is grown by fewer sectors than need_sectors?
The alignment/allocation loop restores current_size = existing_size and jumps to finish with did_something == false, leaving c->n_blocks set to new_size (and c->n_groups sized for new_size). The subsequent calls in dm_compress_preresume() to load_bitmap_directories(c, c->n_blocks) and dm_compress_get_free_space(c) then read the unallocated zero pointer (block 0, the superblock) as a bitmap or directory buffer and fail with -EUCLEAN, disabling the device.
Separately, in modify_bitmap() and dm_compress_prepare_chunk(), CC_SET_CURRENT() updates cc_txc before the committed slot is copied into the backup slot.
Quoted 5 lines
drivers/md/dm-compress/cc.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/cc.c new file +0
-0@@ -0,0 +1,214 @@
[ ... ]
Quoted 19 lines
drivers/md/dm-compress/cc.c new file +19
-0+ cc->compressed_data =__vmalloc (512UL << c->log2_sectors_per_chunk,GFP_KERNEL ); +if (!cc->compressed_data) + goto free_fail; + + cc->merging_data =__vmalloc (512UL << c->log2_sectors_per_chunk,GFP_KERNEL ); +if (!cc->merging_data) + goto free_fail; + +if (is_vmalloc_addr (cc->compressed_data)) { + cc->bio_vectors =DIV_ROUND_UP (512UL << c->log2_sectors_per_chunk,PAGE_SIZE ); + cc->bio =bio_kmalloc (cc->bio_vectors,GFP_KERNEL ); +if (!cc->bio) + goto free_fail; + bv =bio_inline_vecs (cc->bio); +for (v =0 ; v < cc->bio_vectors; v++) { + bv[v].bv_page =vmalloc_to_page (cc->compressed_data + (size_t )v *PAGE_SIZE ); + bv[v].bv_len =PAGE_SIZE ; + bv[v].bv_offset =0 ; + }
drivers/md/dm-compress/cc.c line 56
Quoted 10 lines
drivers/md/dm-compress/cc.c new file +10
-0+ }else { + cc->bio_vectors =1 ; + cc->bio =bio_kmalloc (cc->bio_vectors,GFP_KERNEL ); +if (!cc->bio) + goto free_fail; + bv =bio_inline_vecs (cc->bio); + bv[0 ].bv_page =virt_to_page (cc->compressed_data); + bv[0 ].bv_len =512UL << c->log2_sectors_per_chunk; + bv[0 ].bv_offset =0 ; + }
[Severity: Medium]
Does submitting cc->bio directly on vmalloc-backed cc->compressed_data pages need flush_kernel_vmap_range() before REQ_OP_WRITE in dm_compress_allocate_chunk() and invalidate_kernel_vmap_range() before CPU decompression reads cc->compressed_data?
Without vmap cache maintenance, architectures with virtually indexed caches that implement ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE can see stale cache aliases and corrupt compressed data. Also, in the !is_vmalloc_addr() branch, hardcoding bv[0].bv_offset = 0 instead of offset_in_page(cc->compressed_data) uses the wrong page offset if a small chunk allocation is not page-aligned.
[ ... ]
Quoted 31 lines
drivers/md/dm-compress/cc.c new file +31
-0+void dm_compress_wait_for_cached_chunk (struct dm_compress_io *dio) +{ +struct dm_compress *c = dio->c; +struct rb_node *parent, **node; + +list_add (&dio->waiting_list_entry, &c->waiting_bio_lru); + + parent =NULL ; + node = &c->waiting_bio_tree.rb_node; + +while (*node) { + struct dm_compress_io *tdio = container_of(*node, struct dm_compress_io, tree_entry); + parent = &tdio->tree_entry; +if (tdio->chunk > dio->chunk) { + node = &parent->rb_left; + }else { + node = &parent->rb_right; + } + } + +rb_link_node (&dio->tree_entry, parent, node); +rb_insert_color (&dio->tree_entry, &c->waiting_bio_tree); +} + +struct dm_compress_io *dm_compress_pick_dio_for_chunk (struct dm_compress *c,sector_t chunk) +{ +struct rb_node *node = c->waiting_bio_tree.rb_node; + +while (node) { + struct dm_compress_io *tdio = container_of(node, struct dm_compress_io, tree_entry); +if (tdio->chunk == chunk) {
drivers/md/dm-compress/cc.c line 182
Quoted 10 lines
drivers/md/dm-compress/cc.c new file +10
-0+return tdio; + } +if (tdio->chunk > chunk) + node = tdio->tree_entry.rb_left; +else + node = tdio->tree_entry.rb_right; + } + +return NULL ; +}
[Severity: High]
Can rb-tree rotations on c->waiting_bio_tree cause dm_compress_pick_dio_for_chunk() to return waiting bios for the same chunk out of submission order?
dm_compress_wait_for_cached_chunk() inserts duplicate chunk keys down rb_right, and rb_insert_color() / rb_erase() rotations can move a newer dio above an older dio with the same chunk key. dm_compress_pick_dio_for_chunk() returns the highest node matching chunk rather than the oldest one, so waiting writes and reads on the same chunk can be reordered and overwrite newer data with older data.
When dm_compress_chunk_decompress() calls dm_compress_process_bios_on_chunk() while cc->intent is INTENT_WRITE or INTENT_FREE, picking a waiting write or discard before a waiting read also causes dm_compress_process_chunk() to return false and break out of the loop before the read is served, after which the chunk is written out and evicted.
In addition, dm_compress_chunk_work_2() only calls dm_compress_process_pending_ios(), which stops immediately if oldest_dio is still blocked on a different chunk instead of waking bios waiting on cc->chunk, and the flush guard in dm_compress_process_chunk() only checks oldest_dio->is_flush, allowing new writes to bypass a queued flush when an older non-flush bio sits ahead of it in c->waiting_bio_lru.
Quoted 5 lines
drivers/md/dm-compress/chunk.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/chunk.c new file +0
-0@@ -0,0 +1,440 @@
[ ... ]
drivers/md/dm-compress/chunk.c line 326
Quoted 12 lines
drivers/md/dm-compress/chunk.c new file +12
-0+appended: + sub =dm_bufio_new (c->split_bufio, subblk, &bp); +if (IS_ERR (sub)) { +dm_compress_error (c,"Unable to create a new buffer" ,PTR_ERR (sub)); + goto free_ret; + } + this_step =min (block_size, len_compressed); +memcpy (sub, src_ptr, this_step); + src_ptr += this_step; + len_compressed -= this_step; +dm_bufio_mark_buffer_dirty (bp); +dm_bufio_release (bp);
[Severity: Medium]
When split_space < len_compressed < block_size, does memcpy(sub, src_ptr, this_step) leave the trailing block_size - this_step bytes of the dm_bufio_new() buffer uninitialized before writing the full block to disk?
Quoted 5 lines
drivers/md/dm-compress/io.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/io.c new file +0
-0@@ -0,0 +1,640 @@
[ ... ]
drivers/md/dm-compress/io.c line 77
Quoted 6 lines
drivers/md/dm-compress/io.c new file +6
-0+static void dm_compress_setup_flush (struct dm_compress_io *dio) +{ + dio->is_flush = true; + dio->chunk =0 ; + dio->offset_in_chunk =0 ; +}
[Severity: High]
Because dm_compress_setup_flush() sets dio->chunk = 0 and waiting flush bios are inserted into c->waiting_bio_tree, won't dm_compress_pick_dio_for_chunk(c, 0) match waiting REQ_PREFLUSH or REQ_FUA bios whenever chunk 0 finishes or fails?
If a read or decompression of chunk 0 fails, dm_compress_read_failed() -> dm_compress_process_bios_on_chunk(c, 0, status) will pick any waiting flush bio and complete it with chunk 0's read error without syncing the device. If chunk 0 finishes reading while another chunk is still in progress, picking the waiting flush bio in dm_compress_process_bios_on_chunk(c, 0, BLK_STS_OK) returns false from dm_compress_process_chunk() and breaks out of the loop before waking ready data bios waiting on chunk 0.
[ ... ]
Quoted 22 lines
drivers/md/dm-compress/io.c new file +22
-0+static bool dm_compress_process_chunk (struct dm_compress_io *dio) +{ +struct dm_compress *c = dio->c; +struct bio *bio =dm_bio_from_per_bio_data (dio,sizeof (struct dm_compress_io )); +struct cached_chunk *cc; +struct chunk_entry *ce; +struct dm_buffer *bp; +struct chunk_ptr *cp; + +if (unlikely (c->failed)) { + bio->bi_status =errno_to_blk_status (c->failed); +return true; + } + +if (unlikely (dio->is_flush)) { +if (dm_compress_is_something_in_progress (c)) +return false; +dm_compress_sync (c); +if (unlikely (c->failed)) + bio->bi_status =errno_to_blk_status (c->failed); +return true; + }
[ ... ]
Quoted 8 lines
drivers/md/dm-compress/io.c new file +8
-0+ ce =map_chunk (c, dio->chunk, &bp); +if (unlikely (IS_ERR (ce))) { + bio->bi_status =errno_to_blk_status (PTR_ERR (ce)); +return true; + } + cp = &ce->ptr[CC_VALID (c, &ce->cc_txc)]; +if (cp->algorithm ==ALGORITHM_ZERO ) { +if (bio_op (bio) ==REQ_OP_READ ) {
drivers/md/dm-compress/io.c line 273
Quoted 10 lines
drivers/md/dm-compress/io.c new file +10
-0+dm_bufio_release (bp); +zero_fill_bio (bio); +return true; + } +if (bio_op (bio) ==REQ_OP_DISCARD ) { +dm_bufio_release (bp); +return true; + } + } +dm_bufio_release (bp);
[Severity: Medium]
Does dm_compress_process_chunk() need to call map_chunk() on REQ_OP_WRITE cache misses, or hold c->mutex across synchronous metadata I/O and dm_compress_sync()?
On a write cache miss, map_chunk() performs up to two synchronous dm_bufio_read() calls under c->mutex even though ce and cp are immediately released without being used. Holding the global c->mutex across map_chunk() and dm_compress_sync() blocks all concurrent cache-hit reads, writes, and worker completions across the device.
Quoted 6 lines
drivers/md/dm-compress/io.c new file +6
-0+ + cc =dm_compress_new_cached_chunk (dio); +if (cc) { +struct cached_chunk *qc =dm_compress_find_cached_chunk (c, dio->chunk, cc); +if (unlikely (qc !=NULL )) { +dm_compress_release_cached_chunk (cc);
drivers/md/dm-compress/io.c line 289
Quoted 10 lines
drivers/md/dm-compress/io.c new file +10
-0+ cc = qc; + goto have_cached_chunk; + } + goto have_cached_chunk; + } + + cc = list_entry(c->lru.prev, struct cached_chunk, lru_entry); +dm_compress_enqueue_chunk (cc,INTENT_FREE ); +return false; +}
[Severity: Medium]
Once c->free_chunks is empty, doesn't always picking c->lru.prev serialize cache eviction on a single chunk?
Until c->lru.prev finishes compression and writeback and dm_compress_release_cached_chunk() unlinks it from c->lru, every subsequent cache miss targets the same c->lru.prev entry (where dm_compress_enqueue_chunk() is a no-op because cc->intent is already INTENT_FREE) instead of starting eviction on the next LRU chunks or synchronously reclaiming a clean idle chunk under c->mutex.
Quoted 21 lines
drivers/md/dm-compress/io.c new file +21
-0+ +static void dm_compress_chunk_work (struct work_struct *w) +{ + struct cached_chunk *cc = container_of(w, struct cached_chunk, work); +struct dm_compress *c = cc->c; +unsigned len_in, len_out, len_compressed, trailing_space; +int ret; +sector_t preferred_block; +struct dm_buffer *bp; +struct chunk_ptr *cp; +struct chunk_ptr old_cp, new_cp; + +init_completion (&cc->completion); + +if (memchr (cc->sector_tags,0 ,1U << c->log2_sectors_per_chunk)) { +dm_compress_read_and_decompress (cc); +return ; + } + +mutex_lock (&c->mutex); +if (cc->intent ==INTENT_READ ) {
drivers/md/dm-compress/io.c line 320
Quoted 10 lines
drivers/md/dm-compress/io.c new file +10
-0+ cc->intent =INTENT_IDLE ; +dm_compress_process_bios_on_chunk (c, cc->chunk,BLK_STS_OK ); +return ; + } +if (!cc->dirty) { +mutex_unlock (&c->mutex); +complete (&cc->completion); +dm_compress_chunk_work_2 (&cc->work); +return ; + }
[Severity: Medium]
Can a read failure on a chunk cause waiting or subsequent writes to fail?
When an in-flight read fails, dm_compress_read_failed() passes the read error status to dm_compress_process_bios_on_chunk(), which fails all bios waiting on that chunk, including waiting REQ_OP_WRITE and REQ_OP_DISCARD bios that would otherwise clear cc->failed in dm_compress_process_chunk() and overwrite the chunk. Moreover, because dm_compress_chunk_work() checks memchr(cc->sector_tags, 0, ...) before checking !cc->dirty, evicting a clean chunk that had a prior read failure (leaving sector_tags zeroed) calls dm_compress_read_and_decompress() -> dm_compress_read_failed() instead of releasing the clean chunk.
Quoted 5 lines
drivers/md/dm-compress/target.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/md/dm-compress/target.c new file +0
-0@@ -0,0 +1,934 @@
[ ... ]
drivers/md/dm-compress/target.c line 412
Quoted 6 lines
drivers/md/dm-compress/target.c new file +6
-0+if (sscanf (argv[4 ],"%llu%c" , ¶m, &dummy) !=1 || !param || param != (sector_t )param) { + ti->error ="Invalid number of chunks" ; + r = -EINVAL ; + goto bad; + } + c->n_chunks = param;
[Severity: Medium]
Should c->n_chunks be bounded in dm_compress_ctr() the same way c->n_blocks is?
If c->n_chunks >= ULLONG_MAX - CHUNKS_PER_BUFFER + 2, dm_sector_div_up(c->n_chunks, CHUNKS_PER_BUFFER) in initialize_device() wraps around 64-bit sector_t to 0 and formats a corrupted superblock with zero chunk blocks. On 32-bit architectures with 64-bit sector_t, block_location() and chunk_location() also truncate 64-bit directory and group indices into 32-bit size_t output parameters, and the vmalloc_array() failure paths for block_directories, groups, and chunk_directories return -ENOMEM without setting ti->error.
[ ... ]
drivers/md/dm-compress/target.c line 473
Quoted 6 lines
drivers/md/dm-compress/target.c new file +6
-0+ c->compress_wq =alloc_workqueue ("dm-compress-compress" ,WQ_PERCPU |WQ_MEM_RECLAIM ,METADATA_WORKQUEUE_MAX_ACTIVE ); +if (unlikely (!c->compress_wq)) { + ti->error ="Cannot allocate workqueue" ; + r = -ENOMEM ; + goto bad; + }
[Severity: Medium]
Should c->compress_wq use WQ_UNBOUND (or WQ_CPU_INTENSIVE) instead of WQ_PERCPU?
When dm_compress_is_something_in_progress() runs during flush, autocommit, or suspend, it queues all dirty cached chunks from a single CPU, so a bound WQ_PERCPU workqueue pins all CPU-heavy chunk compressions onto that one core. In addition, dm_compress_allocate_chunk() and dm_compress_read_chunk() call queue_work(c->compress_wq, &cc->work) on the synchronous ALGORITHM_ZERO and ALGORITHM_SPLIT paths from a worker already running on c->compress_wq, waking a second worker that blocks in wait_for_completion(&cc->completion).
[ ... ]
Quoted 5 lines
drivers/md/dm-compress/target.c new file +5
-0+ r =mempool_init_kmalloc_pool (&c->block_io_buffers,1 ,512U << c->log2_sectors_per_block); +if (r) { + ti->error ="Cannot allocate io buffers" ; + goto bad; + }
[ ... ]
drivers/md/dm-compress/target.c line 827
Quoted 12 lines
drivers/md/dm-compress/target.c new file +12
-0+static void dm_compress_postsuspend (struct dm_target *ti) +{ +struct dm_compress *c = ti->private; +int r; + +check_again: +mutex_lock (&c->mutex); +if (dm_compress_is_something_in_progress (c)) { +mutex_unlock (&c->mutex);\ +schedule_timeout_uninterruptible (1 ); + goto check_again; + }
[Severity: Medium]
Can dm_compress_postsuspend() wait on c->wait_idle (like dm_compress_autocommit() does) instead of polling with a 1-jiffy sleep in schedule_timeout_uninterruptible(1)?
Also, c->block_io_buffers is a 1-element kmalloc mempool for block sizes up to 512 KiB (or 1 MiB per MAX_BLOCK_SIZE), so concurrent split-chunk workers in map_split_block() and dm_compress_allocate_chunk() either stall on the single preallocated buffer or trigger order 7-8 GFP_NOIO contiguous kmalloc allocations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1