Linux Change The I/O Scheduler For A Hard Disk

last updated in Categories , , , , , , , ,

How do I change the I/O scheduler for a particular hard disk without rebooting my Linux server system?

CFQ [cfq] (Completely Fair Queuing) is an I/O scheduler for the Linux kernel and default under many Linux distributions.

Noop scheduler (noop) is the simplest I/O scheduler for the Linux kernel based upon FIFO queue concept.

Anticipatory scheduler (anticipatory) is an algorithm for scheduling hard disk input/output as well as old scheduler which is replaced by CFQ

Deadline scheduler (deadline) – it attempt to guarantee a start service time for a request.

Task: View Current Disk scheduler

Assuming that your disk name /dev/sda, type:
# cat /sys/block/{DEVICE-NAME}/queue/scheduler
# cat /sys/block/sda/queue/scheduler

Sample output:

noop anticipatory deadline [cfq]

Task: Set I/O Scheduler For A Hard Disk

To set a specific scheduler, simply type the command as follows:
# echo {SCHEDULER-NAME} > /sys/block/{DEVICE-NAME}/queue/scheduler
For example, set noop scheduler, enter:
# echo noop > /sys/block/hda/queue/scheduler

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

12 comment

  1. You can echo to /sys/block//queue/scheduler/

    e.g. If you want the scheduler to be ‘noop’ for ‘sda’, you should run:
    # echo noop > /sys/block/sda/queue/scheduler

  2. “But I’m on Ubuntu, and I want to do it without enabling the root account or running sudo su –:
    echo anticipatory | sudo tee /sys/block/sdb/queue/scheduler

    Also note that, if you’re using lvm, you’ll have the physical devices (like sda) as well as the virtual devices (like dm-1). Same goes for software raid – you’ll have md0, etc. It’s unclear to me which setting wins if you are running lvm on top of software raid (which isn’t incredibly uncommon), and have different schedulers set for the physical disks, raid devices, and lvm devices…

    PS: it looks like you can find out which LVM volume maps to “dm-6”, for example, by dong an ls -l on /dev/block/252:*. On one of my machines, I get

    lrwxrwxrwx 1 root root 18 2009-12-12 21:53 /dev/block/252:6 -> ../mapper/pyro-var

    Which indicates that dm-6 is currently the “var” volume in the “pyro” volume group.

  3. I cant find device name of my attached device in /sys/block/ since its attached external drive. Therefore I cant see current io-scheduler for this disk.
    Please help.

  4. we can automate this step for every reboot by:

    cat /etc/rc.local | grep -iv “^exit” > /tmp/temp
    echo -e “echo deadline > /sys/block/vda/queue/scheduler\nexit 0” >> /tmp/temp
    cat /tmp/temp > /etc/rc.local; rm /tmp/temp

    as u can see i used deadline for vda in this example.
    it simply ignore “exit” line and add deadline command to reboot script.

  5. I did: “cat /sys/block/sda/queue/scheduler”
    The output is: “noop deadline [cfq]”
    What does it mean?
    Is my current elevator ‘noop’, ‘deadline’ or ‘cfq’?

    Still, have a question? Get help on our forum!