Minimizing Power Consumption in Linux

From JimboWiki
Revision as of 01:02, 17 December 2007 by J (Talk | contribs) (Wireless Powersave Mode)

Jump to: navigation, search

Want to make your laptop battery last longer? Want to lower the power consumption of that awesome Linux based media PC you have? Here's where to start.

This article is written specifically for Ubuntu 7.10 (Gusty Gibbon), but the ideas expressed here can apply to any Linux distribution. Some of the higher-level thought can even be applied to other operating systems.

This page is incomplete
More work needs to be done on this page, so if something is missing, don't be surprised
1 Still working on finding ways to save power
2 Need to finish documenting others


Overview

The high level concept of battery discharge science that this article depends on is pretty simple - the more load (measured in Watts, abbreviated W) put onto a given battery of a set capacity (measured in Volt Hours, abbreviated Vh), the faster it will drain. So, if we want to make the battery last longer, we need to minimize the load or get a larger capacity battery - obviously.

Laptop batteries are expensive, and larger capacity usually means a heavier battery - so getting a new battery is probably not such a good idea. Of course, none of that battery stuff applies to the power consumption of a desktop machine - and I told you we could lower the power consumption of those too - so a new battery is definitely not the answer.

Instead of a bigger battery, we could consider physical devices that consume less power. For instance:

Device Typical Device Power Saving Device
Hard Drive Spinning platters, moving read/write head Solid state - no moving parts
CPU High power, full size processor, single maximum clock speed Low power, limited size processor, many dynamically variable clock speeds
Fans High speed, constant RPM fans Low speed, variable RPM fans
Graphics Always on, full power backlight Low power modes, variable backlight

Most of these power saving options are either ridiculously expensive (like solid state hard drives) or hard to change (such as laptop graphics cards). That means we have to reduce the power consumption of the computer through software.

How to Reduce Power Consumption

The Linux "tickless" Kernel Feature

Also called CONFIG_NO_HZ or Dynamic Ticks, this feature eliminates unnecessary timer ticks, resulting in lower CPU work, which in turn lowers power consumption and heat output. This feature has been available since the 2.6.21 kernel, and is usually enabled by default.

Intel PowerTOP

Intel makes an open source tool, called PowerTOP, which allows you to see which processes are forcing the computer to jump out of power save mode. It also gives recommendations for other ways to save power and will even automatically implement some of the suggested measures for you if you like. Ubuntu users can get PowerTOP from the apt repositories:

sudo apt-get install powertop

Run the tool as root for maximum benefit

sudo powertop

PowerTOP will cover most of the following topics automatically.

Eliminating Power Hungry Processes

Inefficient programs, like background file indexers or certain server processes, require your computer to come out of power save mode more often. Disable these programs to reduce power consumption.

PowerTOP will detect some such software, but others you'll have to use your brain for.

Hardware Settings

It's possible to configure certain pieces of physical hardware to minimize power consumption.

CD-ROM Auto Poll

The idea of this setting is to detect CDs or memory sticks being inserted or removed. We can shut off the auto-poll for all drives to save even more power. Keep in mind, this will affect any auto-mounting features that you have in place in your distribution.

PowerTOP detects this, and provides a simple method for you to turn off auto-poll.

Wireless Powersave Mode

Wireless transmission takes a huge amount of power. If you don't need as much power - for instance, you're just browsing the web - we can turn the power saving mode to maximum, causing the wireless card to go into a sleep state when not in use:

iwpriv eth1 set_power 5

Note that decreasing the transmission power of your wireless device will decrease the device's effectiveness. Try modes between 1 and 5 if you have problems - 1 for minimal power savings, 5 for maximum.
To undo this, set the power mode back to 6 (which is the same as mode 0):

iwpriv eth1 set_power 6



PowerTOP detects this, and provides a simple method for you to turn on power saving mode.

USB autosuspend

PowerTOP suggests this, I'm not sure exactly what it does yet:

usbcore.autosuspend=1

apparently, it doesn't work in Ubuntu anyway

Automated Actions

File Access Time Update

Whenever a file is accessed, Linux performs a write to disk to update the access time. (Note that there is a disk write even if the file is already cached in memory.) Shutting off this feature, commonly referred to as atime, reduces disk activity, which decreases power consumption and increases system performance.[1]

There are a few different ways to disable the access time update. First, we can shut it off for individual files:

sudo chattr +A <filename>

or for whole directories (recursively):

sudo chattr -R +A <directory>

We can also shut it off for an entire mount point at boot time by changing /etc/fstab entries that look like this:

/dev/sda1       /      ext3    defaults,errors=remount-ro       0 1

into this:

/dev/sda1       /      ext3    defaults,noatime,errors=remount-ro       0 1

We can make the same change by doing a live remount, like this: (note that this change will not affect subsequent system reboots)

sudo mount -o noatime,remount,rw /dev/sda1

It's all well and good that we can shut off atime, but what does that break? Many mail tools compare the last write time with the last access time to decide if mail has been read. Many backup software packages depend on access times to make sure things get backed up properly.

There's a slightly different way to deal with access time updates, which addresses some of these concerns. It's called relatime and it's available since kernel version 2.6.20. Using the relatime option in place of the noatime option causes access times to be updated only if the current access time is before or at the same time as the last write time.

PowerTOP detects this. The PowerTOP recommended method to address this is the live remount.

Virtual Memory Dirty Write Rate

Increase the VM dirty writeback time to 15 seconds with:

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

This wakes the disk up less frequenty for background VM activity. I'm not sure hoe effective it is, or if this method works in Ubuntu, or if this method is permenant. [2]

PowerTOP detects this, and suggests this procedure.

Laptop-Mode

Laptop-mode allows you to switch your laptop in and out of power-saving mode automatically when power is disconnected or connected. Need to figure out how to configure it.[3]

/etc/laptop-mode/

major configuration bug with laptop-mode relating to hard drives

References

  1. http://lwn.net/Articles/244829/
  2. http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#1239
  3. http://www.mjmwired.net/kernel/Documentation/laptop-mode.txt