Get rid of freeze-ups during disk I/O activity in Ubuntu

If you are using Ubuntu(or it’s variants), and your computer locks/freezes up or becomes unusable during copying files or heavy disk activity, this post is for you.

Ubuntu currently employs the kernel default I/O scheduler, CFQ or Completely Fair Queuing. It has been known to cause lags and lock-ups during heavy disk activity like copying/moving or backing up data, and one (still-active) bugs report demands the use of an alternative I/O scheduler by default in future Ubuntu releases.

Personally, my computer became virtually unusable during moving/copying files and it has been completely eradicated by the use of an alternative scheduler, Deadline. I’ll be using it for the examples here. Other alternative I/O schedulers include :

  • noop
  • anticipatory

At first, you need to check whether you really benefit from the use of an alternative i/o scheduler. To do this, run this from the console :

echo "deadline" | sudo tee /sys/block/sda/queue/scheduler

Now copy a large file to/from your hard drive. If the lock-ups vanish, this has worked for you. Now, we need to make this permanent for your system. To do this, you need to know which version of Ubuntu you are using. If you are using Ubuntu 9.10 (Karmic Koala) or higher, you will be using Grub2, else you’ll be using Grub Legacy. I have got instructions for both.

For Grub2 :

gksudo gedit /etc/default/grub

For Kubuntu and Xubuntu, you will need to use kdesu kate and gksudo mousepad in place of gksudo gedit respectively.

Find :

GRUB_CMDLINE_LINUX_DEFAULT=""

Add elevator=deadline before the end of the closing double-quotes. For me, after the edit, that line looked like this :

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=deadline"

After you are done, save and close the file. Now run “update-grub” from the terminal.

sudo update-grub

You’ll get something like this :

Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.31-20-generic
Found initrd image: /boot/initrd.img-2.6.31-20-generic
Found memtest86+ image: /boot/memtest86+.bin
done

It means grub.cfg has been rebuilt successfully. You are now good to go.

For legacy Grub :

gksudo gedit /boot/grub/menu.lst

For Kubuntu and Xubuntu, you will need to use kdesu kate and gksudo mousepad in place of gksudo gedit respectively.

Find the kernel line for your current kernel. It will be something like :

kernel /boot/vmlinuz-2.6.12-10-386 root=/dev/hda2 ro quiet splash

It will differ according to the kernel version and the logical drive to which Ubuntu is installed. Now add elevator=deadline to it. After the edit, it should look like this :

kernel /boot/vmlinuz-2.6.12-10-386 root=/dev/hda2 ro quiet splash elevator=deadline

Reboot your system and you are good to go.

12 Comments

  1. Victim says:

    Thanks a ton!

    Worked wonders for me, had just about given up on fixing this.

    1. Ellimist says:

      I’m glad it worked for you. :)

  2. Berti says:

    I have started using the “deadline” scheduler this morning at work, and my i7 now feels like a quad-core powered beast instead of a freeze-prone kitty :D

    Thank you very much!

    1. Ellimist says:

      Thanks for the comment and the linkage, Berti.

      I’m glad Ubuntu users with similar woes are finding this useful.

  3. [...] it seems that the disk scheduler is to blame here. But fear not, for there is a simple solution to your grievings. Changing the scheduler from CFQ (Completely Fair Queuing) to Deadline seems to [...]

  4. Cliff Steele says:

    This solution worked for me. Thanks for posting.

    1. Ellimist says:

      You are welcome.

  5. Not working for me :(

    I’m on Ubuntu 11.04 on MacBook 3.1 (120Go at 5400 rpm).

  6. Tim says:

    Hi,

    helped a lot with ubuntu 11 on usb-flashdrive.

    Thanks

    TIm

  7. noenid says:

    Worked like a charm, thanks a lot ! What’s the difference between this scheduler and the default (and the other alternatives) ?

    1. Ellimist says:

      This post at XDA precisely lists the features of different I/O schedulers: I/O SCHEDULERS

      You can also view the entries for individual schedulers at Wikipedia, if you are interested to know more about them.

      1. noenid says:

        Thanks !