Linux Change The I/O Scheduler For A Hard Disk

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.

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
12 comments… add one
  • marco Sep 24, 2008 @ 15:41

    How do i change the scheduler in general?

  • newbie Oct 17, 2008 @ 10:21

    Edit /boot/grub/grub.conf and enter in kernel line elevator=noop or any other scheduler available.

    Kernel compilation should also be a way I think.?.

    http://www.redhat.com/magazine/008jun05/features/schedulers/

    Greetz

  • marco Oct 17, 2008 @ 15:57

    Thank you newbie. :)

  • Ratnadeep Joshi Nov 6, 2009 @ 8:43

    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

  • Danny Dec 29, 2009 @ 6:24

    “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.

  • sreenath s Sep 5, 2010 @ 18:20

    How to change the linux scheduler for user fairness ???

  • Kedar Mar 27, 2014 @ 6:56

    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.

    • Ron Jul 28, 2014 @ 13:55

      @Kedar: you would need to specify how exactly the external disk is attached

  • daft117 Jul 28, 2014 @ 20:37

    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.

    • Cat Grepper Oct 3, 2015 @ 23:06

      Advice from a cat grepper should generally be avoided.

  • Todd May 24, 2016 @ 12:23

    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’?
    Thanks

    • Terrance Jun 8, 2016 @ 15:45

      “noop deadline [cfq]”

      Means that “cfq” is the current elevator.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.