UPSTREAM: zram: introduce per-device debug_stat sysfs node
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Sat, 21 May 2016 00:00:02 +0000 (17:00 -0700)
committerivanmeler <i_ivan@windowslive.com>
Wed, 13 Apr 2022 21:13:15 +0000 (21:13 +0000)
debug_stat sysfs is read-only and represents various debugging data that
zram developers may need.  This file is not meant to be used by anyone
else: its content is not documented and will change any time w/o any
notice.  Therefore, the output of debug_stat file contains a version
string.  To avoid any confusion, we will increase the version number
every time we modify the output.

At the moment this file exports only one value -- the number of
re-compressions, IOW, the number of times compression fast path has
failed.  This stat is temporary any will be useful in case if any
per-cpu compression streams regressions will be reported.

Link: http://lkml.kernel.org/r/20160513230834.GB26763@bbox
Link: http://lkml.kernel.org/r/20160511134553.12655-1-sergey.senozhatsky@gmail.com
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 623e47fc64f8de480b322b7ed68855f97137e2a5)
Signed-off-by: Peter Kalauskas <peskal@google.com>
Bug: 112488418
Change-Id: Ie0ef61db7aa0b2c713de1d8bf48e8a545b4276e9

Documentation/ABI/testing/sysfs-block-zram
Documentation/blockdev/zram.txt
drivers/block/zram/zram_drv.c
drivers/block/zram/zram_drv.h

index 2e69e83bf51057501662e606fb6791338e3838cd..4518d30b8c2edf5b30405e6da700f757000aab77 100644 (file)
@@ -166,3 +166,12 @@ Description:
                The mm_stat file is read-only and represents device's mm
                statistics (orig_data_size, compr_data_size, etc.) in a format
                similar to block layer statistics file format.
+
+What:          /sys/block/zram<id>/debug_stat
+Date:          July 2016
+Contact:       Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
+Description:
+               The debug_stat file is read-only and represents various
+               device's debugging info useful for kernel developers. Its
+               format is not documented intentionally and may change
+               anytime without any notice.
index d88f0c70cd7fc470875960d07a63fb883e75d48b..13100fb3c26df99317a6ddd8acc9ec0fa85ed0dd 100644 (file)
@@ -172,6 +172,7 @@ mem_limit         RW    the maximum amount of memory ZRAM can use to store
 pages_compacted   RO    the number of pages freed during compaction
                         (available only via zram<id>/mm_stat node)
 compact           WO    trigger memory compaction
+debug_stat        RO    this file is used for zram debugging purposes
 
 WARNING
 =======
index e38f4419cc4e1f695e6fe74ad311fe0c0813213d..74fb46afac71f57f17cf08ef82abb44893f4727f 100644 (file)
@@ -435,8 +435,26 @@ static ssize_t mm_stat_show(struct device *dev,
        return ret;
 }
 
+static ssize_t debug_stat_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       int version = 1;
+       struct zram *zram = dev_to_zram(dev);
+       ssize_t ret;
+
+       down_read(&zram->init_lock);
+       ret = scnprintf(buf, PAGE_SIZE,
+                       "version: %d\n%8llu\n",
+                       version,
+                       (u64)atomic64_read(&zram->stats.writestall));
+       up_read(&zram->init_lock);
+
+       return ret;
+}
+
 static DEVICE_ATTR_RO(io_stat);
 static DEVICE_ATTR_RO(mm_stat);
+static DEVICE_ATTR_RO(debug_stat);
 ZRAM_ATTR_RO(num_reads);
 ZRAM_ATTR_RO(num_writes);
 ZRAM_ATTR_RO(failed_reads);
@@ -719,6 +737,8 @@ compress_again:
                zcomp_strm_release(zram->comp, zstrm);
                zstrm = NULL;
 
+               atomic64_inc(&zram->stats.writestall);
+
                handle = zs_malloc(meta->mem_pool, clen,
                                GFP_NOIO | __GFP_HIGHMEM);
                if (handle)
@@ -1181,6 +1201,7 @@ static struct attribute *zram_disk_attrs[] = {
        &dev_attr_comp_algorithm.attr,
        &dev_attr_io_stat.attr,
        &dev_attr_mm_stat.attr,
+       &dev_attr_debug_stat.attr,
        NULL,
 };
 
index 06b1636f472218b206084037400b703850220307..3f5bf66a27e45aa5bb6f6bc14da5ac35855dec14 100644 (file)
@@ -85,6 +85,7 @@ struct zram_stats {
        atomic64_t zero_pages;          /* no. of zero filled 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 */
 };
 
 struct zram_meta {