Skip to content

Commit d922d39

Browse files
qiwu.chenkawasaki
authored andcommitted
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. Signed-off-by: qiwu.chen <[email protected]>
1 parent 79e9b9d commit d922d39

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

drivers/block/zram/zram_drv.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
948948
clear_slot_flag(zram, index, ZRAM_IDLE);
949949
if (test_slot_flag(zram, index, ZRAM_HUGE))
950950
atomic64_dec(&zram->stats.huge_pages);
951+
if (test_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE))
952+
atomic64_dec(&zram->stats.incompressible_pages);
951953
atomic64_sub(get_slot_size(zram, index), &zram->stats.compr_data_size);
952954
zs_free(zram->mem_pool, get_slot_handle(zram, index));
953955
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,
19081910
max_used = atomic_long_read(&zram->stats.max_used_pages);
19091911

19101912
ret = sysfs_emit(buf,
1911-
"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
1913+
"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu %8llu %8llu\n",
19121914
orig_size << PAGE_SHIFT,
19131915
(u64)atomic64_read(&zram->stats.compr_data_size),
19141916
mem_used << PAGE_SHIFT,
@@ -1917,7 +1919,9 @@ static ssize_t mm_stat_show(struct device *dev, struct device_attribute *attr,
19171919
(u64)atomic64_read(&zram->stats.same_pages),
19181920
atomic_long_read(&pool_stats.pages_compacted),
19191921
(u64)atomic64_read(&zram->stats.huge_pages),
1920-
(u64)atomic64_read(&zram->stats.huge_pages_since));
1922+
(u64)atomic64_read(&zram->stats.huge_pages_since),
1923+
(u64)atomic64_read(&zram->stats.incompressible_pages),
1924+
(u64)atomic64_read(&zram->stats.incompressible_pages_since));
19211925

19221926
return ret;
19231927
}
@@ -1989,10 +1993,15 @@ static void slot_free(struct zram *zram, u32 index)
19891993
#endif
19901994

19911995
clear_slot_flag(zram, index, ZRAM_IDLE);
1992-
clear_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
19931996
clear_slot_flag(zram, index, ZRAM_PP_SLOT);
19941997
set_slot_comp_priority(zram, index, 0);
19951998

1999+
if (test_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE)) {
2000+
if (!test_slot_flag(zram, index, ZRAM_WB))
2001+
atomic64_dec(&zram->stats.incompressible_pages);
2002+
clear_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
2003+
}
2004+
19962005
if (test_slot_flag(zram, index, ZRAM_HUGE)) {
19972006
/*
19982007
* Writeback completion decrements ->huge_pages but keeps
@@ -2197,7 +2206,7 @@ static int write_same_filled_page(struct zram *zram, unsigned long fill,
21972206
return 0;
21982207
}
21992208

2200-
static int write_incompressible_page(struct zram *zram, struct page *page,
2209+
static int write_huge_page(struct zram *zram, struct page *page,
22012210
u32 index)
22022211
{
22032212
unsigned long handle;
@@ -2268,7 +2277,7 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
22682277

22692278
if (comp_len >= huge_class_size) {
22702279
zcomp_stream_put(zstrm);
2271-
return write_incompressible_page(zram, page, index);
2280+
return write_huge_page(zram, page, index);
22722281
}
22732282

22742283
handle = zs_malloc(zram->mem_pool, comp_len,
@@ -2487,6 +2496,8 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page,
24872496
if (prio < zram->num_active_comps)
24882497
return 0;
24892498
set_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
2499+
atomic64_inc(&zram->stats.incompressible_pages);
2500+
atomic64_inc(&zram->stats.incompressible_pages_since);
24902501
return 0;
24912502
}
24922503

drivers/block/zram/zram_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct zram_stats {
8585
atomic64_t same_pages; /* no. of same element filled pages */
8686
atomic64_t huge_pages; /* no. of huge pages */
8787
atomic64_t huge_pages_since; /* no. of huge pages since zram set up */
88+
atomic64_t incompressible_pages; /* no. of incompressible pages */
89+
atomic64_t incompressible_pages_since; /* no. of incompressible pages since zram set up */
8890
atomic64_t pages_stored; /* no. of pages currently stored */
8991
atomic_long_t max_used_pages; /* no. of maximum pages stored */
9092
atomic64_t miss_free; /* no. of missed free */

0 commit comments

Comments
 (0)