Next Previous Contents

4. Changing some general system settings

After I got Linux up and running on my laptop, I found it accessing the harddisk every few seconds, even when there was no user logged in to the system. The harddisk could never enter its power saving mode. Reducing harddisk activity can greatly increase the battery runtime, so this is why I collected the following recipes.

I tested all this with RedHat 4.1, the locations of some configuration settings may be different for your distribution. (If so, please let me know.)

4.1 The crond daemon and atrun

Check your /etc/crontab file if it starts a process every minute. You will often find atrun there.

With the at command, you can spool commands that must be invoked some time in the future. Some Linux systems use a dedicated atd daemon to take care of this, others (e. g. RedHat) let the crond daemon run atrun once every minute.

This is not really necessairy on most systems, since at commands rarely depend upon being invoked on exact time. So if you find a line like this in your /etc/crontab:


# Run any at jobs every minute
* * * * * root [ -x /usr/sbin/atrun ] && /usr/sbin/atrun

Then you can safely change this to:


# Run any at jobs every hour
00 * * * * root [ -x /usr/sbin/atrun ] && /usr/sbin/atrun

Read man 5 crontab for details. Some folks can even work fine without the crond daemon, so if you know what you are doing, you might want to consider disabling it completely.

4.2 The update / bdflush daemon

Linux deals with a lot of open file buffers at any given moment, so the system must make sure that file changes are saved to the harddisk as soon possible. Otherwise, those changes will be lost after a system crash.

The update / bdflush daemon takes care of this. (These are two names for the same program, so you can use either name to start the daemon). The default settings will make this daemon call flush every 5 seconds and sync every 30 seconds.

With my Fujitsu disk this caused non-stop access. (It seems that this harddisk flushes its ram cache even when nothing has changed. But this depends on your harddisk's firmware: Other people told me that their harddisk does enter its power saving mode even without the following modification.)

Since Linux does not crash very often anymore, I have changed both values to 3600 seconds (= one hour). This caused no problems at all and the constant disk access has stopped. (But if my system crashes now, there will be more broken files, of course.)

RedHat 4.1: In /etc/inittab, change the update call to:


ud::once:/sbin/update -s 3600 -f 3600

Suse 4.4.1: update is called in /sbin/init.d/boot.

Slackware: update is called in /etc/rc.d/rc.S.

See man update for details.

4.3 The syslogd daemon

The syslogd daemon is responsible for the various Linux system log files that are found in the /var/log/ directory. By default syslogd will sync the log file each time after logging a system message.

You can turn that off by preceding the filename with a dash in /etc/syslog.conf. Here's an example as found in my system's syslog.conf:


# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none                  -/var/log/messages

This again means that if the system crashes, the message that reported the problem may not have been stored to disk. Dilemma...

4.4 The init command

During the bootup, the initial processes and daemons will be started using the init command. This command (yet again) calls sync before each process it creates.

You can change this by removing the sync() call in the source code and recompiling the command.

To avoid problems with lost file buffers, you should add a call to sync in your system's /etc/rc.d/init.d/halt script, right before the script unmounts the file systems.

4.5 The swap partition

The Linux swap partition is used to increase the physical ram space with virtual memory. This again is a possible reason for harddisk access. If your laptop already has a lot of ram or if the applications that you use are quite simple (think of vi), you might want to consider turning it off.

This of course depends on what you plan to do. 4 to 8 megs are not enough, you must use a swap partition then. With 8 to 16 megs, text console applications will work fine and if you can avoid using a lot of multitasking features, you can safely disable swap. The X-Windows enviroment requires a lot of ram and you should not use it without a swap partition unless you really have a lot more than 16 megs.

(Sidenote: My laptop with 16 megs and disabled swap partition can run an emacs session, four bash shells and compile a kernel without running out of memory. That's enough for me.)

If you already have installed a swap partition, you can disable it by preceding the swapon command that is called in /etc/rc.d/rc.sysinit with a hash mark. If you don't want to make it a permanent move, let the system ask during boot if you want to use the swap partition. In /etc/rc.d/rc.sysinit (RedHat 4.1) or /sbin/init.d/boot (Suse 4.4.1):


echo "Should the system use swap?"
echo "  0: No."
echo "  1: Yes."
/bin/echo "Your choice: \c"
read SWAPCHOICE

case "$SWAPCHOICE" in
    0)
        # Do nothing.
        echo "(Swap partitions disabled)"
        ;;
    *)
        # Start up swapping.
        echo "Activating swap partitions"
        swapon -a
esac

Then you can use the swap partition while on ac power and drop it while on battery.

4.6 The apache httpd webserver daemon

I am using my laptop to develop and test cgi scipts for websites, that is why I am running a local webserver on it. The standard configuration is a bit too much if all you want to do is just test a script or check a page from time to time.

In httpd.conf, just change the values of MinSpareServers and StartServers to 1. This will be enough for a local test site.

If you wish to turn off the webserver's logging, you must recompile the httpd daemon. Read the documentation for details.

Grant Taylor recompiled apache's logging and found that this ``didn't make it stop churning the disk. So I used another, IMHO better, solution: I configured apache to run from inetd instead of standalone.'' Read man inetd for details.

4.7 The XFree86 package

Configuring XFree86 for laptops is a story of its own. And yet again, I have to refer you to the Linux Laptop page where you will find a lot of help on this.

X's console blanking only turns the screen black, but does not turn it off. As mentioned in the sidenote about console blanking, you can use xset's dpms option to change this. However, this feature depends on your laptop's graphics chipset and bios.

Grant Taylor uses the following setup to send his laptop to sleep with the help of apmd and the screensaver:


# Run xscreensaver with APM program
xscreensaver -timeout 5 \
             -xrm xscreensaver.programs:apm_standby \ 
             -xrm xscreensaver.colorPrograms:apm_standby &

Where ``apm_standby is a suid perl script that allows only certain people to run apm -S.''

4.8 The emacs editor

Ok, emacs is not an editor, but a way of life. Here's a tip from Florent Chabaud: ``If you use emacs, perhaps you have noticed that the editor makes some automatic saves. This is of course useful and should not be disabled, but the default parameters can be adjusted to a laptop use.

I have put in the file /usr/share/emacs/site-lisp/site-start.el the two following lines:


(setq auto-save-interval 2500)
(setq auto-save-timeout nil)

This disables auto-saving based on time, and makes the auto-saving be done every 2500 keyboard actions. Of course if you are typing a text this last parameter should be reduced, but for programming it is sufficient. Since every action (up, down, left, backspace, paste, etc...) is counted, 2500 actions are reached very rapidly.''

4.9 How to find more ways to optimize

If your Linux system still seems to access the harddisk too often, you can find out what is going on inside by using the ps ax command. This will show all running processes and their full name, sometimes it also reveals the command line arguments of each process.

Now read the man page of each process to find out what it does and how to change its behaviour. With this method, you will most likely find the process that is responsible. You may also find strace helpful.

Please send me an email if you found something new.


Next Previous Contents