The patch titled Subject: zram: writeback throttle has been removed from the -mm tree. Its filename was zram-writeback-throttle-v4.patch This patch was dropped because it was folded into zram-writeback-throttle.patch ------------------------------------------------------ From: Minchan Kim <minchan@xxxxxxxxxx> Subject: zram: writeback throttle If there are lots of write IO with flash device, it could have a wearout problem of storage. To overcome the problem, admin needs to design write limitation to guarantee flash health for entire product life. This patch creates a new knob "writeback_limit" on zram. writeback_limit's default value is 0 so that it doesn't limit any writeback. If admin want to measure writeback count in a certain period, he could know it via /sys/block/zram0/bd_stat's 3rd column. If admin want to limit writeback as per-day 400M, he could do it like below. MB_SHIFT=20 4K_SHIFT=12 echo $((400<<MB_SHIFT>>4K_SHIFT)) > \ /sys/block/zram0/writeback_limit. If admin want to allow further write again, he could do it like below echo 0 > /sys/block/zram0/writeback_limit If admin want to see remaining writeback budget, cat /sys/block/zram0/writeback_limit The writeback_limit count will reset whenever you reset zram(e.g., system reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of writeback happened until you reset the zram to allocate extra writeback budget in next setting is user's job. Link: http://lkml.kernel.org/r/20181203024045.153534-8-minchan@xxxxxxxxxx Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx> Cc: Joey Pabalinas <joeypabalinas@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- Documentation/blockdev/zram.txt | 29 +++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.c | 21 +++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) --- a/Documentation/blockdev/zram.txt~zram-writeback-throttle-v4 +++ a/Documentation/blockdev/zram.txt @@ -277,6 +277,35 @@ Admin can request writeback of those idl With the command, zram writeback idle pages from memory to the storage. +If there are lots of write IO with flash device, potentially, it has +flash wearout problem so that admin needs to design write limitation +to guarantee storage health for entire product life. +To overcome the concern, zram supports "writeback_limit". +The "writeback_limit"'s default value is 0 so that it doesn't limit +any writeback. If admin want to measure writeback count in a certain +period, he could know it via /sys/block/zram0/bd_stat's 3rd column. + +If admin want to limit writeback as per-day 400M, he could do it +like below. + + MB_SHIFT=20 + 4K_SHIFT=12 + echo $((400<<MB_SHIFT>>4K_SHIFT)) > \ + /sys/block/zram0/writeback_limit. + +If admin want to allow further write again, he could do it like below + + echo 0 > /sys/block/zram0/writeback_limit + +If admin want to see remaining writeback budget since he set, + + cat /sys/block/zram0/writeback_limit + +The writeback_limit count will reset whenever you reset zram(e.g., +system reboot, echo 1 > /sys/block/zramX/reset) so keeping how many of +writeback happened until you reset the zram to allocate extra writeback +budget in next setting is user's job. + = memory tracking With CONFIG_ZRAM_MEMORY_TRACKING, user can know information of the --- a/drivers/block/zram/zram_drv.c~zram-writeback-throttle-v4 +++ a/drivers/block/zram/zram_drv.c @@ -330,7 +330,6 @@ next: } #ifdef CONFIG_ZRAM_WRITEBACK - static ssize_t writeback_limit_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -343,7 +342,7 @@ static ssize_t writeback_limit_store(str down_read(&zram->init_lock); atomic64_set(&zram->stats.bd_wb_limit, val); - if (val == 0 || val > atomic64_read(&zram->stats.bd_writes)) + if (val == 0) zram->stop_writeback = false; up_read(&zram->init_lock); ret = len; @@ -605,7 +604,6 @@ static ssize_t writeback_store(struct de char mode_buf[8]; unsigned long mode = -1UL; unsigned long blk_idx = 0; - u64 wb_count, wb_limit; sz = strscpy(mode_buf, buf, sizeof(mode_buf)); if (sz <= 0) @@ -710,7 +708,7 @@ static ssize_t writeback_store(struct de continue; } - wb_count = atomic64_inc_return(&zram->stats.bd_writes); + atomic64_inc(&zram->stats.bd_writes); /* * We released zram_slot_lock so need to check if the slot was * changed. If there is freeing for the slot, we can catch it @@ -734,9 +732,11 @@ static ssize_t writeback_store(struct de zram_set_element(zram, index, blk_idx); blk_idx = 0; atomic64_inc(&zram->stats.pages_stored); - wb_limit = atomic64_read(&zram->stats.bd_wb_limit); - if (wb_limit != 0 && wb_count >= wb_limit) - zram->stop_writeback = true; + if (atomic64_add_unless(&zram->stats.bd_wb_limit, + -1 << (PAGE_SHIFT - 12), 0)) { + if (atomic64_read(&zram->stats.bd_wb_limit) == 0) + zram->stop_writeback = true; + } next: zram_slot_unlock(zram, index); } @@ -1061,6 +1061,7 @@ static ssize_t mm_stat_show(struct devic } #ifdef CONFIG_ZRAM_WRITEBACK +#define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) static ssize_t bd_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1070,9 +1071,9 @@ static ssize_t bd_stat_show(struct devic down_read(&zram->init_lock); ret = scnprintf(buf, PAGE_SIZE, "%8llu %8llu %8llu\n", - (u64)atomic64_read(&zram->stats.bd_count) * (PAGE_SHIFT - 12), - (u64)atomic64_read(&zram->stats.bd_reads) * (PAGE_SHIFT - 12), - (u64)atomic64_read(&zram->stats.bd_writes) * (PAGE_SHIFT - 12)); + FOUR_K((u64)atomic64_read(&zram->stats.bd_count)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_reads)), + FOUR_K((u64)atomic64_read(&zram->stats.bd_writes))); up_read(&zram->init_lock); return ret; _ Patches currently in -mm which might be from minchan@xxxxxxxxxx are zram-fix-lockdep-warning-of-free-block-handling.patch zram-fix-double-free-backing-device.patch zram-refactoring-flags-and-writeback-stuff.patch zram-introduce-zram_idle-flag.patch zram-support-idle-huge-page-writeback.patch zram-add-bd_stat-statistics.patch zram-writeback-throttle.patch