Skip to content

Commit 623e47f

Browse files
sergey-senozhatskytorvalds
authored andcommitted
zram: introduce per-device debug_stat sysfs node
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>
1 parent 43209ea commit 623e47f

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎Documentation/ABI/testing/sysfs-block-zram‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,12 @@ Description:
166166
The mm_stat file is read-only and represents device's mm
167167
statistics (orig_data_size, compr_data_size, etc.) in a format
168168
similar to block layer statistics file format.
169+
170+
What: /sys/block/zram<id>/debug_stat
171+
Date: July 2016
172+
Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
173+
Description:
174+
The debug_stat file is read-only and represents various
175+
device's debugging info useful for kernel developers. Its
176+
format is not documented intentionally and may change
177+
anytime without any notice.

‎Documentation/blockdev/zram.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ mem_limit RW the maximum amount of memory ZRAM can use to store
172172
pages_compacted RO the number of pages freed during compaction
173173
(available only via zram<id>/mm_stat node)
174174
compact WO trigger memory compaction
175+
debug_stat RO this file is used for zram debugging purposes
175176

176177
WARNING
177178
=======

‎drivers/block/zram/zram_drv.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,26 @@ static ssize_t mm_stat_show(struct device *dev,
435435
return ret;
436436
}
437437

438+
static ssize_t debug_stat_show(struct device *dev,
439+
struct device_attribute *attr, char *buf)
440+
{
441+
int version = 1;
442+
struct zram *zram = dev_to_zram(dev);
443+
ssize_t ret;
444+
445+
down_read(&zram->init_lock);
446+
ret = scnprintf(buf, PAGE_SIZE,
447+
"version: %d\n%8llu\n",
448+
version,
449+
(u64)atomic64_read(&zram->stats.writestall));
450+
up_read(&zram->init_lock);
451+
452+
return ret;
453+
}
454+
438455
static DEVICE_ATTR_RO(io_stat);
439456
static DEVICE_ATTR_RO(mm_stat);
457+
static DEVICE_ATTR_RO(debug_stat);
440458
ZRAM_ATTR_RO(num_reads);
441459
ZRAM_ATTR_RO(num_writes);
442460
ZRAM_ATTR_RO(failed_reads);
@@ -719,6 +737,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
719737
zcomp_strm_release(zram->comp, zstrm);
720738
zstrm = NULL;
721739

740+
atomic64_inc(&zram->stats.writestall);
741+
722742
handle = zs_malloc(meta->mem_pool, clen,
723743
GFP_NOIO | __GFP_HIGHMEM);
724744
if (handle)
@@ -1181,6 +1201,7 @@ static struct attribute *zram_disk_attrs[] = {
11811201
&dev_attr_comp_algorithm.attr,
11821202
&dev_attr_io_stat.attr,
11831203
&dev_attr_mm_stat.attr,
1204+
&dev_attr_debug_stat.attr,
11841205
NULL,
11851206
};
11861207

‎drivers/block/zram/zram_drv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct zram_stats {
8585
atomic64_t zero_pages; /* no. of zero filled pages */
8686
atomic64_t pages_stored; /* no. of pages currently stored */
8787
atomic_long_t max_used_pages; /* no. of maximum pages stored */
88+
atomic64_t writestall; /* no. of write slow paths */
8889
};
8990

9091
struct zram_meta {

0 commit comments

Comments
 (0)