Skip to content

Commit 2f6a3be

Browse files
sergey-senozhatskytorvalds
authored andcommitted
zram: export new 'io_stat' sysfs attrs
Per-device `zram<id>/io_stat' file provides accumulated I/O statistics of 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): failed_reads failed_writes invalid_io notify_free 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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 77ba015 commit 2f6a3be

3 files changed

Lines changed: 40 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
@@ -149,3 +149,12 @@ Description:
149149
The compact file is write-only and trigger compaction for
150150
allocator zrm uses. The allocator moves some objects so that
151151
it could free fragment space.
152+
153+
What: /sys/block/zram<id>/io_stat
154+
Date: August 2015
155+
Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
156+
Description:
157+
The io_stat file is read-only and accumulates device's I/O
158+
statistics not accounted by block layer. For example,
159+
failed_reads, failed_writes, etc. File format is similar to
160+
block layer statistics file format.

‎Documentation/blockdev/zram.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ File /sys/block/zram<id>/stat
133133
Represents block layer statistics. Read Documentation/block/stat.txt for
134134
details.
135135

136+
File /sys/block/zram<id>/io_stat
137+
138+
The stat file represents device's I/O statistics not accounted by block
139+
layer and, thus, not available in zram<id>/stat file. It consists of a
140+
single line of text and contains the following stats separated by
141+
whitespace:
142+
failed_reads
143+
failed_writes
144+
invalid_io
145+
notify_free
146+
136147
8) Deactivate:
137148
swapoff /dev/zram0
138149
umount /dev/zram1

‎drivers/block/zram/zram_drv.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,25 @@ static DEVICE_ATTR_RW(mem_used_max);
10331033
static DEVICE_ATTR_RW(max_comp_streams);
10341034
static DEVICE_ATTR_RW(comp_algorithm);
10351035

1036+
static ssize_t io_stat_show(struct device *dev,
1037+
struct device_attribute *attr, char *buf)
1038+
{
1039+
struct zram *zram = dev_to_zram(dev);
1040+
ssize_t ret;
1041+
1042+
down_read(&zram->init_lock);
1043+
ret = scnprintf(buf, PAGE_SIZE,
1044+
"%8llu %8llu %8llu %8llu\n",
1045+
(u64)atomic64_read(&zram->stats.failed_reads),
1046+
(u64)atomic64_read(&zram->stats.failed_writes),
1047+
(u64)atomic64_read(&zram->stats.invalid_io),
1048+
(u64)atomic64_read(&zram->stats.notify_free));
1049+
up_read(&zram->init_lock);
1050+
1051+
return ret;
1052+
}
1053+
1054+
static DEVICE_ATTR_RO(io_stat);
10361055
ZRAM_ATTR_RO(num_reads);
10371056
ZRAM_ATTR_RO(num_writes);
10381057
ZRAM_ATTR_RO(failed_reads);
@@ -1060,6 +1079,7 @@ static struct attribute *zram_disk_attrs[] = {
10601079
&dev_attr_mem_used_max.attr,
10611080
&dev_attr_max_comp_streams.attr,
10621081
&dev_attr_comp_algorithm.attr,
1082+
&dev_attr_io_stat.attr,
10631083
NULL,
10641084
};
10651085

0 commit comments

Comments
 (0)