Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

zram: introduce writeback_compressed device attribute

Introduce witeback_compressed device attribute to toggle compressed
writeback (decompression on demand) feature.

[senozhatsky@chromium.org: rewrote original patch, added documentation]
Link: https://lkml.kernel.org/r/20251201094754.4149975-3-senozhatsky@chromium.org
Signed-off-by: Richard Chang <richardycc@google.com>
Co-developed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Brian Geffon <bgeffon@google.com>
Cc: David Stevens <stevensd@google.com>
Cc: Minchan Kim <minchan@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Richard Chang and committed by
Andrew Morton
4c1d6138 d38fab60

+58
+7
Documentation/ABI/testing/sysfs-block-zram
··· 150 150 Description: 151 151 The algorithm_params file is write-only and is used to setup 152 152 compression algorithm parameters. 153 + 154 + What: /sys/block/zram<id>/writeback_compressed 155 + Date: Decemeber 2025 156 + Contact: Richard Chang <richardycc@google.com> 157 + Description: 158 + The writeback_compressed device atrribute toggles compressed 159 + writeback feature.
+13
Documentation/admin-guide/blockdev/zram.rst
··· 214 214 writeback_limit WO specifies the maximum amount of write IO zram 215 215 can write out to backing device as 4KB unit 216 216 writeback_limit_enable RW show and set writeback_limit feature 217 + writeback_compressed RW show and set compressed writeback feature 217 218 comp_algorithm RW show and change the compression algorithm 218 219 algorithm_params WO setup compression algorithm parameters 219 220 compact WO trigger memory compaction ··· 434 433 system reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of 435 434 writeback happened until you reset the zram to allocate extra writeback 436 435 budget in next setting is user's job. 436 + 437 + By default zram stores written back pages in decompressed (raw) form, which 438 + means that writeback operation involves decompression of the page before 439 + writing it to the backing device. This behavior can be changed by enabling 440 + `writeback_compressed` feature, which causes zram to write compressed pages 441 + to the backing device, thus avoiding decompression overhead. To enable 442 + this feature, execute:: 443 + 444 + $ echo yes > /sys/block/zramX/writeback_compressed 445 + 446 + Note that this feature should be configured before the `zramX` device is 447 + initialized. 437 448 438 449 If admin wants to measure writeback count in a certain period, they could 439 450 know it via /sys/block/zram0/bd_stat's 3rd column.
+38
drivers/block/zram/zram_drv.c
··· 539 539 u32 index; 540 540 }; 541 541 542 + static ssize_t writeback_compressed_store(struct device *dev, 543 + struct device_attribute *attr, 544 + const char *buf, size_t len) 545 + { 546 + struct zram *zram = dev_to_zram(dev); 547 + bool val; 548 + 549 + if (kstrtobool(buf, &val)) 550 + return -EINVAL; 551 + 552 + down_write(&zram->init_lock); 553 + if (init_done(zram)) { 554 + up_write(&zram->init_lock); 555 + return -EBUSY; 556 + } 557 + 558 + zram->wb_compressed = val; 559 + up_write(&zram->init_lock); 560 + 561 + return len; 562 + } 563 + 564 + static ssize_t writeback_compressed_show(struct device *dev, 565 + struct device_attribute *attr, 566 + char *buf) 567 + { 568 + bool val; 569 + struct zram *zram = dev_to_zram(dev); 570 + 571 + down_read(&zram->init_lock); 572 + val = zram->wb_compressed; 573 + up_read(&zram->init_lock); 574 + 575 + return sysfs_emit(buf, "%d\n", val); 576 + } 577 + 542 578 static ssize_t writeback_limit_enable_store(struct device *dev, 543 579 struct device_attribute *attr, 544 580 const char *buf, size_t len) ··· 3084 3048 static DEVICE_ATTR_RW(writeback_limit); 3085 3049 static DEVICE_ATTR_RW(writeback_limit_enable); 3086 3050 static DEVICE_ATTR_RW(writeback_batch_size); 3051 + static DEVICE_ATTR_RW(writeback_compressed); 3087 3052 #endif 3088 3053 #ifdef CONFIG_ZRAM_MULTI_COMP 3089 3054 static DEVICE_ATTR_RW(recomp_algorithm); ··· 3107 3070 &dev_attr_writeback_limit.attr, 3108 3071 &dev_attr_writeback_limit_enable.attr, 3109 3072 &dev_attr_writeback_batch_size.attr, 3073 + &dev_attr_writeback_compressed.attr, 3110 3074 #endif 3111 3075 &dev_attr_io_stat.attr, 3112 3076 &dev_attr_mm_stat.attr,