mm: add NR_ZSMALLOC to vmstat
authorMinchan Kim <minchan@kernel.org>
Tue, 26 Jul 2016 22:24:45 +0000 (15:24 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Jul 2016 23:19:19 +0000 (16:19 -0700)
zram is very popular for some of the embedded world (e.g., TV, mobile
phones).  On those system, zsmalloc's consumed memory size is never
trivial (one of example from real product system, total memory: 800M,
zsmalloc consumed: 150M), so we have used this out of tree patch to
monitor system memory behavior via /proc/vmstat.

With zsmalloc in vmstat, it helps in tracking down system behavior due
to memory usage.

[minchan@kernel.org: zsmalloc: follow up zsmalloc vmstat]
Link: http://lkml.kernel.org/r/20160607091737.GC23435@bbox
[akpm@linux-foundation.org: fix build with CONFIG_ZSMALLOC=m]
Link: http://lkml.kernel.org/r/1464919731-13255-1-git-send-email-minchan@kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Cc: Sangseok Lee <sangseok.lee@lge.com>
Cc: Chanho Min <chanho.min@lge.com>
Cc: Chan Gyun Jeong <chan.jeong@lge.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/mmzone.h
mm/vmstat.c
mm/zsmalloc.c

index 3388ccbab7d6514952a92010f0ce8a0c958adcd0..3d7ab30d4940c0db87147f7a4246f61354fd2397 100644 (file)
@@ -140,6 +140,9 @@ enum zone_stat_item {
        NR_DIRTIED,             /* page dirtyings since bootup */
        NR_WRITTEN,             /* page writings since bootup */
        NR_PAGES_SCANNED,       /* pages scanned since last reclaim */
+#if IS_ENABLED(CONFIG_ZSMALLOC)
+       NR_ZSPAGES,             /* allocated in zsmalloc */
+#endif
 #ifdef CONFIG_NUMA
        NUMA_HIT,               /* allocated in intended node */
        NUMA_MISS,              /* allocated in non intended node */
index cb2a67bb41581de147427e2289190beea33f69da..2a0f26bdae394137007cbb6f123646958f5901bf 100644 (file)
@@ -718,7 +718,9 @@ const char * const vmstat_text[] = {
        "nr_dirtied",
        "nr_written",
        "nr_pages_scanned",
-
+#if IS_ENABLED(CONFIG_ZSMALLOC)
+       "nr_zspages",
+#endif
 #ifdef CONFIG_NUMA
        "numa_hit",
        "numa_miss",
index 6b6986a02aa01c1e967a10cc2449be15752285d5..e4e8081b160b56c7fe7ceb1c842bc6ef9bd7d0bf 100644 (file)
@@ -1007,6 +1007,7 @@ static void __free_zspage(struct zs_pool *pool, struct size_class *class,
                next = get_next_page(page);
                reset_page(page);
                unlock_page(page);
+               dec_zone_page_state(page, NR_ZSPAGES);
                put_page(page);
                page = next;
        } while (page != NULL);
@@ -1137,11 +1138,15 @@ static struct zspage *alloc_zspage(struct zs_pool *pool,
 
                page = alloc_page(gfp);
                if (!page) {
-                       while (--i >= 0)
+                       while (--i >= 0) {
+                               dec_zone_page_state(pages[i], NR_ZSPAGES);
                                __free_page(pages[i]);
+                       }
                        cache_free_zspage(pool, zspage);
                        return NULL;
                }
+
+               inc_zone_page_state(page, NR_ZSPAGES);
                pages[i] = page;
        }