Skip to content
Snippets Groups Projects
  1. Sep 10, 2024
  2. May 31, 2024
  3. May 09, 2024
  4. Aug 30, 2023
  5. Jun 25, 2023
  6. Sep 27, 2022
  7. Sep 24, 2022
  8. Sep 12, 2022
    • 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.com
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      a880ae93
    • Yu Kuai's avatar
      blk-throttle: fix that io throttle can only work for single bio · 320fb0f9
      Yu Kuai authored
      
      Test scripts:
      cd /sys/fs/cgroup/blkio/
      echo "8:0 1024" > blkio.throttle.write_bps_device
      echo $$ > cgroup.procs
      dd if=/dev/zero of=/dev/sda bs=10k count=1 oflag=direct &
      dd if=/dev/zero of=/dev/sda bs=10k count=1 oflag=direct &
      
      Test result:
      10240 bytes (10 kB, 10 KiB) copied, 10.0134 s, 1.0 kB/s
      10240 bytes (10 kB, 10 KiB) copied, 10.0135 s, 1.0 kB/s
      
      The problem is that the second bio is finished after 10s instead of 20s.
      
      Root cause:
      1) second bio will be flagged:
      
      __blk_throtl_bio
       while (true) {
        ...
        if (sq->nr_queued[rw]) -> some bio is throttled already
         break
       };
       bio_set_flag(bio, BIO_THROTTLED); -> flag the bio
      
      2) flagged bio will be dispatched without waiting:
      
      throtl_dispatch_tg
       tg_may_dispatch
        tg_with_in_bps_limit
         if (bps_limit == U64_MAX || bio_flagged(bio, BIO_THROTTLED))
          *wait = 0; -> wait time is zero
          return true;
      
      commit 9f5ede3c ("block: throttle split bio in case of iops limit")
      support to count split bios for iops limit, thus it adds flagged bio
      checking in tg_with_in_bps_limit() so that split bios will only count
      once for bps limit, however, it introduce a new problem that io throttle
      won't work if multiple bios are throttled.
      
      In order to fix the problem, handle iops/bps limit in different ways:
      
      1) for iops limit, there is no flag to record if the bio is throttled,
         and iops is always applied.
      2) for bps limit, original bio will be flagged with BIO_BPS_THROTTLED,
         and io throttle will ignore bio with the flag.
      
      Noted this patch also remove the code to set flag in __bio_clone(), it's
      introduced in commit 111be883 ("block-throttle: avoid double
      charge"), and author thinks split bio can be resubmited and throttled
      again, which is wrong because split bio will continue to dispatch from
      caller.
      
      Fixes: 9f5ede3c ("block: throttle split bio in case of iops limit")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Link: https://lore.kernel.org/r/20220829022240.3348319-2-yukuai1@huaweicloud.com
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      320fb0f9
  9. Mar 18, 2022
  10. Feb 17, 2022
  11. Oct 18, 2021
Loading