• Yu Kuai's avatar
    blk-throttle: fix io hung due to configuration updates · a880ae93
    Yu Kuai authored
    If new configuration is submitted while a bio is throttled, then new
    waiting time is recalculated regardless that the bio might already wait
    for some time:
    
    tg_conf_updated
     throtl_start_new_slice
      tg_update_disptime
      throtl_schedule_next_dispatch
    
    Then io hung can be triggered by always submmiting new configuration
    before the throttled bio is dispatched.
    
    Fix the problem by respecting the time that throttled bio already waited.
    In order to do that, add new fields to record how many bytes/io are
    waited, and use it to calculate wait time for throttled bio under new
    configuration.
    
    Some simple test:
    1)
    cd /sys/fs/cgroup/blkio/
    echo $$ > cgroup.procs
    echo "8:0 2048" > blkio.throttle.write_bps_device
    {
            sleep 2
            echo "8:0 1024" > blkio.throttle.write_bps_device
    } &
    dd if=/dev/zero of=/dev/sda bs=8k count=1 oflag=direct
    
    2)
    cd /sys/fs/cgroup/blkio/
    echo $$ > cgroup.procs
    echo "8:0 1024" > blkio.throttle.write_bps_device
    {
            sleep 4
            echo "8:0 2048" > blkio.throttle.write_bps_device
    } &
    dd if=/dev/zero of=/dev/sda bs=8k count=1 oflag=direct
    
    test results: io finish time
    	before this patch	with this patch
    1)	10s			6s
    2)	8s			6s
    Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
    Reviewed-by: default avatarMichal Koutný <mkoutny@suse.com>
    Acked-by: default avatarTejun Heo <tj@kernel.org>
    Link: https://lore.kernel.org/r/20220829022240.3348319-5-yukuai1@huaweicloud.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
    a880ae93
blk-throttle.h 6.37 KB