Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zram: deprecate zram attrs sysfs nodes

Add Documentation/ABI/obsolete/sysfs-block-zram file and list obsolete and
deprecated attributes there. The patch also adds additional information
to zram documentation and describes the basic strategy:

- the existing RW nodes will be downgraded to WO nodes (in 4.11)
- deprecated RO sysfs nodes will eventually be removed (in 4.11)

Users will be additionally notified about deprecated attr usage by
pr_warn_once() (added to every deprecated attr _show()), as suggested by
Minchan Kim.

User space is advised to use zram<id>/stat, zram<id>/io_stat and
zram<id>/mm_stat files.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reported-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>

authored by

Sergey Senozhatsky and committed by
Linus Torvalds
8f7d282c 4f2109f6

+150
+119
Documentation/ABI/obsolete/sysfs-block-zram
··· 1 + What: /sys/block/zram<id>/num_reads 2 + Date: August 2015 3 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 4 + Description: 5 + The num_reads file is read-only and specifies the number of 6 + reads (failed or successful) done on this device. 7 + Now accessible via zram<id>/stat node. 8 + 9 + What: /sys/block/zram<id>/num_writes 10 + Date: August 2015 11 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 12 + Description: 13 + The num_writes file is read-only and specifies the number of 14 + writes (failed or successful) done on this device. 15 + Now accessible via zram<id>/stat node. 16 + 17 + What: /sys/block/zram<id>/invalid_io 18 + Date: August 2015 19 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 20 + Description: 21 + The invalid_io file is read-only and specifies the number of 22 + non-page-size-aligned I/O requests issued to this device. 23 + Now accessible via zram<id>/io_stat node. 24 + 25 + What: /sys/block/zram<id>/failed_reads 26 + Date: August 2015 27 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 28 + Description: 29 + The failed_reads file is read-only and specifies the number of 30 + failed reads happened on this device. 31 + Now accessible via zram<id>/io_stat node. 32 + 33 + What: /sys/block/zram<id>/failed_writes 34 + Date: August 2015 35 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 36 + Description: 37 + The failed_writes file is read-only and specifies the number of 38 + failed writes happened on this device. 39 + Now accessible via zram<id>/io_stat node. 40 + 41 + What: /sys/block/zram<id>/notify_free 42 + Date: August 2015 43 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 44 + Description: 45 + The notify_free file is read-only. Depending on device usage 46 + scenario it may account a) the number of pages freed because 47 + of swap slot free notifications or b) the number of pages freed 48 + because of REQ_DISCARD requests sent by bio. The former ones 49 + are sent to a swap block device when a swap slot is freed, which 50 + implies that this disk is being used as a swap disk. The latter 51 + ones are sent by filesystem mounted with discard option, 52 + whenever some data blocks are getting discarded. 53 + Now accessible via zram<id>/io_stat node. 54 + 55 + What: /sys/block/zram<id>/zero_pages 56 + Date: August 2015 57 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 58 + Description: 59 + The zero_pages file is read-only and specifies number of zero 60 + filled pages written to this disk. No memory is allocated for 61 + such pages. 62 + Now accessible via zram<id>/mm_stat node. 63 + 64 + What: /sys/block/zram<id>/orig_data_size 65 + Date: August 2015 66 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 67 + Description: 68 + The orig_data_size file is read-only and specifies uncompressed 69 + size of data stored in this disk. This excludes zero-filled 70 + pages (zero_pages) since no memory is allocated for them. 71 + Unit: bytes 72 + Now accessible via zram<id>/mm_stat node. 73 + 74 + What: /sys/block/zram<id>/compr_data_size 75 + Date: August 2015 76 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 77 + Description: 78 + The compr_data_size file is read-only and specifies compressed 79 + size of data stored in this disk. So, compression ratio can be 80 + calculated using orig_data_size and this statistic. 81 + Unit: bytes 82 + Now accessible via zram<id>/mm_stat node. 83 + 84 + What: /sys/block/zram<id>/mem_used_total 85 + Date: August 2015 86 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 87 + Description: 88 + The mem_used_total file is read-only and specifies the amount 89 + of memory, including allocator fragmentation and metadata 90 + overhead, allocated for this disk. So, allocator space 91 + efficiency can be calculated using compr_data_size and this 92 + statistic. 93 + Unit: bytes 94 + Now accessible via zram<id>/mm_stat node. 95 + 96 + What: /sys/block/zram<id>/mem_used_max 97 + Date: August 2015 98 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 99 + Description: 100 + The mem_used_max file is read/write and specifies the amount 101 + of maximum memory zram have consumed to store compressed data. 102 + For resetting the value, you should write "0". Otherwise, 103 + you could see -EINVAL. 104 + Unit: bytes 105 + Downgraded to write-only node: so it's possible to set new 106 + value only; its current value is stored in zram<id>/mm_stat 107 + node. 108 + 109 + What: /sys/block/zram<id>/mem_limit 110 + Date: August 2015 111 + Contact: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> 112 + Description: 113 + The mem_limit file is read/write and specifies the maximum 114 + amount of memory ZRAM can use to store the compressed data. 115 + The limit could be changed in run time and "0" means disable 116 + the limit. No limit is the initial state. Unit: bytes 117 + Downgraded to write-only node: so it's possible to set new 118 + value only; its current value is stored in zram<id>/mm_stat 119 + node.
+16
Documentation/blockdev/zram.txt
··· 128 128 num_migrated RO the number of objects migrated migrated by compaction 129 129 130 130 131 + WARNING 132 + ======= 133 + per-stat sysfs attributes are considered to be deprecated. 134 + The basic strategy is: 135 + -- the existing RW nodes will be downgraded to WO nodes (in linux 4.11) 136 + -- deprecated RO sysfs nodes will eventually be removed (in linux 4.11) 137 + 138 + The list of deprecated attributes can be found here: 139 + Documentation/ABI/obsolete/sysfs-block-zram 140 + 141 + Basically, every attribute that has its own read accessible sysfs node 142 + (e.g. num_reads) *AND* is accessible via one of the stat files (zram<id>/stat 143 + or zram<id>/io_stat or zram<id>/mm_stat) is considered to be deprecated. 144 + 145 + User space is advised to use the following files to read the device statistics. 146 + 131 147 File /sys/block/zram<id>/stat 132 148 133 149 Represents block layer statistics. Read Documentation/block/stat.txt for
+15
drivers/block/zram/zram_drv.c
··· 43 43 /* Module params (documentation at end) */ 44 44 static unsigned int num_devices = 1; 45 45 46 + static inline void deprecated_attr_warn(const char *name) 47 + { 48 + pr_warn_once("%d (%s) Attribute %s (and others) will be removed. %s\n", 49 + task_pid_nr(current), 50 + current->comm, 51 + name, 52 + "See zram documentation."); 53 + } 54 + 46 55 #define ZRAM_ATTR_RO(name) \ 47 56 static ssize_t name##_show(struct device *d, \ 48 57 struct device_attribute *attr, char *b) \ 49 58 { \ 50 59 struct zram *zram = dev_to_zram(d); \ 60 + \ 61 + deprecated_attr_warn(__stringify(name)); \ 51 62 return scnprintf(b, PAGE_SIZE, "%llu\n", \ 52 63 (u64)atomic64_read(&zram->stats.name)); \ 53 64 } \ ··· 100 89 { 101 90 struct zram *zram = dev_to_zram(dev); 102 91 92 + deprecated_attr_warn("orig_data_size"); 103 93 return scnprintf(buf, PAGE_SIZE, "%llu\n", 104 94 (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT); 105 95 } ··· 111 99 u64 val = 0; 112 100 struct zram *zram = dev_to_zram(dev); 113 101 102 + deprecated_attr_warn("mem_used_total"); 114 103 down_read(&zram->init_lock); 115 104 if (init_done(zram)) { 116 105 struct zram_meta *meta = zram->meta; ··· 141 128 u64 val; 142 129 struct zram *zram = dev_to_zram(dev); 143 130 131 + deprecated_attr_warn("mem_limit"); 144 132 down_read(&zram->init_lock); 145 133 val = zram->limit_pages; 146 134 up_read(&zram->init_lock); ··· 173 159 u64 val = 0; 174 160 struct zram *zram = dev_to_zram(dev); 175 161 162 + deprecated_attr_warn("mem_used_max"); 176 163 down_read(&zram->init_lock); 177 164 if (init_done(zram)) 178 165 val = atomic_long_read(&zram->stats.max_used_pages);