Skip to content

Commit 89e85bc

Browse files
minchanktorvalds
authored andcommitted
zram: mark incompressible page as ZRAM_HUGE
Mark incompressible pages so that we could investigate who is the owner of the incompressible pages once the page is swapped out via using upcoming zram memory tracker feature. With it, we could prevent such pages to be swapped out by using mlock. Otherwise we might remove them. This patch exposes new stat for huge pages via mm_stat. Link: http://lkml.kernel.org/r/20180416090946.63057-3-minchan@kernel.org Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c4d6c4c commit 89e85bc

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎Documentation/blockdev/zram.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ line of text and contains the following stats separated by whitespace:
218218
same_pages the number of same element filled pages written to this disk.
219219
No memory is allocated for such pages.
220220
pages_compacted the number of pages freed during compaction
221+
huge_pages the number of incompressible pages
221222

222223
9) Deactivate:
223224
swapoff /dev/zram0

‎drivers/block/zram/zram_drv.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,15 @@ static ssize_t mm_stat_show(struct device *dev,
729729
max_used = atomic_long_read(&zram->stats.max_used_pages);
730730

731731
ret = scnprintf(buf, PAGE_SIZE,
732-
"%8llu %8llu %8llu %8lu %8ld %8llu %8lu\n",
732+
"%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu\n",
733733
orig_size << PAGE_SHIFT,
734734
(u64)atomic64_read(&zram->stats.compr_data_size),
735735
mem_used << PAGE_SHIFT,
736736
zram->limit_pages << PAGE_SHIFT,
737737
max_used << PAGE_SHIFT,
738738
(u64)atomic64_read(&zram->stats.same_pages),
739-
pool_stats.pages_compacted);
739+
pool_stats.pages_compacted,
740+
(u64)atomic64_read(&zram->stats.huge_pages));
740741
up_read(&zram->init_lock);
741742

742743
return ret;
@@ -805,6 +806,11 @@ static void zram_free_page(struct zram *zram, size_t index)
805806
{
806807
unsigned long handle;
807808

809+
if (zram_test_flag(zram, index, ZRAM_HUGE)) {
810+
zram_clear_flag(zram, index, ZRAM_HUGE);
811+
atomic64_dec(&zram->stats.huge_pages);
812+
}
813+
808814
if (zram_wb_enabled(zram) && zram_test_flag(zram, index, ZRAM_WB)) {
809815
zram_wb_clear(zram, index);
810816
atomic64_dec(&zram->stats.pages_stored);
@@ -973,6 +979,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
973979
}
974980

975981
if (unlikely(comp_len >= huge_class_size)) {
982+
comp_len = PAGE_SIZE;
976983
if (zram_wb_enabled(zram) && allow_wb) {
977984
zcomp_stream_put(zram->comp);
978985
ret = write_to_bdev(zram, bvec, index, bio, &element);
@@ -984,7 +991,6 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
984991
allow_wb = false;
985992
goto compress_again;
986993
}
987-
comp_len = PAGE_SIZE;
988994
}
989995

990996
/*
@@ -1046,6 +1052,11 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
10461052
zram_slot_lock(zram, index);
10471053
zram_free_page(zram, index);
10481054

1055+
if (comp_len == PAGE_SIZE) {
1056+
zram_set_flag(zram, index, ZRAM_HUGE);
1057+
atomic64_inc(&zram->stats.huge_pages);
1058+
}
1059+
10491060
if (flags) {
10501061
zram_set_flag(zram, index, flags);
10511062
zram_set_element(zram, index, element);

‎drivers/block/zram/zram_drv.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum zram_pageflags {
4747
ZRAM_LOCK = ZRAM_FLAG_SHIFT,
4848
ZRAM_SAME, /* Page consists the same element */
4949
ZRAM_WB, /* page is stored on backing_device */
50+
ZRAM_HUGE, /* Incompressible page */
5051

5152
__NR_ZRAM_PAGEFLAGS,
5253
};
@@ -71,6 +72,7 @@ struct zram_stats {
7172
atomic64_t invalid_io; /* non-page-aligned I/O requests */
7273
atomic64_t notify_free; /* no. of swap slot free notifications */
7374
atomic64_t same_pages; /* no. of same element filled pages */
75+
atomic64_t huge_pages; /* no. of huge pages */
7476
atomic64_t pages_stored; /* no. of pages currently stored */
7577
atomic_long_t max_used_pages; /* no. of maximum pages stored */
7678
atomic64_t writestall; /* no. of write slow paths */

0 commit comments

Comments
 (0)