io_u: fix rate limiting to handle file wrap-around
authorKen Barr <kenbarr@google.com>
Fri, 3 Jan 2020 20:11:44 +0000 (15:11 -0500)
committerKen Barr <kenbarr@google.com>
Fri, 3 Jan 2020 20:11:44 +0000 (15:11 -0500)
commit970d9000a32a57b7a18333ec612e1a19276b0c87
treed9f086f7b18f1e386b509200af18f2e5ffa46508
parentdda119873be898ede40af9007ca0a9e79e3a9796
io_u: fix rate limiting to handle file wrap-around

When using "rate" with "time_based", the amount of time to sleep should be based
on the invocation time (epoch) rather than the start time of a given loop
(start) because no other statistics are reset when a file is re-opened.
Prior to this change, a wrap-around would cause the rate_ddir code to compute
that ~0 time had elapsed since the last I/O (i.e., a near-infinite rate), and
trigger a very long sleep in an attempt to adjust to the given rate.

Testing done:
  Using configuration below...
    Before: starts at 100 MB/sec and drops to 0 after ~10 sec (upon wrap) before
    recovering at t ~ 20.
    After: maintains 100 MB/sec for the duration of the test

  [repro]
  # 1 GiB + 1 Byte, to force a fill_io_u failure, the file to close and
  # reopen, and the start timestamp to reset.
  size=1073741825
  bs=2097152
  direct=1
  ioengine=psync
  readwrite=write

  runtime=30s
  time_based
  rate=100m

  filename=data_file
io_u.c