[PATCH 6.6.y 3/4] zram: move bd_stat to writeback section
From: Sasha Levin <sashal@kernel.org>
Date: 2026-09-05 01:13:02
Subsystem:
block layer, the rest, zram compressed ram block device drvier · Maintainers:
Jens Axboe, Linus Torvalds, Minchan Kim, Sergey Senozhatsky
From: Sergey Senozhatsky <senozhatsky@chromium.org> [ Upstream commit 910bbb441c004050e188dd8da5071054099e592c ] Move bd_stat function and attribute declaration to existing CONFIG_WRITEBACK ifdef-sections. Link: https://lkml.kernel.org/r/20251201094754.4149975-5-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Brian Geffon <redacted> Cc: David Stevens <redacted> Cc: Minchan Kim <redacted> Cc: Richard Chang <redacted> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: dde75313eed0 ("zram: set default primary compressor in zram_destroy_comps()") Signed-off-by: Sasha Levin <sashal@kernel.org> --- drivers/block/zram/zram_drv.c | 54 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 64a1136447cf5..6a4870cf6e590 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c@@ -364,6 +364,24 @@ static ssize_t idle_store(struct device *dev, } #ifdef CONFIG_ZRAM_WRITEBACK +#define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) +static ssize_t bd_stat_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct zram *zram = dev_to_zram(dev); + ssize_t ret; + + down_read(&zram->init_lock); + ret = scnprintf(buf, PAGE_SIZE, + "%8llu %8llu %8llu\n", + FOUR_K((u64)atomic64_read(&zram->stats.bd_count)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_writes))); + up_read(&zram->init_lock); + + return ret; +} + static ssize_t writeback_limit_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
@@ -1200,27 +1218,6 @@ static ssize_t mm_stat_show(struct device *dev, return ret; } - -#ifdef CONFIG_ZRAM_WRITEBACK -#define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) -static ssize_t bd_stat_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct zram *zram = dev_to_zram(dev); - ssize_t ret; - - down_read(&zram->init_lock); - ret = scnprintf(buf, PAGE_SIZE, - "%8llu %8llu %8llu\n", - FOUR_K((u64)atomic64_read(&zram->stats.bd_count)), - FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)), - FOUR_K((u64)atomic64_read(&zram->stats.bd_writes))); - up_read(&zram->init_lock); - - return ret; -} -#endif - static ssize_t debug_stat_show(struct device *dev, struct device_attribute *attr, char *buf) {
@@ -1241,9 +1238,6 @@ static ssize_t debug_stat_show(struct device *dev, static DEVICE_ATTR_RO(io_stat); static DEVICE_ATTR_RO(mm_stat); -#ifdef CONFIG_ZRAM_WRITEBACK -static DEVICE_ATTR_RO(bd_stat); -#endif static DEVICE_ATTR_RO(debug_stat); static void zram_meta_free(struct zram *zram, u64 disksize)
@@ -2014,6 +2008,7 @@ static void zram_slot_free_notify(struct block_device *bdev, zram_slot_unlock(zram, index); } +#define zram_comp_params_reset(_zram) ((void)(_zram)) static void zram_destroy_comps(struct zram *zram) { u32 prio;
@@ -2034,11 +2029,14 @@ static void zram_destroy_comps(struct zram *zram) kfree(zram->comp_algs[prio]); zram->comp_algs[prio] = NULL; } + + zram_comp_params_reset(zram); } +#undef zram_comp_params_reset static void zram_reset_device(struct zram *zram) { - down_write(&zram->init_lock); + guard(rwsem_write)(&zram->init_lock); zram->limit_pages = 0;
@@ -2053,7 +2051,6 @@ static void zram_reset_device(struct zram *zram) reset_bdev(zram); comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); - up_write(&zram->init_lock); } static ssize_t disksize_store(struct device *dev,
@@ -2180,6 +2177,7 @@ static DEVICE_ATTR_WO(idle); static DEVICE_ATTR_RW(max_comp_streams); static DEVICE_ATTR_RW(comp_algorithm); #ifdef CONFIG_ZRAM_WRITEBACK +static DEVICE_ATTR_RO(bd_stat); static DEVICE_ATTR_RW(backing_dev); static DEVICE_ATTR_WO(writeback); static DEVICE_ATTR_RW(writeback_limit);
@@ -2201,6 +2199,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_max_comp_streams.attr, &dev_attr_comp_algorithm.attr, #ifdef CONFIG_ZRAM_WRITEBACK + &dev_attr_bd_stat.attr, &dev_attr_backing_dev.attr, &dev_attr_writeback.attr, &dev_attr_writeback_limit.attr,
@@ -2208,9 +2207,6 @@ static struct attribute *zram_disk_attrs[] = { #endif &dev_attr_io_stat.attr, &dev_attr_mm_stat.attr, -#ifdef CONFIG_ZRAM_WRITEBACK - &dev_attr_bd_stat.attr, -#endif &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr,
--
2.53.0