public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: "qiwu.chen" <qiwuchen55@gmail.com>
To: senozhatsky@chromium.org, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, "qiwu.chen" <qiwu.chen@transsion.com>
Subject: [PATCH] zram: add accounting for incompressible pages
Date: Wed, 15 Apr 2026 18:43:56 +0800	[thread overview]
Message-ID: <20260415104356.82248-1-qiwu.chen@transsion.com> (raw)

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


             reply	other threads:[~2026-04-15 10:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 10:43 qiwu.chen [this message]
2026-04-16  7:07 ` [PATCH] zram: add accounting for incompressible pages Sergey Senozhatsky
2026-04-16 13:20   ` chenqiwu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260415104356.82248-1-qiwu.chen@transsion.com \
    --to=qiwuchen55@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=qiwu.chen@transsion.com \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox