Selecting a Linux I/O Scheduler

前端 未结 5 851
逝去的感伤
逝去的感伤 2020-12-12 09:39

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

5条回答
  •  天命终不由人
    2020-12-12 10:08

    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.

    # 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 resources
    • deadline is a lightweight scheduler which tries to put a hard limit on latency
    • cfq tries to maintain system-wide fairness of I/O bandwidth

    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 most important 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.

提交回复
热议问题