选择 Linux I/O 调度程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1009577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting a Linux I/O Scheduler
提问by Robert S. Barnes
I read that it's supposedly possible to change the I/O scheduler for a particular device on a running kernel by writing to /sys/block/[disk]/queue/scheduler. For example I can see on my system:
我读到可以通过写入 /sys/block/[disk]/queue/scheduler 来更改正在运行的内核上特定设备的 I/O 调度程序。例如,我可以在我的系统上看到:
anon@anon:~$ cat /sys/block/sda/queue/scheduler
noop anticipatory deadline [cfq]
that the default is the completely fair queuing scheduler. What I'm wondering is if there is any use in including all four schedulers in my custom kernel. It would seem that there's not much point in having more than one scheduler compiled in unless the kernel is smart enough to select the correct scheduler for the correct hardware, specifically the 'noop' scheduler for flash based drives and one of the others for a traditional hard drive.
默认是完全公平的排队调度程序。我想知道在我的自定义内核中包含所有四个调度程序是否有任何用处。似乎编译一个以上的调度程序没有多大意义,除非内核足够聪明,可以为正确的硬件选择正确的调度程序,特别是针对基于闪存的驱动器的“noop”调度程序,以及用于传统驱动器的其他调度程序之一硬盘。
Is this the case?
是这种情况吗?
采纳答案by ephemient
As documented in /usr/src/linux/Documentation/block/switching-sched.txt
, the I/O scheduler on any particular block device can be changed at runtime. There may be some latency as the previous scheduler's requests are all flushed before bringing the new scheduler into use, but it can be changed without problems even while the device is under heavy use.
如 中所述/usr/src/linux/Documentation/block/switching-sched.txt
,可以在运行时更改任何特定块设备上的 I/O 调度程序。可能会有一些延迟,因为在使用新调度程序之前,先前调度程序的请求都被刷新了,但是即使在设备大量使用时也可以毫无问题地更改它。
# cat /sys/block/hda/queue/scheduler
noop deadline [cfq]
# echo anticipatory > /sys/block/hda/queue/scheduler
# cat /sys/block/hda/queue/scheduler
noop [deadline] cfq
Ideally, there would be a single scheduler to satisfy all needs. It doesn't seem to exist yet. The kernel often doesn't have enough knowledge to choose the best scheduler for your workload:
理想情况下,将有一个调度程序来满足所有需求。它似乎还不存在。内核通常没有足够的知识来为您的工作负载选择最佳调度程序:
noop
is often the best choice for memory-backed block devices (e.g. ramdisks) and other non-rotational media (flash) where trying to reschedule I/O is a waste of resourcesdeadline
is a lightweight scheduler which tries to put a hard limit on latencycfq
tries to maintain system-wide fairness of I/O bandwidth
noop
通常是内存支持的块设备(例如 ramdisk)和其他非旋转介质(闪存)的最佳选择,其中尝试重新安排 I/O 会浪费资源deadline
是一个轻量级的调度程序,它试图对延迟进行严格限制cfq
尝试保持系统范围内 I/O 带宽的公平性
The default was anticipatory
for a long time, and it received a lot of tuning, but was removed in 2.6.33(early 2010). cfq
became the default some while ago, as its performance is reasonable and fairness is a good goal for multi-user systems (and even single-user desktops). For some scenarios -- databases are often used as examples, as they tend to already have their own peculiar scheduling and access patterns, and are often the mostimportant service (so who cares about fairness?) -- anticipatory
has a long history of being tunable for best performance on these workloads, and deadline
very quickly passes all requests through to the underlying device.
默认设置anticipatory
了很长时间,并进行了大量调整,但在2.6.33(2010 年初)中被删除。 cfq
不久前成为默认设置,因为它的性能是合理的,公平是多用户系统(甚至单用户桌面)的一个很好的目标。对于某些场景——数据库经常被用作示例,因为它们往往已经有自己独特的调度和访问模式,并且通常是最重要的服务(那么谁在乎公平?)——anticipatory
具有可调性的悠久历史为了在这些工作负载上获得最佳性能,并且deadline
非常快速地将所有请求传递到底层设备。
回答by MarkR
The aim of having the kernel support different ones is that you can try them out without a reboot; you can then run test workloads through the sytsem, measure performance, and then make that the standard one for your app.
让内核支持不同内核的目的是让您无需重新启动就可以试用它们;然后,您可以通过系统运行测试工作负载,测量性能,然后使其成为您应用程序的标准工作负载。
On modern server-grade hardware, only the noop one appears to be at all useful. The others seem slower in my tests.
在现代服务器级硬件上,只有 noop 似乎完全有用。在我的测试中,其他人似乎更慢。
回答by KZcoding
The Linux Kernel does not automatically change the IO Scheduler at run-time. By this I mean, the Linux kernel, as of today, is not able to automatically choose an "optimal" scheduler depending on the type of secondary storage devise. During start-up, or during run-time, it is possible to change the IO scheduler manually.
Linux 内核不会在运行时自动更改 IO 调度程序。我的意思是,截至今天,Linux 内核无法根据二级存储设备的类型自动选择“最佳”调度程序。在启动期间或运行期间,可以手动更改 IO 调度程序。
The default scheduler is chosen at start-up based on the contents in the file located at /linux-2.6 /block/Kconfig.iosched. However, it is possible to change the IO scheduler during run-time by echo
ing a valid scheduler name into the file located at /sys/block/[DEV]/queue/scheduler. For example, echo deadline > /sys/block/hda/queue/scheduler
默认调度程序在启动时根据位于 /linux-2.6 /block/Kconfig.iosched的文件中的内容选择。但是,可以在运行时更改 IO 调度程序,方法是echo
将有效的调度程序名称放入位于 /sys/block/[DEV]/queue/scheduler 的文件中。例如,echo deadline > /sys/block/hda/queue/scheduler
回答by Dani_l
It's possible to use a udev rule to let the system decide on the scheduler based on some characteristics of the hw.
An example udev rule for SSDs and other non-rotational drives might look like
可以使用 udev 规则让系统根据硬件的某些特征决定调度程序。
SSD 和其他非旋转驱动器的示例 udev 规则可能如下所示
# set noop scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop"
inside a new udev rules file (e.g., /etc/udev/rules.d/60-ssd-scheduler.rules
). This answer is based on the debian wiki
在新的 udev 规则文件(例如,/etc/udev/rules.d/60-ssd-scheduler.rules
)中。这个答案基于debian wiki
To check whether ssd disks would use the rule, it's possible to check for the trigger attribute in advance:
要检查ssd磁盘是否会使用该规则,可以提前检查trigger属性:
for f in /sys/block/sd?/queue/rotational; do printf "$f "; cat $f; done
回答by Tim Savannah
You can set this at boot by adding the "elevator" parameter to the kernel cmdline (such as in grub.cfg)
您可以通过将“elevator”参数添加到内核 cmdline(例如在 grub.cfg 中)在启动时进行设置
Example:
例子:
elevator=deadline
This will make "deadline" the default I/O scheduler for all block devices.
这将使“deadline”成为所有块设备的默认 I/O 调度程序。
If you'd like to query or change the scheduler after the system has booted, or would like to use a different scheduler for a specific block device, I recommend installing and use the tool ioschedsetto make this easy.
如果您想在系统启动后查询或更改调度程序,或者想为特定块设备使用不同的调度程序,我建议安装并使用工具ioschedset来简化此操作。
https://github.com/kata198/ioschedset
https://github.com/kata198/ioschedset
If you're on Archlinux it's available in aur:
如果你使用 Archlinux,它可以在 aur 中使用:
https://aur.archlinux.org/packages/ioschedset
https://aur.archlinux.org/packages/ioschedset
Some example usage:
一些示例用法:
# Get i/o scheduler for all block devices
[username@hostname ~]$ io-get-sched
sda: bfq
sr0: bfq
# Query available I/O schedulers
[username@hostname ~]$ io-set-sched --list
mq-deadline kyber bfq none
# Set sda to use "kyber"
[username@hostname ~]$ io-set-sched kyber /dev/sda
Must be root to set IO Scheduler. Rerunning under sudo...
[sudo] password for username:
+ Successfully set sda to 'kyber'!
# Get i/o scheduler for all block devices to assert change
[username@hostname ~]$ io-get-sched
sda: kyber
sr0: bfq
# Set all block devices to use 'deadline' i/o scheduler
[username@hostname ~]$ io-set-sched deadline
Must be root to set IO Scheduler. Rerunning under sudo...
+ Successfully set sda to 'deadline'!
+ Successfully set sr0 to 'deadline'!
# Get the current block scheduler just for sda
[username@hostname ~]$ io-get-sched sda
sda: mq-deadline
Usage should be self-explanatory. The tools are standalone and only require bash.
用法应该是不言自明的。这些工具是独立的,只需要 bash。
Hope this helps!
希望这可以帮助!
EDIT: Disclaimer, these are scripts I wrote.
编辑:免责声明,这些是我写的脚本。