Why aren’t you using ionice yet???

I am surprised at how many people complain about IO responsiveness while multitasking, but have never heard of ionice(1). Most intermediate-level Linux users have heard of, or know how to use, the nice command. Well, ionice is like nice for the disk (nice on most Linux kernels only affects the CPU scheduler. So, a large copy operation with the maximum niceness can still ruin disk response times to a process on highest priority.)

The best usecase for using ionice to improve performance is when you need to do two classes of tasks at once: The ones that don’t use much disk IO but demand fast response, and the ones that do a LOT of disk IO but don’t need it done urgently.

For example, think of some of the time-consuming things you want to do in the background, like:

  • Downloading a torrent on a fast internet link that creates a great deal of disk seeking.
  • Copy a huge file between two locations
  • Perform a system backup
  • Install your latest set up system updates

Most of the time, you really don’t care how fast (within reason) these tasks take, as long as your desktop applications don’t lag like hell! This is where ionice comes to the rescue. You can, in effect, tell Linux to only give disk access to these programs when nothing else wants it.

The command for doing this is sudo ionice -c3 -ppid, where pid is the numeric Process ID of the task you want to reschedule. You can find this number by looking at your GNOME or KDE process list viewer (also called System Monitor), or via top, ps -aux, and other command line tools. The -c3 part places the process in the idle scheduling class. You can read the ionice(1) man page for more cool things you can do with ionice.

Now, one trick you might find handy is rescheduling an entire parent shell to idle class, so that all commands executed from that shell are idle priority. You can get this from the $$ shell variable in bash and sh. For example:

jdong@severance:~$ echo $$

This output means that my current bash shell is process id 29033. If I want to switch the whole shell to idle disk priority, I would run:

jdong@severance:~$ sudo ionice -c3 -p$$

And there we go! Everything I do in this shell is now idle priority. Let’s apply this trick to other case. Ubuntu and other distributions like to run disk-intensive scripts like updatedb every night at midnight. If you’re a night owl like me and use your computer at these hours, this can be terribly irritating. Well, ionice to the rescue! Open up /etc/cron.daily/slocate, and add the following bolded line:

#! /bin/sh
ionice -c3 -p$$

if [ -x /usr/bin/slocate ]

And now, updatedb will no longer lag your productive midnight computing activities!

Now of course, there are a couple gotchas with ionice:

  1. It only works on kernels 2.6.13 and later using the CFQ IO scheduler. Kernels 2.6.17 (Ubuntu Edgy) and later, plus most versions of Redhat/Fedora-based distributions , will use the CFQ IO scheduler by default. You can check what scheduler is running by running cat /sys/block/[sh]d[a-z]*/queue/scheduler. The word outlined in [brackets] is currently selected. Use the boot parameter elevator=cfq in grub/menu.lst to set cfq as default.
  2. Idle priority is VERY cautious about marking block devices idle. If your foreground tasks are using disk, then your background tasks will become noticeably slower, as they get blocked from touching the disks until Linux knows for sure your foreground tasks have all had a chance at the disk. Most of the times, you don’t care about this anyway, but don’t run a torrent in non-idle class and expect a 20GB copy to finish till the torrent’s done!
  3. Please be careful fooling around with other ionice options, particularly the realtime class. You can easily set a process to receive the disk’s full attention and freeze your system. I’m not responsible for any hard reboots you have due to this.
  4. Some filesystems, particularly reiserfs and XFS, are very unfriendly at hogging the disk while performing metadata operations (such as creating or deleting files). Even ionice may not save you from noticeable disk IO lag during heavy metadata activities.


  1. […] lagging so not good that you can’t get anything else done! Fear no increasingly Linux fans, a great tutorial at Fried CPU shows you to use ionice to control that unruly I/O that’s sapping your real-time […]

  2. Thanks for the tip. This is really helpful.

    One Man. One Year. $100,000 online. How’s he doing it?

  3. Caleb Cushing said

    This looks cool… but um… where do I get Ionice? google’s my friend and all… but seems like you could provide a homepage link? my distro doesn’t seem to have it in it’s package manager.

  4. Caleb Cushing said

    found it… gentoo it’s in package sys-process/schedutils. seems like it should be merged into utils-linux soon according to the home page. http://rlove.org/

  5. Excuse me, but how does this help me watch pr0n?

  6. Jaytee said

    Excellent article and how-to. Clear, clean and concise, just the opposite of what I’m used to in tech docs and what actually prefer in women.

  7. bruce said

    great, thanks!

  8. […] Why aren’t you using ionice yet??? I am surprised at how many people complain about IO responsiveness while multitasking, but have never heard of […] […]

  9. marcos said

    but why i dont have this problems in window?
    the other day i was downloading a big file with wget and burning a dvd with k3b, k3b was so slow until I stoped wget.

  10. fryfrog said

    The one thing not mentioned is what package ionice is part of. In Ubuntu at least, it is part of [b]schedutils[/b] in case anyone is hoping to find and use it.

    Can it be used with regular old nice as well? Would `ionice -c3 nice -19 command` be a valid use?

  11. […] Linux: Using ionice to make disk IO more responsive when multitasking Ever had to run a huge copy or archiving job in the background while using your computer? Noticed that your background task seemed to make everything else that needed disk access REALLY lag? Learn how to tell Linux to prioritize disk access with ionice. (tags: digg Linux/Unix Technology) […]

  12. […] Link to Linux: Using ionice to make disk IO more responsive when multitasking […]

  13. […] Get real, dude. I don’t want to type a UNIX command every time I drag and drop an episode of House M.D. to file in the right folder. That’s a job for the computer. And, ideally, a job for the disk scheduler, not an external program that reacts slowly using out-of-date information. […]

  14. Crusader said

    This Gentoo wiki page mentions it, so it would seem so:


    ionice nice $1”

  15. […] read more | digg story […]

  16. You can also try the other schedulers. There are better schedulers for a desktop environment than CFQ. Also it will be interesting to see how CFS performs by comparison.

    Another solution is to get a more powerful machine. For example get yourself a dual or quad Opteron with dual core CPUs. Ensure that your storage is a 5 or more 15,000 RPM RAID0 stripe set of U320 devices with an ICP Vortex U320 controller card ( hard to find but they were/are the best ). Get ample RAM 16 or more GB, and make sure you have the highest of high-end nVidia GeForce video display controller card….etc etc

    -Dr. Ass Goblin Phd.

  17. […] July 18th, 2007 · No Comments Why aren’t you using ionice yet??? […]

  18. funsillygal said

    oooooooooooooooooookkkkkkkkkkkkkkk….i don’t care.

  19. […] Why aren’t you using ionice yet??? « Fried CPU ionice – control disk intensive operations (tags: linux performance ubuntu ionice disk io nice shell) […]

  20. […] Handle the Digg Effect With Your Blog Please Crash my HTTP server. An introduction to Yahoo Pipes Linux: Using ionice to make disk IO more responsive when multitasking Back up like an expert with rsync 10 hot tips to being a better IT manager What’s more […]

  21. […] read more | digg story […]

  22. […] read more | digg story […]

  23. […] read more | digg story […]

  24. […] read more | digg story […]

  25. […] read more | digg story […]

  26. http://xenoterracide.blogspot.com/2008/04/really-nice.html

    I just made a post about really nice (e.g. combining ionice and nice)

    funny to stumble upon an article I looked at a year-ish ago.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: