writeback: throttle buffered writeback wb-buf-throttle-v6
authorJens Axboe <axboe@fb.com>
Wed, 31 Aug 2016 16:52:39 +0000 (10:52 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 31 Aug 2016 16:52:39 +0000 (10:52 -0600)
commit2f0a58af6c7396b8a8ee191955c4886b54240974
treedb6d1756c32f96525fb4172baa7a575dc2cf9cba
parent0ac0f3e57c1a9ef7cab6fea257890567495cb631
writeback: throttle buffered writeback

Test patch that throttles buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.

The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.

The patch registers two sysfs entries. The first one, 'wb_window_usec',
defines the window of monitoring. The second one, 'wb_lat_usec',
sets the latency target for the window. It defaults to 2 msec for
non-rotational storage, and 75 msec for rotational storage. Setting
this value to '0' disables blk-wb. Generally, a user would not have
to touch these settings.

We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.

Signed-off-by: Jens Axboe <axboe@fb.com>
Documentation/block/queue-sysfs.txt
block/Kconfig
block/blk-core.c
block/blk-mq.c
block/blk-settings.c
block/blk-stat.c
block/blk-sysfs.c
block/cfq-iosched.c
include/linux/blkdev.h