Disks and Filesystems

Disks are one of the few moving parts in your computer, and they tend to have a high speed data link going to them. Both of these properties turn disks into serious power consumers when they’re active.

SATA Aggressive Link Power Management

Several SATA controllers, that use the AHCI specification, have a feature called ALPM, which stands for Aggressive Link Power Management. ALPM is a technique where the SATA AHCI controller puts the SATA link to the disk into a very low power mode when there’s no IO for awhile. The controller automatically puts the link back into active power state when there’s real work to be done. This can save between 0.5 and 1.5 Watts of power.

Find more details about ALPM in the Device power management project section of this web site.

As of kernel version 2.6.23, the ALPM patches have not been merged yet; they are however on track for the 2.6.24 or 2.6.25 kernel series. Until then, you can download the patches from the download page.

Filesystem atime

The POSIX standard requires operating systems to: keep track of the last time each file was accessed by an application or the user, and to store this timestamp as part of the filesystem data. This timestamp, called atime. atime, can be useful in finding out which files are never used (to clean up the /tmp directory for example) or to find out if a file has been looked at after it changed (this is sometimes used by email applications to warn about newly received email).

A significant downside to atime, is that every time a file is accessed, the kernel has to write a new timestamp to the disk, at least after a few seconds of activity. These disk writes will keep the disk and the link to the disk busy, and that costs both performance (the disk is prevented from doing something else) and power (with ALPM, the link to the disk needs to be powered back on, and if the disk was in low power mode, it would need to go to full power as well).

You can disable atime entirely using this command:

mount -o remount,noatime   /

Filesystem relatime

Because few programs use atime, disabling it always and for everyone is not very practical. The Linux kernel has a feature called relatime, which is an effective compromise between having some of the information that atime provides, without having the disk time updated every single time.

relatime works by updating the atime field on disk only if the file hasn’t been accessed since the last time it was accessed, (to provide the new email detection capability) or when the last access was more than 1 day ago (to help programs and users clean up unused files in the /tmp directory).

A discussion of the relatime option can be found at http://lwn.net/Articles/244829/.

Older version of the mount command do not support relatime, but you can try the following command to see if your mount program and kernel support relatime:

mount -o remount,relatime /

Another option is to use the nodiratime option instead of noatime or relatime. nodiratime will not update the atime field on directory inodes. This allows you to continue to update file access on read, for programs which require it, but prevents updates for just reading a directory, such as with ls.

mount -o remount,nodiratime /

Disk Power Management

Some hard disks support disk power management. You can use the hdparm program to check whether your disk supports this feature.

hdparm -i /dev/sda

/dev/sda:

 Model=HTS541060G9SA00, FwRev=MB3IC60H, SerialNo=      MPBCL0XGHTUU8M
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
 BuffType=DualPortCache, BuffSize=7538kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=117210240
 IORDY=on/off, tPIO={min:240,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4
 DMA modes:  mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2
 AdvancedPM=yes: mode=0x80 (128) WriteCache=enabled
 Drive conforms to: ATA/ATAPI-7 T13 1532D revision 1:
 ATA/ATAPI-2 ATA/ATAPI-3 ATA/ATAPI-4
 ATA/ATAPI-5 ATA/ATAPI-6 ATA/ATAPI-7

 * signifies the current active mode

If your hard drive supports AdvancedPM, you can use hdparm to tell the disk to go into power savings mode after an elapsed period of idle time. The relevant options for hdparm are:

 -B   set Advanced Power Management setting (1-255)
 -S   set standby (spindown) timeout
 -y   put IDE drive in standby mode
 -Y   put IDE drive to sleep
 -Z   disable Seagate auto-powersaving mode

To put the disk into the most aggressive power savings mode after 60 seconds of idle time, you would use:

hdparm -B 1 -S 12 /dev/sda

Read more about hdparm on your system by typing:

man hdparm

The VM writeback time

The VM subsystem, in the Linux kernel, buffers writes to files that applications perform for a period of time. This caching allows the kernel to group consecutive writes into one big write, and to generally optimize the disk IO to be the most efficient. The kernel, by default, will start writing out data to disk after 5 seconds, so, if a power failure or kernel crash happens, at most, 5 seconds of data would be lost.

If your machine has a reliable power supply (for example because you have a UPS or because your laptop has a battery) and doesn’t crash much, you can increase this time so that the VM subsystem can do a better job optimizing the IO, as well as having the disk (and the SATA link when using ALPM) in lower power states for a longer period of time.

You can check the current value of this writeback time with this command:

# cat /proc/sys/vm/dirty_writeback_centisecs
500

This example shows that the timeout on this system was 500 centiseconds (or 5 seconds in human terms). To increase the timeout to 15 seconds, you can issue this command:

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

Enable laptop mode

For several years, the Linux kernel has had a “laptop mode” for the IO subsystem. When laptop mode is enabled, the kernel will try to be smart about when to do IO, to give the disk and the SATA links as much time as possible in a low power state.

Laptop mode works by submitting all future pending disk IO (such as pending VM cache writebacks, as described in the VM writeback time tip, above) at once, when the kernel has to do an IO to the disk for any reason. By submitting future planned IO right away, when the disk is powered up anyway, the assumption is that this IO will no longer need to happen, so the disk can remain in a low power mode longer.

You can see if laptop mode is active with this command:

# cat /proc/sys/vm/laptop_mode
5

If the content of that file is 0, laptop mode is disabled. In the example here, laptop mode is enabled.

To enable laptop mode, you can use this command:

echo 5 > /proc/sys/vm/laptop_mode

Several distributions also include the laptopmode scripts as part of their standard installation. These scripts enable laptop mode automatically, in some cases.

Use the “-” option in /etc/syslog.conf

The syslog daemon is the software component that takes care of logging all kernel and related logmessages to the /var/log/messages file. By default, the syslog daemon will issue a filesystem sync operation after each message. This sync operation has three effects on typical Linux systems: The data is written from the disk cache to the actual disk immediately (so the disk wakes up more); for some of the journalling filesystems, the journal gets flushed and cleaned, and the cache on the drive itself is flushed to the platter.

This sync operation makes sure that crash logs of critical systems have a higher chance of being on the disk in the event of a system crash.

However, more disk IO will consume more power (and will potentially hurt interactive performance some); if your requirements for syslog are less strict than described above, you can edit the /etc/syslog.conf file and add a “-” in front of this line:

*.info;mail.none;authpriv.none;cron.none		/var/log/messages

like this:

*.info;mail.none;authpriv.none;cron.none		-/var/log/messages

This will cause the syslog program to stop using the sync operation for the most common messages.

hal cdrom polling

hal is a core component of the various desktop environments and deals with all sorts of hardware interaction. One component of the hal daemon is the part where it polls the cdrom drive regularly (as often as once every two seconds!) to see if the user has inserted a CD. This is used, for example, to automatically open a new window with a file browser for the CD.

Such regular polling will keep the hardware awake somewhat; the amount of power consumed depends on the exact type of CDROM drive. It also depends on the presence of the ALPM feature.

If you rarely or never insert CDs (for example because the machine in question is a server located 3000 miles away), you can save some power by stopping this polling.

Current versions of hal have a special command for this:

hal-disable-polling --device /dev/scd0

Note that this means that you will not get a pop-up window if you insert a CD. To enable this polling again, use the this command:

hal-disable-polling --device /dev/scd0 --enable-polling

Newer SATA-based CDROM drives have the capability to notify the machine when a CD gets inserted, making polling unnecessary. Both the kernel and hal are currently undergoing development to detect and support this capability, so that polling is not needed at any time for these devices.

Kill Unnecessary Programs and Services

Some programs keep your disk busy, which drains power. If you are in a power conservation environment, you will want to stop these programs from executing. Below is a list of programs that you should consider killing, to save power:


  • beagle – Beagle indexes files on your desktop.
  • updatedb – updatedb creates the database for locate