Minimizing Power Consumption in Linux

From JimboWiki
Revision as of 20:30, 20 June 2008 by J (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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


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.

CPU Speed Adjustment

To get manual control of your CPU speed, do this:

sudo chmod +s /usr/bin/cpufreq-selector

and add the CPU Frequency Scaling Monitor to your Gnome panel. One click on this applet will allow you to adjust your speed governor or set a specific manual speed. Lower speeds means less power.

The terminal solution to this problem is a bit more complex - I'll detail that at a later date.

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/program launching features that you have in place in your distribution.

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

To undo:

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


j@jimbocomp:~$ sudo hal-disable-polling --device /dev/scd0
Polling for drive /dev/scd0 have been disabled. The fdi file written was
j@jimbocomp:~$ sudo hal-disable-polling --device /dev/scd0 --enable-polling
Polling for drive /dev/scd0 have been enabled. The fdi file deleted was

PowerTOP detects this, and provides a shortcut key 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 0 (which is the same as mode 6):

iwpriv eth1 set_power 0

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:


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, officially called "laptop-mode-tools", allows you to switch your kernel in and out of power-saving mode automatically when power is disconnected or connected. The basic functionality is to spin down the hard drive when it's not in use, but it's also able to automatically enable/disable software services. Laptop-mode is disabled by default in Ubuntu.
Now, there is a major configuration bug in laptop-mode which might cause you some headaches in the form of failed hardware. Read up on it before you go further.

How to make it work

Enable in: /etc/default/acpi-support Runs in: /etc/acpi/

Need to figure out how to configure it.[3]