This counter shows how many identical compressed
pages have been processed by zram so far.
Signed-off-by: Alexey Romanov <[email protected]>
---
Documentation/admin-guide/blockdev/zram.rst | 2 ++
drivers/block/zram/zram_drv.c | 8 ++++++--
drivers/block/zram/zram_drv.h | 1 +
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst
index e4551579cb12..a1dd202efca1 100644
--- a/Documentation/admin-guide/blockdev/zram.rst
+++ b/Documentation/admin-guide/blockdev/zram.rst
@@ -209,6 +209,7 @@ compact WO trigger memory compaction
debug_stat RO this file is used for zram debugging purposes
backing_dev RW set up backend storage for zram to write out
idle WO mark allocated slot as idle
+merge WO trigger merge identical pages
====================== ====== ===============================================
@@ -267,6 +268,7 @@ line of text and contains the following stats separated by whitespace:
pages_compacted the number of pages freed during compaction
huge_pages the number of incompressible pages
huge_pages_since the number of incompressible pages since zram set up
+ pages_merged the number of identical pages merged into single one
================ =============================================================
File /sys/block/zram<id>/bd_stat
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 1dae3564cabd..7a267b37e5db 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1260,7 +1260,7 @@ static ssize_t mm_stat_show(struct device *dev,
max_used = atomic_long_read(&zram->stats.max_used_pages);
ret = scnprintf(buf, PAGE_SIZE,
- "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
+ "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu %8llu\n",
orig_size << PAGE_SHIFT,
(u64)atomic64_read(&zram->stats.compr_data_size),
mem_used << PAGE_SHIFT,
@@ -1269,7 +1269,8 @@ static ssize_t mm_stat_show(struct device *dev,
(u64)atomic64_read(&zram->stats.same_pages),
atomic_long_read(&pool_stats.pages_compacted),
(u64)atomic64_read(&zram->stats.huge_pages),
- (u64)atomic64_read(&zram->stats.huge_pages_since));
+ (u64)atomic64_read(&zram->stats.huge_pages_since),
+ (u64)atomic64_read(&zram->stats.pages_merged));
up_read(&zram->init_lock);
return ret;
@@ -1473,6 +1474,7 @@ static int zram_cmp_obj_and_merge(struct zram *zram, struct hlist_head *htable,
rb_node->cnt++;
}
+ atomic64_inc(&zram->stats.pages_merged);
atomic64_sub(obj_size, &zram->stats.compr_data_size);
zram_set_flag(zram, index, ZRAM_MERGED);
zram_set_flag(zram, node->index, ZRAM_MERGED);
@@ -1657,6 +1659,8 @@ static void zram_free_page(struct zram *zram, size_t index)
} else {
mutex_unlock(&zram_rbtree_mutex);
}
+
+ atomic64_dec(&zram->stats.pages_merged);
} else {
zs_free(zram->mem_pool, handle);
}
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 4a7151c94523..2afdbf76a1aa 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -88,6 +88,7 @@ struct zram_stats {
atomic_long_t max_used_pages; /* no. of maximum pages stored */
atomic64_t writestall; /* no. of write slow paths */
atomic64_t miss_free; /* no. of missed free */
+ atomic64_t pages_merged; /* no. of pages, which merged into single one */
#ifdef CONFIG_ZRAM_WRITEBACK
atomic64_t bd_count; /* no. of pages in backing device */
atomic64_t bd_reads; /* no. of reads from backing device */
--
2.25.1