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

Configure Feed

Select the types of activity you want to include in your feed.

zram: add writeback batch size device attr

Introduce writeback_batch_size device attribute so that the maximum number
of in-flight writeback bio requests can be configured at run-time
per-device. This essentially enables batched bio writeback.

Link: https://lkml.kernel.org/r/20251122074029.3948921-3-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Brian Geffon <bgeffon@google.com>
Cc: Minchan Kim <minchan@google.com>
Cc: Richard Chang <richardycc@google.com>
Cc: Yuwen Chen <ywen.chen@foxmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
e828cccb f405066a

+41 -6
+40 -6
drivers/block/zram/zram_drv.c
··· 590 590 return sysfs_emit(buf, "%llu\n", val); 591 591 } 592 592 593 + static ssize_t writeback_batch_size_store(struct device *dev, 594 + struct device_attribute *attr, 595 + const char *buf, size_t len) 596 + { 597 + struct zram *zram = dev_to_zram(dev); 598 + u32 val; 599 + 600 + if (kstrtouint(buf, 10, &val)) 601 + return -EINVAL; 602 + 603 + if (!val) 604 + return -EINVAL; 605 + 606 + down_write(&zram->init_lock); 607 + zram->wb_batch_size = val; 608 + up_write(&zram->init_lock); 609 + 610 + return len; 611 + } 612 + 613 + static ssize_t writeback_batch_size_show(struct device *dev, 614 + struct device_attribute *attr, 615 + char *buf) 616 + { 617 + u32 val; 618 + struct zram *zram = dev_to_zram(dev); 619 + 620 + down_read(&zram->init_lock); 621 + val = zram->wb_batch_size; 622 + up_read(&zram->init_lock); 623 + 624 + return sysfs_emit(buf, "%u\n", val); 625 + } 626 + 593 627 static void reset_bdev(struct zram *zram) 594 628 { 595 629 if (!zram->backing_dev) ··· 815 781 kfree(wb_ctl); 816 782 } 817 783 818 - /* XXX: should be a per-device sysfs attr */ 819 - #define ZRAM_WB_REQ_CNT 32 820 - 821 - static struct zram_wb_ctl *init_wb_ctl(void) 784 + static struct zram_wb_ctl *init_wb_ctl(struct zram *zram) 822 785 { 823 786 struct zram_wb_ctl *wb_ctl; 824 787 int i; ··· 830 799 init_waitqueue_head(&wb_ctl->done_wait); 831 800 spin_lock_init(&wb_ctl->done_lock); 832 801 833 - for (i = 0; i < ZRAM_WB_REQ_CNT; i++) { 802 + for (i = 0; i < zram->wb_batch_size; i++) { 834 803 struct zram_wb_req *req; 835 804 836 805 /* ··· 1231 1200 goto release_init_lock; 1232 1201 } 1233 1202 1234 - wb_ctl = init_wb_ctl(); 1203 + wb_ctl = init_wb_ctl(zram); 1235 1204 if (!wb_ctl) { 1236 1205 ret = -ENOMEM; 1237 1206 goto release_init_lock; ··· 2874 2843 static DEVICE_ATTR_WO(writeback); 2875 2844 static DEVICE_ATTR_RW(writeback_limit); 2876 2845 static DEVICE_ATTR_RW(writeback_limit_enable); 2846 + static DEVICE_ATTR_RW(writeback_batch_size); 2877 2847 #endif 2878 2848 #ifdef CONFIG_ZRAM_MULTI_COMP 2879 2849 static DEVICE_ATTR_RW(recomp_algorithm); ··· 2896 2864 &dev_attr_writeback.attr, 2897 2865 &dev_attr_writeback_limit.attr, 2898 2866 &dev_attr_writeback_limit_enable.attr, 2867 + &dev_attr_writeback_batch_size.attr, 2899 2868 #endif 2900 2869 &dev_attr_io_stat.attr, 2901 2870 &dev_attr_mm_stat.attr, ··· 2958 2925 2959 2926 init_rwsem(&zram->init_lock); 2960 2927 #ifdef CONFIG_ZRAM_WRITEBACK 2928 + zram->wb_batch_size = 32; 2961 2929 spin_lock_init(&zram->wb_limit_lock); 2962 2930 #endif 2963 2931
+1
drivers/block/zram/zram_drv.h
··· 129 129 struct file *backing_dev; 130 130 spinlock_t wb_limit_lock; 131 131 bool wb_limit_enable; 132 + u32 wb_batch_size; 132 133 u64 bd_wb_limit; 133 134 struct block_device *bdev; 134 135 unsigned long *bitmap;