Don't let updatedb take your Linux down
words - read.

Don't let updatedb take your Linux down

Coffee break everyone?

Everyday morning was the same: updatedb came and took my Gentoo away. The symptoms were clear, X/KDE applications starting to become slow and unresponsive, and then the two inevitable choices: go for a coffee and wait or pkill the bastard.

Asking updatedb to be nice (the wrong way)

To fix this came to my mind the nice command. This is well known to Gentoo users because of the PORTAGE_NICENESS feature include in make.conf. Nice is a program that adjusts the process scheduling (aka niceness) of the desired programs so setting a value of 19 (the maximum) would make updatedb to be "nicer" to other applications and therefore being less bossy. So I've edited /etc/cron.daily/slocate, placed "nice -n 19" before the updatedb command and waited. But, once again, updatedb came and owned my computer.

Asking updatedb to be I/O-nice (the right way)

So. what's wrong here? Updatedb is not a CPU-intensive application so nice won't change a thing. The bottleneck is disk access so what we need here is a nice for I/O. The solution? Ionice.

Ionice is able to set the I/O scheduling class and priority for a given program. To give updatedb a low priority we pick the class 3, the idle one.

Again, let's go to crontab and edit the slocate entry.

# vim /etc/cron.daily/slocate

Put ionice -c 3 before the updatedb command.

#! /bin/sh

if [ -x /usr/bin/updatedb ]
    if [ -f /etc/updatedb.conf ]
            ionice -c 3 /usr/bin/updatedb
            ionice -c 3 /usr/bin/updatedb -f proc

And if you're asking where (in Gentoo) is this ionice program, the solution is sys-apps/util-linux, which I'm pretty sure is already installed. If not:
# emerge -a sys-apps/util-linux

This is all good but... what's this updatedb thing?

Updatedb is a tool ran daily by cron to update the slocate database. And Slocate (Secure Locate) is a security enhanced version of the GNU Locate, which is used to index all the files of your system allowing a (very) quick search of them. In Gentoo Linux the slocate is available in Portage through sys-apps/slocate.


comments powered by Disqus