Skip to contentSkip to conversation

zram: add accounting for incompressible pages

PATCH In review qiwu.chen 2 participants 3 messages Apr 15 – Apr 16

Subsystems (2)
lore
Share & tools
lore

qiwu.chen

author
#0 lore raw

PATCH 1/1 zram: add accounting for incompressible pages

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.

---
 drivers/block/zram/zram_drv.c | 21 ++++++++++++++++-----
 drivers/block/zram/zram_drv.h |  2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)
drivers/block/zram/zram_drv.c +16 -5
index af679375b193..f16d52c4ed79 100644
@@ -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;
 	}
 
drivers/block/zram/zram_drv.h +2 -0
index f0de8f8218f5..cec84638f626 100644
@@ -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 */
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · qiwu.chen

1. Rename write_incompressible_page to write_huge_page since huge page could be recompressed with secondary algorithms.

Please no. "huge_page" is the most confusing term that zram uses.

Quoted 4 lines

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.

What for?

author
#2 lore raw
Quoted 6 lines · Sergey Senozhatsky
Quoted 2 lines · qiwu.chen

1. Rename write_incompressible_page to write_huge_page since huge page could be recompressed with secondary algorithms.

Please no. "huge_page" is the most confusing term that zram uses.

So what is differece between ZRAM_HUGE and ZRAM_INCOMPRESSIBLE? In my opinion, the slot is marked as ZRAM_HUGE if primary algorithm cannot compress the page. the slot is marked as ZRAM_INCOMPRESSIBLE if scondary algorithms failed to recompress the page in a way that condary algorithms failed to recompress the page.
The huge page could be recompressed with secondary algorithms with a certain probability, so it should not be defined as incompressible page.

Quoted 6 lines
Quoted 4 lines

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.

What for?

Add accounting for ZRAM_INCOMPRESSIBLE pages showed by mm_stat, so we can get how many pages is incompressiable in current system.