]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
zram: export new 'mm_stat' sysfs attrs
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tue, 7 Apr 2015 23:44:49 +0000 (09:44 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 7 Apr 2015 23:44:49 +0000 (09:44 +1000)
Per-device `zram<id>/mm_stat' file provides mm statistics of a particular
zram device in a format similar to block layer statistics.  The file
consists of a single line and represents the following stats (separated by
whitespace):

orig_data_size
compr_data_size
mem_used_total
mem_limit
mem_used_max
zero_pages
num_migrated

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/ABI/testing/sysfs-block-zram
Documentation/blockdev/zram.txt
drivers/block/zram/zram_drv.c

index a7f622f9bcf6579caa24874bf9062201432e7435..2e69e83bf51057501662e606fb6791338e3838cd 100644 (file)
@@ -158,3 +158,11 @@ Description:
                statistics not accounted by block layer. For example,
                failed_reads, failed_writes, etc. File format is similar to
                block layer statistics file format.
+
+What:          /sys/block/zram<id>/mm_stat
+Date:          August 2015
+Contact:       Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
+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.
index 5ed4dd5f589c6064fa2e01afd56626716f6bfa1d..b133138aee475f5704014f03bff13db1c2eccf79 100644 (file)
@@ -165,6 +165,20 @@ whitespace:
        invalid_io
        notify_free
 
+
+File /sys/block/zram<id>/mm_stat
+
+The stat file represents device's mm statistics. It consists of a single
+line of text and contains the following stats separated by whitespace:
+       orig_data_size
+       compr_data_size
+       mem_used_total
+       mem_limit
+       mem_used_max
+       zero_pages
+       num_migrated
+
+
 9) Deactivate:
        swapoff /dev/zram0
        umount /dev/zram1
index 99d9286ec2cd68835a71f7f9833df75a9015bae7..f2dc90d3f17000c11abb11709ce13b14e027ad70 100644 (file)
@@ -402,7 +402,37 @@ static ssize_t io_stat_show(struct device *dev,
        return ret;
 }
 
+static ssize_t mm_stat_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct zram *zram = dev_to_zram(dev);
+       u64 orig_size, mem_used = 0;
+       long max_used;
+       ssize_t ret;
+
+       down_read(&zram->init_lock);
+       if (init_done(zram))
+               mem_used = zs_get_total_pages(zram->meta->mem_pool);
+
+       orig_size = atomic64_read(&zram->stats.pages_stored);
+       max_used = atomic_long_read(&zram->stats.max_used_pages);
+
+       ret = scnprintf(buf, PAGE_SIZE,
+                       "%8llu %8llu %8llu %8lu %8ld %8llu %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.zero_pages),
+                       (u64)atomic64_read(&zram->stats.num_migrated));
+       up_read(&zram->init_lock);
+
+       return ret;
+}
+
 static DEVICE_ATTR_RO(io_stat);
+static DEVICE_ATTR_RO(mm_stat);
 ZRAM_ATTR_RO(num_reads);
 ZRAM_ATTR_RO(num_writes);
 ZRAM_ATTR_RO(failed_reads);
@@ -1105,6 +1135,7 @@ static struct attribute *zram_disk_attrs[] = {
        &dev_attr_max_comp_streams.attr,
        &dev_attr_comp_algorithm.attr,
        &dev_attr_io_stat.attr,
+       &dev_attr_mm_stat.attr,
        NULL,
 };