3. Power Management Methods

The basic goal of any power management technique is to reduce an entity's consumption. In the case of laptop power management, our focus is on decreasing CPU and hard drive usage. To make things a bit simpler, this is broken down into obvious, semi-obvious, and non-obvious techniques. Granted, your mileage may vary.

3.1. swsusp(8)

Suspend to Disk (S2D) is still an elusive task under Linux. The main project at the moment is swsusp, available at http://sourceforge.net/projects/swsusp. It's still fairly new and requires a bit of configuration to enable it.

3.2. hdparm(8)

hdparm is a Linux shell utility that can be used to spin down and improve the performance of various ATA/IDE drives. If it's not included with your system, you can fetch the source from http://freshmeat.net/redir/hdparm/4062/url_homepage/hardware. For example, the following provides 32-bit IO support with sync (-c3), DMA support (-d1), Advanced Power Management (-B128), write-caching (-W1), disk spin down after five minutes (-S60). gains me tremendous performance with added power savings. Note that your mileage may vary, and you'll want to adjust this for your specific system to prevent data loss (especially the -B and -m flags!).

In the following example, we run some read/write benchmarks of our hard drive before and after using hdparm. Note that while our cache reads remain about the same, our actual physical reads from the drive increase tremendously! If you like living on the edge, you can play with the -m, -c, -B, and -u switches with caution (see the man page).

bash# hdparm -tT /dev/hda
Timing buffer-cache reads:   588 MB in  2.01 seconds = 292.15 MB/sec
Timing buffered disk reads:   14 MB in  3.46 seconds =   4.05 MB/sec

bash# hdparm -k1 -K1 -c3 -d1 -W1 /dev/hda
bash# hdparm -tT /dev/hda
Timing buffer-cache reads:   596 MB in  2.01 seconds = 297.01 MB/sec
Timing buffered disk reads:   72 MB in  3.05 seconds =  23.58 MB/sec

3.3. sysklogd(8)

Examine your /etc/syslog.conf file for unnecessary logging activity and to optimize its performance. If you don't want to log any system activity, consider disabling syslogd and klogd entirely or, at the very least, minimize the amount of logging your system performs. You can also prefix each entry with the minus sign (-) to omit syncing the file after each log entry [1]. For example, this will log anything with a priority of info or higher, but lower than warning, to /var/log/messages or /var/log/mail without needing to sync to disk after each write. Since we want to keep all messages with a priority of warning, this will be logged to a different file without disabling disk syncing (to prevent data loss in the event of a system crash).

*.warning			/var/log/syslog
*.info;*.!warning;mail.none	-/var/log/messages
mail.info;mail.!warning		-/var/log/mail

Another item to be aware of is the -- MARK -- messages that syslogd(8) writes. This will affect your hard drive inactivity settings. You can simply disable this by running syslogd(8) with:

if [ -x /usr/sbin/syslogd -a -x /usr/sbin/klogd ]; then
	# '-m 0' disabled 'MARK' messages
	/usr/sbin/syslogd -m 0
	sleep 1
	# '-c 3' displays errors on console
	# '-x' turns off broken EIP translation
	/usr/sbin/klogd -c 3 -x

3.4. XFree86

There are essentially two different types of screen blanking that can be performed under XFree86: BlankTime and DPMS. The first is simply a fake "blanking" effect that doesn't actually save any power. The others are specific only to DPMS-compliant monitors, and must be specifically enabled to take effect. They are located in your XF86Config file, which normally resides in /etc/X11/XF86Config.

If you have a DPMS-compliant monitor, you might want to try enabling support for it under the Monitor section of your XF86Config file:

Section "Monitor"
	Option	"DPMS"

To manipulate the DPMS functions, you can create/modify the following items in the ServerLayout section.

Section "ServerLayout"
	Option "BlankTime"	"10"	# Blank the screen in 10 minutes
	Option "StandbyTime" 	"20"	# Turn off screen in 20 minutes
	Option "SuspendTime"	"30"	# Full hibernation in 30 minutes
	Option "OffTime"	"40"	# Turn off DPMS monitor

It's worth noting that BlankTime is not actually a power saving level at all. The screen is sent a "fake" blanking effect and defaults to activate after 10 minutes. Alternately, it can indicate the number of minutes until the screensaver should activate. It has nothing to do with DPMS.

After activating your changes and restarting X-Windows, you might want to examine your logfile to see if your video card has any problems with your changes:

bash$ egrep "^\(WW|EE\)" /var/log/XFree86.0.log

There may be additional options that you can enable for your specific video card/chip driver; see the XFree86 Documentation website for specifics.

Of course, all of this can also be activated "on-the-fly" by using xset(1). If you don't have access to your system's XF86Config file, a good place to put these commands would be in your ~/.Xsession or ~/.xinitrc file.

bash$ xset -dpms			# Disable DPMS
bash$ xset +dpms			# Enable DPMS
bash$ xset s off			# Disable screen blanking
bash$ xset s 150			# Blank the screen after 150 seconds
bash$ xset dpms 300 600 900		# Set standby, suspend, & off times (in seconds)
bash$ xset dpms force standby		# Immediately go into standby mode
bash$ xset dpms force suspend		# Immediately go into suspend mode
bash$ xset dpms force off		# Immediately turn off the monitor
bash$ xset -q				# Query current settings

If instead you're using the Linux console (not X-Windows), you'll want to use setterm(1):

bash$ setterm -blank 10			# Blank the screen in 10 minutes
bash$ setterm -powersave on		# Put the monitor into VESA power saving mode
bash$ setterm -powerdown 20		# Set the VESA powerdown to 20 minutes

3.5. KDE 3.1

3.5.1. Display Power Control

Assuming you've configured XFree86 to support DPMS, simply run kcontrol and choose Power Control/Display Power Control. From here, you can configure Standby, Suspend, and Power off settings for your monitor.

3.5.2. Laptop Battery

Assuming you've configured your kernel to support either APM or ACPI, simply run kcontrol and choose Power Control/Laptop Battery. From here, you can configure the various settings for your system based on the level of battery power remaining.

It's worth noting that some people running ACPI tend to see the following message:

Your computer seems to have a partial ACPI installation. ACPI was probably 
enabled, but some of the sub-options were not - you need to enable at least 
'AC Adaptor' and 'Control Method Battery' and then rebuild your kernel.

If you see this, either ACPI is not installed or, more likely, KDE does not recognize your particular Linux ACPI Subsystem. If patching the kernel with any ACPI updates does not resolve this, you must either not use this KDE function or, alternately, revert back to using APM.

3.6. Energy Star

Energy Star is a United States government-backed program to promote energy efficiency standards. Of interest:

Typically, Energy Star savings is accomplished by other power management settings and is not, in and of itself, a power management technique.

3.7. Swap File

Consider disabling your swap file in /etc/fstab to reduce hard drive access. If you've got lots of memory, this is definitely the way to go. One way to tell if you need your swap file is to enable it, use your system for a period of time, and examine /proc/meminfo and /proc/swaps to determine how much free memory you've got on average, and whether or not your swap file is even being utilized.

For example, today I've compiled several intensive programs and have been running my laptop for about eight hours straight. A simple examination of my system reveals:

bash$ cat /proc/swaps
Filename                                Type            Size    Used    
/dev/hda3                                partition      136544  0       -1

bash$ cat /proc/meminfo
MemTotal:       513880 kB
MemFree:        254820 kB
Buffers:         42812 kB
Cached:         142880 kB
SwapCached:          0 kB
Active:         159644 kB
Inactive:        76888 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       513880 kB
LowFree:        254820 kB
SwapTotal:      136544 kB
SwapFree:       136544 kB
Dirty:               0 kB
Writeback:           0 kB
Mapped:          86148 kB
Slab:            10748 kB
Committed_AS:   203944 kB
PageTables:       1140 kB
VmallocTotal:   516076 kB
VmallocUsed:      1468 kB
VmallocChunk:   514604 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     4096 kB

Given this, I'd opt to disable my swapfile if this is any indicator of my future usage.

3.8. tmpfs

Compile your kernel with tmpfs (temporary file system) enabled and mount your /tmp directory using it. The useful bit here is that nothing will be written to your hard drive on this mount point as it will act like a RAM disk (however nothing will be saved either). The advantage of tmpfs over the more traditional ramfs is that it lives in the kernel internal cache and grows and shrinks to accommodate the files placed there. See your kernel's Documentation/filesystems/tmpfs.txt for full information. If you don't specify a maximum size, it will default to a ceiling limit of half your available memory. An example /etc/fstab with 100MB temporary ram file mounted on /tmp would look like:
tmpfs	/tmp	tmpfs	size=100m,mode=1777	0 0

3.9. Miscellaneous Tuning

Modifying /proc/sys/vm/bdflush allows a user to specify under what circumstances dirty buffers are flushed to disk, how many such buffers exist, etc. Details are in linux_src_tree/Documentation/sysctl/vm.txt (thanks to Marc Liberatore for pointing this out).

Boot your system and list the currently loaded modules with lsmod. Anything listed here most likely needs to be loaded on a regular basis; compiling these in as part of your kernel rather than as loadable modules may help to decrease the amount of time they must be loaded from disk, and to a very minor degree, decrease the amount of disk access required to start your system.

Examine your crontab settings to see if anything is being run on a regular basis. Comment out any unnecessary items. Don't forget to examine every user's crontab, including the user 'nobody'. If you don't need to schedule any background activity, consider disabling crond alltogether. The same advice goes for atd.

If you run httpd to test and/or develop web pages, try altering the values of MinSpareServers and StartServers to 1. Don't define any CustomLogging or at least increase the value of LogLevel to warn. If you're really sure of yourself, you can change the ErrorLog directive to point to /dev/null.

Consider creating a power-saving script that will immediately take your laptop into low-power mode:

if [ -x /usr/sbin/hdparm ]; then
	hdparm -y /dev/hda

if [ -x /usr/X11R6/bin/xset ]; then
	xset dpms force off

Additionally, it's worth considering anything in the following areas:

3.10. Power Saving Myths

It used to be beneficial to recompile the Linux PCMCIA drivers to allow the slots to have APM power support. However, most of the functionality of these drivers are now built into the kernel itself. If you're interested in specifics, the PCMCIA project page is available at http://sourceforge.net/projects/pcmcia-cs/.

Some people believe that APM offers better power savings over ACPI, and vice-versa. While their power management techniques differ, in actual battery-usage tests, both reportedly perform about the same.

Contrary to popular belief, Lithium Ion (see below) batteries do suffer from a memory effect. Luckily, the effect is not large over the lifespan of a typical battery (3-4 years). Anyone who tells you different is selling something.




Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:58:07