public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] zram: add accounting for incompressible pages
@ 2026-04-15 10:43 qiwu.chen
  2026-04-16  7:07 ` Sergey Senozhatsky
  0 siblings, 1 reply; 3+ messages in thread
From: qiwu.chen @ 2026-04-15 10:43 UTC (permalink / raw)
  To: senozhatsky, axboe; +Cc: linux-block, qiwu.chen

1. Rename write_incompressible_page to write_huge_page since huge page
could be recompressed with secondary algorithms.
2. Similar to huge page, add incompressible_pages accounting for current
incompressible pages, and incompressible_pages_since accounting for
incompressible pages since zram set up. The accounting value can be showed
by mm_stat.

Signed-off-by: qiwu.chen <qiwu.chen@transsion.com>
---
 drivers/block/zram/zram_drv.c | 21 ++++++++++++++++-----
 drivers/block/zram/zram_drv.h |  2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index af679375b193..f16d52c4ed79 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -948,6 +948,8 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
 	clear_slot_flag(zram, index, ZRAM_IDLE);
 	if (test_slot_flag(zram, index, ZRAM_HUGE))
 		atomic64_dec(&zram->stats.huge_pages);
+	if (test_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE))
+		atomic64_dec(&zram->stats.incompressible_pages);
 	atomic64_sub(get_slot_size(zram, index), &zram->stats.compr_data_size);
 	zs_free(zram->mem_pool, get_slot_handle(zram, index));
 	set_slot_handle(zram, index, req->blk_idx);
@@ -1908,7 +1910,7 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 	max_used = atomic_long_read(&zram->stats.max_used_pages);
 
 	ret = sysfs_emit(buf,
-			"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
+			"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu %8llu %8llu\n",
 			orig_size << PAGE_SHIFT,
 			(u64)atomic64_read(&zram->stats.compr_data_size),
 			mem_used << PAGE_SHIFT,
@@ -1917,7 +1919,9 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
 			(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.incompressible_pages),
+			(u64)atomic64_read(&zram->stats.incompressible_pages_since));
 
 	return ret;
 }
@@ -1989,10 +1993,15 @@ static void slot_free(struct zram *zram, u32 index)
 #endif
 
 	clear_slot_flag(zram, index, ZRAM_IDLE);
-	clear_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
 	clear_slot_flag(zram, index, ZRAM_PP_SLOT);
 	set_slot_comp_priority(zram, index, 0);
 
+	if (test_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE)) {
+		if (!test_slot_flag(zram, index, ZRAM_WB))
+			atomic64_dec(&zram->stats.incompressible_pages);
+		clear_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
+	}
+
 	if (test_slot_flag(zram, index, ZRAM_HUGE)) {
 		/*
 		 * Writeback completion decrements ->huge_pages but keeps
@@ -2197,7 +2206,7 @@ static int write_same_filled_page(struct zram *zram, unsigned long fill,
 	return 0;
 }
 
-static int write_incompressible_page(struct zram *zram, struct page *page,
+static int write_huge_page(struct zram *zram, struct page *page,
 				     u32 index)
 {
 	unsigned long handle;
@@ -2268,7 +2277,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
 
 	if (comp_len >= huge_class_size) {
 		zcomp_stream_put(zstrm);
-		return write_incompressible_page(zram, page, index);
+		return write_huge_page(zram, page, index);
 	}
 
 	handle = zs_malloc(zram->mem_pool, comp_len,
@@ -2487,6 +2496,8 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page,
 		if (prio < zram->num_active_comps)
 			return 0;
 		set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
+		atomic64_inc(&zram->stats.incompressible_pages);
+		atomic64_inc(&zram->stats.incompressible_pages_since);
 		return 0;
 	}
 
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index f0de8f8218f5..cec84638f626 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -85,6 +85,8 @@ struct zram_stats {
 	atomic64_t same_pages;		/* no. of same element filled pages */
 	atomic64_t huge_pages;		/* no. of huge pages */
 	atomic64_t huge_pages_since;	/* no. of huge pages since zram set up */
+	atomic64_t incompressible_pages;	/* no. of incompressible pages */
+	atomic64_t incompressible_pages_since;	/* no. of incompressible pages since zram set up */
 	atomic64_t pages_stored;	/* no. of pages currently stored */
 	atomic_long_t max_used_pages;	/* no. of maximum pages stored */
 	atomic64_t miss_free;		/* no. of missed free */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-16 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 10:43 [PATCH] zram: add accounting for incompressible pages qiwu.chen
2026-04-16  7:07 ` Sergey Senozhatsky
2026-04-16 13:20   ` chenqiwu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox