• Liu Bo's avatar
    blk-iolatency: fix IO hang due to negative inflight counter · 8c772a9b
    Liu Bo authored
    Our test reported the following stack, and vmcore showed that
    ->inflight counter is -1.
    
    [ffffc9003fcc38d0] __schedule at ffffffff8173d95d
    [ffffc9003fcc3958] schedule at ffffffff8173de26
    [ffffc9003fcc3970] io_schedule at ffffffff810bb6b6
    [ffffc9003fcc3988] blkcg_iolatency_throttle at ffffffff813911cb
    [ffffc9003fcc3a20] rq_qos_throttle at ffffffff813847f3
    [ffffc9003fcc3a48] blk_mq_make_request at ffffffff8137468a
    [ffffc9003fcc3b08] generic_make_request at ffffffff81368b49
    [ffffc9003fcc3b68] submit_bio at ffffffff81368d7d
    [ffffc9003fcc3bb8] ext4_io_submit at ffffffffa031be00 [ext4]
    [ffffc9003fcc3c00] ext4_writepages at ffffffffa03163de [ext4]
    [ffffc9003fcc3d68] do_writepages at ffffffff811c49ae
    [ffffc9003fcc3d78] __filemap_fdatawrite_range at ffffffff811b6188
    [ffffc9003fcc3e30] filemap_write_and_wait_range at ffffffff811b6301
    [ffffc9003fcc3e60] ext4_sync_file at ffffffffa030cee8 [ext4]
    [ffffc9003fcc3ea8] vfs_fsync_range at ffffffff8128594b
    [ffffc9003fcc3ee8] do_fsync at ffffffff81285abd
    [ffffc9003fcc3f18] sys_fsync at ffffffff81285d50
    [ffffc9003fcc3f28] do_syscall_64 at ffffffff81003c04
    [ffffc9003fcc3f50] entry_SYSCALL_64_after_swapgs at ffffffff81742b8e
    
    The ->inflight counter may be negative (-1) if
    
    1) blk-iolatency was disabled when the IO was issued,
    
    2) blk-iolatency was enabled before this IO reached its endio,
    
    3) the ->inflight counter is decreased from 0 to -1 in endio()
    
    In fact the hang can be easily reproduced by the below script,
    
    H=/sys/fs/cgroup/unified/
    P=/sys/fs/cgroup/unified/test
    
    echo "+io" > $H/cgroup.subtree_control
    mkdir -p $P
    
    echo $$ > $P/cgroup.procs
    
    xfs_io -f -d -c "pwrite 0 4k" /dev/sdg
    
    echo "`cat /sys/block/sdg/dev` target=1000000" > $P/io.latency
    
    xfs_io -f -d -c "pwrite 0 4k" /dev/sdg
    
    This fixes the problem by freezing the queue so that while
    enabling/disabling iolatency, there is no inflight rq running.
    
    Note that quiesce_queue is not needed as this only updating iolatency
    configuration about which dispatching request_queue doesn't care.
    Signed-off-by: default avatarLiu Bo <bo.liu@linux.alibaba.com>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    8c772a9b
blk-iolatency.c 28 KB