BACKPORT: zram: mark incompressible page as ZRAM_HUGE
authorMinchan Kim <minchan@kernel.org>
Fri, 8 Jun 2018 00:05:42 +0000 (17:05 -0700)
committerMichael Benedict <michaelbt@live.com>
Fri, 30 Aug 2019 07:42:51 +0000 (17:42 +1000)
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>
(cherry picked from commit 89e85bce4b02edb7408aebf69d5d1a6692a05f4f)
Signed-off-by: Peter Kalauskas <peskal@google.com>
Bug: 112488418
Change-Id: If1b7b2d6ea6672a575ffc3d70c2c8b58ecafd0d7

Documentation/blockdev/zram.txt
drivers/block/zram/zram_drv.c
drivers/block/zram/zram_drv.h

index 257e65714c6a216f3fce9ebce7398eb821f96176..78db38d02bc9a27a7ffd936ef857455960fe7459 100644 (file)
@@ -218,6 +218,7 @@ line of text and contains the following stats separated by whitespace:
  same_pages       the number of same element filled pages written to this disk.
                   No memory is allocated for such pages.
  pages_compacted  the number of pages freed during compaction
+ huge_pages      the number of incompressible pages
 
 9) Deactivate:
        swapoff /dev/zram0
index 5439ccd0be9af998bd60b17a964be8751a38ad6c..8e74cafe9008feafa31e532e67382312a2b74e12 100644 (file)
@@ -739,14 +739,15 @@ static ssize_t mm_stat_show(struct device *dev,
        max_used = atomic_long_read(&zram->stats.max_used_pages);
 
        ret = scnprintf(buf, PAGE_SIZE,
-                       "%8llu %8llu %8llu %8lu %8ld %8llu %8lu\n",
+                       "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu\n",
                        orig_size << PAGE_SHIFT,
                        (u64)atomic64_read(&zram->stats.compr_data_size),
                        mem_used << PAGE_SHIFT,
                        zram->limit_pages << PAGE_SHIFT,
                        max_used << PAGE_SHIFT,
                        (u64)atomic64_read(&zram->stats.same_pages),
-                       pool_stats.pages_compacted);
+                       pool_stats.pages_compacted,
+                       (u64)atomic64_read(&zram->stats.huge_pages));
        up_read(&zram->init_lock);
 
        return ret;
@@ -813,6 +814,11 @@ static void zram_free_page(struct zram *zram, size_t index)
 {
        unsigned long handle;
 
+       if (zram_test_flag(zram, index, ZRAM_HUGE)) {
+               zram_clear_flag(zram, index, ZRAM_HUGE);
+               atomic64_dec(&zram->stats.huge_pages);
+       }
+
        if (zram_wb_enabled(zram) && zram_test_flag(zram, index, ZRAM_WB)) {
                zram_wb_clear(zram, index);
                atomic64_dec(&zram->stats.pages_stored);
@@ -981,6 +987,7 @@ compress_again:
        }
 
        if (unlikely(comp_len > max_zpage_size)) {
+               comp_len = PAGE_SIZE;
                if (zram_wb_enabled(zram) && allow_wb) {
                        zcomp_stream_put(zram->comp);
                        ret = write_to_bdev(zram, bvec, index, bio, &element);
@@ -992,7 +999,6 @@ compress_again:
                        allow_wb = false;
                        goto compress_again;
                }
-               comp_len = PAGE_SIZE;
        }
 
        /*
@@ -1054,6 +1060,11 @@ out:
        zram_slot_lock(zram, index);
        zram_free_page(zram, index);
 
+       if (comp_len == PAGE_SIZE) {
+               zram_set_flag(zram, index, ZRAM_HUGE);
+               atomic64_inc(&zram->stats.huge_pages);
+       }
+
        if (flags) {
                zram_set_flag(zram, index, flags);
                zram_set_element(zram, index, element);
index a473d5c7d74fb08ffd623ee56a7f18780e74ae4b..4c4bc6042c898f5f4e43b087e8f8cddd50098131 100644 (file)
@@ -64,6 +64,7 @@ enum zram_pageflags {
        ZRAM_LOCK = ZRAM_FLAG_SHIFT,
        ZRAM_SAME,      /* Page consists the same element */
        ZRAM_WB,        /* page is stored on backing_device */
+       ZRAM_HUGE,      /* Incompressible page */
 
        __NR_ZRAM_PAGEFLAGS,
 };
@@ -88,6 +89,7 @@ struct zram_stats {
        atomic64_t invalid_io;  /* non-page-aligned I/O requests */
        atomic64_t notify_free; /* no. of swap slot free notifications */
        atomic64_t same_pages;          /* no. of same element filled pages */
+       atomic64_t huge_pages;          /* no. of huge pages */
        atomic64_t pages_stored;        /* no. of pages currently stored */
        atomic_long_t max_used_pages;   /* no. of maximum pages stored */
        atomic64_t writestall;          /* no. of write slow paths */