https://zhuanlan.zhihu.com/p/450329513
简单地说,对于磁盘I/O,Linux提供了cfq, deadline和noop三种调度策略
考虑到硬件配置、实际应用场景(读写比例、顺序还是随机读写)的差异,上面的简单解释对于实际选择没有太大帮助,实际该选择哪个基本还是要实测来验证。不过下面几条说明供参考:
用如下命令可以查到每个磁盘的当前设置
# cat /sys/block/sda/queue/scheduler
[noop] deadline cfq
(方括号里面的是当前选定的调度策略)
用如下方法 即时 可以修改设置
echo deadline > /sys/block/sda/queue/scheduler
# or
echo deadline | sudo tee /sys/block/sda/queue/scheduler
Choosing a Disk Queue Scheduler
On GNU/Linux, the queue scheduler determines the order in which requests to a block
device are actually sent to the underlying device.
The default is Completely Fair Queueing, or cfq. It’s okay for casual use on laptops and desktops, where it helps prevent
I/O starvation, but it’s terrible for servers. It causes very poor response times under the types of workload that MySQL generates, because it stalls some requests in the queue
needlessly.
You can see which schedulers are available, and which one is active, with the following
command:
$ cat /sys/block/sda/queue/scheduler noop deadline [cfq]
You should replace sda with the device name of the disk you’re interested in. In our
example, the square brackets indicate which scheduler is in use for this device.
The
other two choices are suitable for server-class hardware, and in most cases they work
about equally well. The noop scheduler is appropriate for devices that do their own
scheduling behind the scenes, such as hardware RAID controllers and SANs, and deadline is fine both for RAID controllers and disks that are directly attached. Our benchmarks show very little difference between these two. The main thing is to use anything
but cfq, which can cause severe performance problems.
Take this advice with a grain of salt, though, because the disk schedulers actually come
in many variations in different kernels, and there is no indication of that in their names.