IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移动到底了再往反方向走,这恰恰就是现实生活中的电梯模型,所以IO调度器也被叫做电梯.(elevator)而相应的算法也就被叫做电梯算法.而Linux中IO调度的电梯算法有好几种,一个叫做as(Anticipatory),一个叫做cfq(Complete
Fairness Queueing),一个叫做deadline,还有一个叫做noop(No
Operation).具体使用哪种算法我们可以在启动的时候通过内核参数elevator来指定.
另一方面我们也可以单独的为某个设备指定它所采用的IO调度算法,这就通过修改在/sys/block/sda/queue/目录下面的scheduler文件.比如我们可以先看一下我的这块硬盘:
[root@localhost ~]# cat /sys/block/sda/queue/scheduler
noop anticipatory deadline [cfq]
可以看到我们这里采用的是cfq.
2.6内核的四种调度算法
In the 2.6 kernel series, there are four interchangeable
schedulers, as follows:
cfq- “Completely Fair Queuing” makes a good default for most
workloads on general-purpose servers.
as - “Anticipatory Scheduler” is best for workstations and other
systems with slow, single-spindle storage.
deadline - “Deadline” is a relatively simple scheduler which tries
to minimize I/O latency by re-ordering requests to improve
performance.
noop- “NOOP” is the most simple scheduler of all, and is really
just a single FIFO queue.
修改默认的IO调度算法
There are two ways to change the I/O scheduler - at boot time, or
with new kernels at runtime. For all Linux kernels, appending
‘elevator={noop|deadline}’ to the kernel boot string sets the I/O
elevator.
With LILO, you can use the ‘append’ keyword:
image=/boot/vmlinuz-2.6.14.2
label=14.2
append=”elevator=deadline”
read-only
optional
With GRUB, append the string to the end of the kernel
command:
title Fedora Core (2.6.9-5.0.3.EL_lustre.1.4.2custom)
root (hd0,0)
kernel /vmlinuz-2.6.9-5.0.3.EL_lustre.1.4.2custom ro
root=/dev/VolGroup00/LogVol00 rhgb noapic quiet
elevator=deadline
With newer Linux kernels (Red Hat Enterprise Linux v3 Update 3 does
not have this feature. It is present in the main Linux tree as of
2.6.15), one can change the scheduler while running. If the file
/sys/block//queue/scheduler
exists (where DEVICE is the block device you wish to affect), it
will contain a list of available schedulers and can be used to
switch the schedulers.
(hda is the ):
[root@cfs2]# cat /sys/block/hda/queue/scheduler
noop [anticipatory] deadline cfq
[root@cfs2 ~]# echo deadline >
/sys/block/hda/queue/scheduler
[root@cfs2 ~]# cat /sys/block/hda/queue/scheduler
noop anticipatory [deadline] cfq
The other schedulers (anticipatory and cfq) are better su