29

I have an SSD in my laptop and I've been told that switching to the "noop" scheduler is preferred.

How do I change to the noop scheduler, and where do I make the change so that it is persistent across reboots?

Jorge Castro
  • 70,934
  • 124
  • 466
  • 653

4 Answers4

31

Suppose your hard disk is /dev/sda. Then you could check to see what scheduler is currently in use for it:

cat /sys/block/sda/queue/scheduler

(The scheduler currently in use will be surrounded by [ ] brackets.)

And you could make it use the noop scheduler:

echo noop > /sys/block/sda/queue/scheduler

See this article for slightly more information.

To make the change persist, you can put the command in /etc/rc.local.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
  • 1
    I get a "permission denied" error running this, even with sudo – Lucas Bustamante Jun 17 '19 at 17:46
  • 2
    @LucasBustamante Are you running `sudo echo noop > /sys/block/sda/queue/scheduler`? That doesn't work, as the shell, which runs as your user, sets up the redirection before running the command whose output is redirected. You can use `echo noop | sudo tee /sys/block/sda/queue/scheduler` instead. See [Cannot echo “hello” > x.txt even with sudo?](https://askubuntu.com/q/103643/22949) and [How to solve “permission denied” when using sudo with redirection in Bash?](https://askubuntu.com/q/230476/22949) for more information and other approaches. (If that's not what you mean, please let me know.) – Eliah Kagan Jun 17 '19 at 17:53
  • thanks for answering, that didn't help either. I'm using a NVMe SSD, I think it doesn't use the scheduler at all, from what I understood https://serverfault.com/questions/693348/what-does-it-mean-when-linux-has-no-i-o-scheduler – Lucas Bustamante Jun 17 '19 at 19:09
24

Edit /etc/default/grub, such as gksudo gedit /etc/default/grub, here you need to add elevator=noop.

Change GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=noop".

Then run sudo update-grub2 and restart.

Anonymous
  • 11,589
  • 5
  • 32
  • 33
  • 6
    Anonymous' answer is good for changing the default across all disks on a system. By contrast, Eliah Kagan's answer sets the default for specific disks. For a laptop with a single drive, either works fine. For systems with multiple disks -- most notably, disks with both SSDs and rotating drives), Eliah Kagan's answer provides finer-grained control. – Royce Williams May 29 '14 at 07:15
  • 6
    The `elevator=` kernel argument was removed in kernel v5.4, which is used since Ubuntu 20.04 LTS focal. https://github.com/torvalds/linux/commit/85c0a037dc7a1a34d6add49d6eaa2deddbf43d7b – Paul Tobias Apr 24 '20 at 08:58
14

This Debian reference shows how to dynamically detect SSDs and change the scheduler accordingly:

In systems with different drive types you can adjust settings with a udev rule (create /etc/udev/rules.d/60-ssd-scheduler.rules):

# Set deadline scheduler for non-rotating disks

 ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0",ATTR{queue/scheduler}="deadline"

To make sure that your kernel can detect rotational status:

$ for f in /sys/block/sd?/queue/rotational; do printf "$f is "; cat $f; done
/sys/block/sda/queue/rotational is 1
/sys/block/sdb/queue/rotational is 1
/sys/block/sdc/queue/rotational is 0   <=== Only this is SSD!

All of the above is quoted directly from the Debian reference, which has many other elements of interest to first-time SSD users.

Royce Williams
  • 286
  • 2
  • 6
  • root@titan:/home/kessaras# for f in /sys/block/sd?/queue/rotational; do printf "$f is "; cat $f; done /sys/block/sda/queue/rotational is 0 /sys/block/sdb/queue/rotational is 0 /sys/block/sdc/queue/rotational is 1 /sys/block/sdd/queue/rotational is 1 root@titan:/home/kessaras# cat /sys/block/sd*/queue/scheduler [mq-deadline] none [mq-deadline] none [mq-deadline] none [mq-deadline] none Something is very wrong here. It changes all the hard disks to deadline – Pavlos Theodorou Aug 14 '19 at 16:57
  • The command doesn't change anything - it simply reports whether a disk is "rotational" (HDD). Rotational = 0 means it's an SSD or other non-spinning drive. – Royce Williams Aug 14 '19 at 17:05
  • what do you mean it doesnt change anything ? And the udev rule written there what does it do ? It is inside a yellow box too. You mean that im blind or i can't read ? – Pavlos Theodorou Aug 15 '19 at 13:07
  • 1
    My mistake. It seems in latest kernel they removed the schedulers... ??? for f in /sys/block/sd?/queue/scheduler; do printf "$f is "; cat $f; done /sys/block/sda/queue/scheduler is [mq-deadline] none /sys/block/sdb/queue/scheduler is [mq-deadline] none /sys/block/sdc/queue/scheduler is [mq-deadline] none /sys/block/sdd/queue/scheduler is [mq-deadline] none The article and everything you wrote is fine. It's just that there is only deadline and nothing else to choose from. – Pavlos Theodorou Aug 15 '19 at 13:24
1
vi /etc/rc.local

Add line

for f in /sys/block/sd?/queue/scheduler; do echo "noop" > $f; cat $f; done

Then run the command

chmod +x /etc/rc.local
Tejas Lotlikar
  • 2,875
  • 5
  • 16
  • 26
mdobrzyn
  • 11
  • 1