Choosing a Linux I / O Scheduler

I read that it is possible to change the I / O scheduler for a specific device on the running kernel by writing to / sys / block / [disk] / queue / scheduler. For example, I can see in my system:

anon@anon:~$ cat /sys/block/sda/queue/scheduler noop anticipatory deadline [cfq] 

which by default is a completely fair queue scheduler. I am wondering if there are any possibilities for including all four schedulers in my own kernel. It would seem that it makes little sense to compile more than one scheduler if the kernel is not smart enough to choose the right scheduler for the right hardware, in particular, the noop scheduler for flash drives and one of the others for a traditional hard drive .

In this case?

+80
linux linux-kernel scheduling
Jun 17 '09 at 21:22
source share
5 answers

As described 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 delay, since previous scheduler requests are all blurred before using the new scheduler, but it can be changed without problems even when the device is in heavy mode.

 # 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, one planner should satisfy all needs. It does not seem to exist yet. The kernel often lacks the knowledge to choose the best scheduler for your workload:

  • noop often the best choice for block devices with memory (such as ramdisks) and other non-rotating media (flash), where trying to transfer I / O is a waste of resources.
  • deadline is an easy scheduler that tries to limit latency
  • cfq tries to maintain system-wide I / O bandwidth fairness

The default was anticipatory for a long time, and it got a lot of settings, but was removed in 2.6.33 (early 2010). cfq became default some time ago, as its performance is reasonable, and fairness is a good target for multi-user systems (and even single desktop computers). For some scenarios, databases are often used as examples, since they usually already have their own planning and access schemes and are often the most important service (so who cares about justice?) - anticipatory has a long history of being tunable for better performance at these workloads, and deadline very quickly transfers all requests to the base device.

+107
Jun 18 '09 at 2:59
source share
β€” -

You can use the udev rule to make the system decide on a scheduler based on some of the hw characteristics.
An example udev rule for SSD and other non-rotational disks might look like

 # set noop scheduler for non-rotating disks ACTION=="add|change", KERNEL=="sd[az]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop" 

inside the new udev rule file (e.g. /etc/udev/rules.d/60-ssd-scheduler.rules ). This answer is based on the debian wiki

To check if ssd drives will use the rule, you can check the trigger attribute in advance:

 for f in /sys/block/sd?/queue/rotational; do printf "$f "; cat $f; done 
+19
Feb 03 '16 at 10:20
source share

The goal of kernel support is that you can try them without rebooting; you can run test workloads through sytsem, measure performance, and then make it standard for your application.

On modern server-level hardware, only the useful noop function is useful. The rest seem slower in my tests.

+7
Jun 17 '09 at 21:24
source share

You can set this at boot by adding the "elevator" parameter to the cmdline of the kernel (for example, to grub.cfg)

Example:

 elevator=deadline 

This will make the deadline the default I / O scheduler for all block devices.

If you want to request or change the scheduler after booting the system or want to use a different scheduler for a specific block device, I recommend installing and using the ioschedset tool to simplify this.

https://github.com/kata198/ioschedset

If you use Archlinux, it is available in aur:

https://aur.archlinux.org/packages/ioschedset

Some examples of use:

 # 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 

Use should be self-explanatory. The tools are standalone and require only bash.

Hope this helps!

EDIT: Disclaimer, these are the scripts I wrote.

0
Dec 11 '18 at 21:27
source share

The Linux kernel does not automatically change the I / O scheduler at run time. By this I mean that the Linux kernel today cannot automatically select the β€œoptimal” scheduler depending on the type of secondary storage. At startup or at run time, you can change the I / O scheduler manually .

The default scheduler is selected at startup based on the contents of the file located in / linux -2.6 /block/Kconfig.iosched . However, at runtime, you can change the I / O scheduler to echo correct scheduler name in the file located in / sys / block / [DEV] / queue / scheduler. For example, echo deadline > /sys/block/hda/queue/scheduler

-6
Nov 13
source share



All Articles