Commit 015af2dd authored by Bart Samwel's avatar Bart Samwel Committed by Linus Torvalds

[PATCH] Add documentation about /proc/sys/vm/laptop_mode to various docs.

From: Bart Samwel <bart@samwel.tk>

A bunch of small laptop mode updates:

* Mention the laptop_mode and block_dump sysctls in the relevant docs,
  referring to the laptop-mode.txt. Improve description of what the
  laptop_mode knob means (i.e. seconds between last I/O and automatic
  sync).

* Document the most relevant config file options.

* Change the installation instructions in the laptop mode doc to describe
  the ACPI-bound version first, because this is the easiest. Explain
  the non-ACPI version afterwards. Added a reference to my "packaged
  version" of the scripts.

* Move the setting of hdparm and cpu frequency out of the ACPI script
  and into the core laptop mode script. Add config option DO_HD to
  enable hdparm. Add config setting HD to set device to do hdparm on.
  Rename Dax's CPU_MANAGE to DO_CPU, with 0/1 instead of yes/no, to
  improve consistency.

* Fix a problem where the root filesystem wouln't be remounted when
  /etc/mtab listed its type as "unknown". Deduce the type of "unknown"
  filesystems from /etc/fstab.

This depends on the patch that adds config files, which was submitted
to Linus by Dax Kelson on July 10.
Signed-off-by: default avatarBart Samwel <bart@samwel.tk>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent db581879
......@@ -1232,6 +1232,18 @@ nr_hugepages configures number of hugetlb page reserved for the system.
hugetlb_shm_group contains group id that is allowed to create SysV shared
memory segment using hugetlb page.
laptop_mode
-----------
laptop_mode is a knob that controls "laptop mode". All the things that are
controlled by this knob are discussed in Documentation/laptop-mode.txt.
block_dump
----------
block_dump enables block I/O debugging when set to a nonzero value. More
information on block I/O debugging is in Documentation/laptop-mode.txt.
2.5 /proc/sys/dev - Device specific parameters
----------------------------------------------
......
......@@ -8,7 +8,7 @@ Last modified: July 10, 2004
Introduction
------------
Laptopmode is used to minimize the time that the hard disk needs to be spun up,
Laptop mode is used to minimize the time that the hard disk needs to be spun up,
to conserve battery power on laptops. It has been reported to cause significant
power savings.
......@@ -16,33 +16,34 @@ Contents
--------
* Introduction
* The short story
* Installation
* Caveats
* The details
* The Details
* Tips & Tricks
* Control script
* ACPI integration
* Monitoring tool
The short story
---------------
Installation
------------
To use laptop mode, you don't need to set any kernel configuration options
or anything. You simply need to run the laptop_mode control script (which
is included in this document) as follows:
# laptop_mode start
or anything. Simply install all the files included in this document, and
laptop mode will automatically be started when you're on battery. For
your convenience, a tarball containing an installer can be downloaded at:
Then set your harddisk spindown time to a relatively low value with hdparm:
http://www.xs4all.nl/~bsamwel/laptop_mode/tools
hdparm -S 4 /dev/hda
To configure laptop mode, you need to edit the configuration file, which is
located in /etc/default/laptop-mode on Debian-based systems, or in
/etc/sysconfig/laptop-mode on other systems.
The value -S 4 means 20 seconds idle time before spindown. Your harddisk will
now only spin up when a disk cache miss occurs, or at least once every 10
minutes to write back any pending changes.
To stop laptop_mode, run "laptop_mode stop".
Unfortunately, automatic enabling of laptop mode does not work for
laptops that don't have ACPI. On those laptops, you need to start laptop
mode manually. To start laptop mode, run "laptop_mode start", and to
stop it, run "laptop_mode stop". (Note: The laptop mode tools package now
has experimental support for APM, you might want to try that first.)
Caveats
......@@ -52,10 +53,7 @@ Caveats
to 10 minutes of work. If you cannot afford this, don't use it! It's
wise to turn OFF laptop mode when you're almost out of battery --
although this will make the battery run out faster, at least you'll
lose less work when it actually runs out. I'm still looking for someone
to submit instructions on how to turn off laptop mode when battery is low,
e.g., using ACPI events. I don't have a laptop myself, so if you do and
you care to contribute such instructions, please do.
lose less work when it actually runs out.
* Most desktop hard drives have a very limited lifetime measured in spindown
cycles, typically about 50.000 times (it's usually listed on the spec sheet).
......@@ -69,23 +67,27 @@ Caveats
* If you have your filesystems listed as type "auto" in fstab, like I did, then
the control script will not recognize them as filesystems that need remounting.
You must list the filesystems with their true type instead.
* It has been reported that some versions of the mutt mail client use file access
times to determine whether a folder contains new mail. If you use mutt and
experience this, you must disable the noatime remounting in the control script
by setting DO_REMOUNT_NOATIME=0.
experience this, you must disable the noatime remounting by setting the option
DO_REMOUNT_NOATIME to 0 in the configuration file.
The details
The Details
-----------
Laptop-mode is controlled by the flag /proc/sys/vm/laptop_mode. This flag is
Laptop mode is controlled by the knob /proc/sys/vm/laptop_mode. This knob is
present for all kernels that have the laptop mode patch, regardless of any
configuration options. When the flag is set, any physical disk read operation
(that might have caused the hard disk to spin up) causes Linux to flush all dirty
blocks. The result of this is that after a disk has spun down, it will not be spun
up anymore to write dirty blocks, because those blocks had already been written
immediately after the most recent read operation.
configuration options. When the knob is set, any physical disk I/O (that might
have caused the hard disk to spin up) causes Linux to flush all dirty blocks. The
result of this is that after a disk has spun down, it will not be spun up
anymore to write dirty blocks, because those blocks had already been written
immediately after the most recent read operation. The value of the laptop_mode
knob determines the time between the occurrence of disk I/O and when the flush
is triggered. A sensible value for the knob is 5 seconds. Setting the knob to
0 disables laptop mode.
To increase the effectiveness of the laptop_mode strategy, the laptop_mode
control script increases dirty_expire_centisecs and dirty_writeback_centisecs in
......@@ -104,32 +106,97 @@ is set, Linux reports all disk read and write operations that take place, and
all block dirtyings done to files. This makes it possible to debug why a disk
needs to spin up, and to increase battery life even more. The output of
block_dump is written to the kernel output, and it can be retrieved using
"dmesg". When you use block_dump, you may want to turn off klogd, otherwise
"dmesg". When you use block_dump and your kernel logging level also includes
kernel debugging messages, you probably want to turn off klogd, otherwise
the output of block_dump will be logged, causing disk activity that is not
normally there.
If 10 minutes is too much or too little downtime for you, you can configure
this downtime as follows. In the control script, set the MAX_AGE value to the
maximum number of seconds of disk downtime that you would like. You should
then set your filesystem's commit interval to the same value. The dirty ratio
is also configurable from the control script.
If you don't like the idea of the control script remounting your filesystems
for you, you can change DO_REMOUNTS to 0 in the script.
Configuration
-------------
The laptop mode configuration file is located in /etc/default/laptop-mode on
Debian-based systems, or in /etc/sysconfig/laptop-mode on other systems. It
contains the following options:
MAX_AGE:
Maximum time, in seconds, of hard drive spindown time that you are
confortable with. Worst case, it's possible that you could lose this
amount of work if your battery fails while you're in laptop mode.
AC_HD/BATT_HD:
The idle timeout that should be set on your hard drive when laptop mode
is active (BATT_HD) and when it is not active (AC_HD). The defaults are
20 seconds (value 4) for BATT_HD and 2 hours (value 244) for AC_HD. The
possible values are those listed in the manual page for "hdparm" for the
"-S" option.
HD:
The devices for which the spindown timeout should be adjusted by laptop mode.
Default is /dev/hda. If you specify multiple devices, separate them by a space.
READAHEAD:
Disk readahead, in 512-byte sectors, while laptop mode is active. A large
readahead can prevent disk accesses for things like executable pages (which are
loaded on demand while the application executes) and sequentially accessed data
(MP3s).
DO_REMOUNTS:
The control script automatically remounts any mounted journaled filesystems
with approriate commit interval options. When this option is set to 0, this
feature is disabled.
DO_REMOUNT_NOATIME:
When remounting, should the filesystems be remounted with the noatime option?
Normally, this is set to "1" (enabled), but there may be programs that require
access time recording.
DIRTY_RATIO:
The percentage of memory that is allowed to contain "dirty" or unsaved data
before a writeback is forced, while laptop mode is active. Corresponds to
the /proc/sys/vm/dirty_ratio sysctl.
DIRTY_BACKGROUND_RATIO:
The percentage of memory that is allowed to contain "dirty" or unsaved data
after a forced writeback is done due to an exceeding of DIRTY_RATIO. Set
this nice and low. This corresponds to the /proc/sys/vm/dirty_background_ratio
sysctl.
Thanks to Kiko Piris, the control script can be used to enable laptop mode on
both the Linux 2.4 and 2.6 series.
Note that the behaviour of dirty_background_ratio is quite different
when laptop mode is active and when it isn't. When laptop mode is inactive,
dirty_background_ratio is the threshold percentage at which background writeouts
start taking place. When laptop mode is active, however, background writeouts
are disabled, and the dirty_background_ratio only determines how much writeback
is done when dirty_ratio is reached.
DO_CPU:
Enable CPU frequency scaling when in laptop mode. (Requires CPUFreq to be setup.
See Documentation/cpu-freq/user-guide.txt for more info. Disabled by default.)
CPU_MAXFREQ:
When on battery, what is the maximum CPU speed that the system should use? Legal
values are "slowest" for the slowest speed that your CPU is able to operate at,
or a value listed in /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies.
Tips & Tricks
-------------
* Bartek Kania reports getting up to 50 minutes of extra battery life (on top
of his regular 3 to 3.5 hours) using very aggressive power management (hdparm
-B1) and a spindown time of 5 seconds (hdparm -S1).
of his regular 3 to 3.5 hours) using a spindown time of 5 seconds (BATT_HD=1).
* You can spin down the disk while playing MP3, by setting the disk readahead
to 8MB (hdparm -a 16384). Effectively, the disk will read a complete MP3 at
* You can spin down the disk while playing MP3, by setting disk readahead
to 8MB (READAHEAD=16384). Effectively, the disk will read a complete MP3 at
once, and will then spin down while the MP3 is playing. (Thanks to Bartek
Kania.)
......@@ -138,18 +205,6 @@ Tips & Tricks
this on powerbooks too. I hope that this is a piece of information that
might be useful to the Laptop Mode patch or it's users."
* One thing which will cause disks to spin up is not-present application
and dynamic library text pages. The kernel will load program text off disk
on-demand, so each time you invoke an application feature for the first
time, the kernel needs to spin the disk up to go and fetch that part of the
application.
So it is useful to increase the disk readahead parameter greatly, so that
the kernel will pull all of the executable's pages into memory on the first
pagefault.
The supplied script does this.
* In syslog.conf, you can prefix entries with a dash ``-'' to omit syncing the
file after every logging. When you're using laptop-mode and your disk doesn't
spin down, this is a likely culprit.
......@@ -158,8 +213,15 @@ Tips & Tricks
(http://noflushd.sourceforge.net/), it seems that noflushd prevents laptop-mode
from doing its thing.
* If you're worried about your data, you might want to consider using a USB
memory stick or something like that as a "working area". (Be aware though
that flash memory can only handle a limited number of writes, and overuse
may wear out your memory stick pretty quickly. Do _not_ use journalling
filesystems on flash memory sticks.)
Configuration file for control and ACPI battery scripts
--------------
-------------------------------------------------------
This allows the tunables to be changed for the scripts via an external
configuration file
......@@ -171,24 +233,24 @@ It should be installed as /etc/default/laptop-mode on Debian, and as
# Maximum time, in seconds, of hard drive spindown time that you are
# confortable with. Worst case, it's possible that you could lose this
# amount of work if your battery fails you while in laptop mode.
MAX_AGE=600
#MAX_AGE=600
# Read-ahead, in kilobytes. You can spin down the disk while playing MP3/OGG, by
# setting the disk readahead to 8MB (READAHEAD=16384). Effectively, the disk
# Read-ahead, in 512-byte sectors. You can spin down the disk while playing MP3/OGG
# by setting the disk readahead to 8MB (READAHEAD=16384). Effectively, the disk
# will read a complete MP3 at once, and will then spin down while the MP3/OGG is
# playing.
READAHEAD=4096
#READAHEAD=4096
# Shall we remount journaled fs. with appropiate commit interval? (1=yes)
DO_REMOUNTS=1
#DO_REMOUNTS=1
# And shall we add the "noatime" option to that as well? (1=yes)
DO_REMOUNT_NOATIME=1
#DO_REMOUNT_NOATIME=1
# Dirty synchronous ratio. At this percentage of dirty pages the process
# which
# calls write() does its own writeback
DIRTY_RATIO=40
#DIRTY_RATIO=40
#
# Allowed dirty background ratio, in percent. Once DIRTY_RATIO has been
......@@ -196,49 +258,57 @@ DIRTY_RATIO=40
# of dirty memory to dirty_background_ratio. Set this nice and low, so once
# some writeout has commenced, we do a lot of it.
#
DIRTY_BACKGROUND_RATIO=5
#DIRTY_BACKGROUND_RATIO=5
# kernel default dirty buffer age
DEF_AGE=30
DEF_UPDATE=5
DEF_DIRTY_BACKGROUND_RATIO=10
DEF_DIRTY_RATIO=40
DEF_XFS_AGE_BUFFER=15
DEF_XFS_SYNC_INTERVAL=30
DEF_XFS_BUFD_INTERVAL=1
#DEF_AGE=30
#DEF_UPDATE=5
#DEF_DIRTY_BACKGROUND_RATIO=10
#DEF_DIRTY_RATIO=40
#DEF_XFS_AGE_BUFFER=15
#DEF_XFS_SYNC_INTERVAL=30
#DEF_XFS_BUFD_INTERVAL=1
# This must be adjusted manually to the value of HZ in the running kernel
# on 2.4, until the XFS people change their 2.4 external interfaces to work in
# centisecs. This can be automated, but it's a work in progress that still
# needs# some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for
# external
# interfaces, and that is currently always set to 100. So you don't need to
# change this on 2.6.
XFS_HZ=100
# external interfaces, and that is currently always set to 100. So you don't
# need to change this on 2.6.
#XFS_HZ=100
# Should the maximum CPU frequency be adjusted down while on battery?
# Requires CPUFreq to be setup.
# See Documentation/cpu-freq/user-guide.txt for more info
CPU_MANAGE=no
#DO_CPU=0
# When on battery what is the maximum CPU speed that the system should
# use? Legal values are "slowest" for the slowest speed that your
# CPU is able to operate at, or a value listed in:
# /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
# Only applicable if CPU_MANAGE=yes
CPU_MAXFREQ=slowest
# Only applicable if DO_CPU=1.
#CPU_MAXFREQ=slowest
# Idle timeout for your hard drive (man hdparm for valid values, -S option)
# Default is 2 hours on AC (AC_HD=244) and 20 seconds for battery (BATT_HD=4).
#AC_HD=244
#BATT_HD=4
# The drives for which to adjust the idle timeout. Separate them by a space,
# e.g. HD="/dev/hda /dev/hdb".
#HD="/dev/hda"
# Spindown time for your hard drive (man hdparm for valid values)
# I prefer 2 hours on AC and 20 seconds for battery
AC_HD=244
BATT_HD=4
# Set the spindown timeout on a hard drive?
#DO_HD=1
--------------------CONFIG FILE END---------------------------------------------
Control script
--------------
Please note that this control script works for the Linux 2.4 and 2.6 series.
Please note that this control script works for the Linux 2.4 and 2.6 series (thanks
to Kiko Piris).
--------------------CONTROL SCRIPT BEGIN----------------------------------------
#!/bin/bash
......@@ -285,10 +355,25 @@ DO_REMOUNTS=${DO_REMOUNTS:-'1'}
# And shall we add the "noatime" option to that as well? (1=yes)
DO_REMOUNT_NOATIME=${DO_REMOUNT_NOATIME:-'1'}
# Shall we adjust the idle timeout on a hard drive?
DO_HD=${DO_HD:-'1'}
# Adjust idle timeout on which hard drive?
HD="${HD:-'/dev/hda'}"
# spindown time for HD (hdparm -S values)
AC_HD=${AC_HD:-'244'}
BATT_HD=${BATT_HD:-'4'}
# Dirty synchronous ratio. At this percentage of dirty pages the process which
# calls write() does its own writeback
DIRTY_RATIO=${DIRTY_RATIO:-'40'}
# cpu frequency scaling
# See Documentation/cpu-freq/user-guide.txt for more info
DO_CPU=${CPU_MANAGE:-'0'}
CPU_MAXFREQ=${CPU_MAXFREQ:-'slowest'}
#
# Allowed dirty background ratio, in percent. Once DIRTY_RATIO has been
# exceeded, the kernel will wake pdflush which will then reduce the amount
......@@ -432,6 +517,20 @@ parse_mount_opts_wfstab () {
fi
}
deduce_fstype () {
MP="$1"
# My root filesystem unfortunately has
# type "unknown" in /etc/mtab. If we encounter
# "unknown", we try to get the type from fstab.
cat /etc/fstab |
grep -v '^#' |
while read FSTAB_DEV FSTAB_MP FSTAB_FST FSTAB_OPTS FSTAB_DUMP FSTAB_DUMP ; do
if [ "$FSTAB_MP" = "$MP" ]; then
echo $FSTAB_FST
exit 0
fi
done
}
if [ $DO_REMOUNT_NOATIME -eq 1 ] ; then
NOATIME_OPT=",noatime"
......@@ -485,6 +584,9 @@ case "$1" in
if [ $DO_REMOUNTS -eq 1 ]; then
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
PARSEDOPTS="$(parse_mount_opts "$OPTS")"
if [ "$FST" = 'unknown' ]; then
FST=$(deduce_fstype $MP)
fi
case "$FST" in
"ext3"|"reiserfs")
PARSEDOPTS="$(parse_mount_opts commit "$OPTS")"
......@@ -499,6 +601,18 @@ case "$1" in
fi
done
fi
if [ $DO_HD -eq 1 ] ; then
for THISHD in $HD ; do
/sbin/hdparm -S $BATT_HD $THISHD > /dev/null 2>&1
/sbin/hdparm -B 1 $THISHD > /dev/null 2>&1
done
fi
if [ $DO_CPU -eq 1 -a -e /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]; then
if [ $CPU_MAXFREQ = 'slowest' ]; then
CPU_MAXFREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
fi
echo $CPU_MAXFREQ > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi
echo "."
;;
stop)
......@@ -530,6 +644,9 @@ case "$1" in
if [ $DO_REMOUNTS -eq 1 ] ; then
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
# Reset commit and atime options to defaults.
if [ "$FST" = 'unknown' ]; then
FST=$(deduce_fstype $MP)
fi
case "$FST" in
"ext3"|"reiserfs")
PARSEDOPTS="$(parse_mount_opts_wfstab $DEV commit $OPTS)"
......@@ -546,6 +663,15 @@ case "$1" in
fi
done
fi
if [ $DO_HD -eq 1 ] ; then
for THISHD in $HD ; do
/sbin/hdparm -S $AC_HD $THISHD > /dev/null 2>&1
/sbin/hdparm -B 255 $THISHD > /dev/null 2>&1
done
fi
if [ $DO_CPU -eq 1 -a -e /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]; then
echo `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq` > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi
echo "."
;;
*)
......@@ -573,54 +699,19 @@ action=/etc/acpi/actions/battery.sh
----------------/etc/acpi/actions/battery.sh BEGIN------------------------------
#!/bin/bash
# Source config
if [ -f /etc/default/laptop-mode ] ; then
# Debian
. /etc/default/laptop-mode
elif [ -f /etc/sysconfig/laptop-mode ] ; then
# Others
. /etc/sysconfig/laptop-mode
fi
# Don't raise an error if the config file is incomplete
# set defaults instead:
# cpu frequency scaling
# See Documentation/cpu-freq/user-guide.txt for more info
CPU_MANAGE=${CPU_MANAGE:-'no'}
CPU_MAXFREQ=${CPU_MAXFREQ:-'slowest'}
# spindown time for HD (man hdparm for valid values)
# I prefer 2 hours on AC and 20 seconds for battery
AC_HD=244
BATT_HD=4
# ac/battery event handler
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state`
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/$2/state`
case $status in
"on-line")
echo "Setting HD spindown for AC mode."
echo "AC mode: disabling laptop mode."
/sbin/laptop_mode stop
/sbin/hdparm -S $AC_HD /dev/hda > /dev/null 2>&1
/sbin/hdparm -B 255 /dev/hda > /dev/null 2>&1
if [ $CPU_MANAGE = 'yes' ]; then
echo `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq` > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi
exit 0
;;
"off-line")
echo "Setting HD spindown for battery mode."
echo "Battery mode: enabling laptop mode."
/sbin/laptop_mode start
/sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1
/sbin/hdparm -B 1 /dev/hda > /dev/null 2>&1
if [ $CPU_MANAGE = 'yes' -a -e /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]; then
if [ $CPU_MAXFREQ = 'slowest' ]; then
CPU_MAXFREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
fi
echo $CPU_MAXFREQ > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
fi
exit 0
;;
esac
......
......@@ -24,11 +24,14 @@ Currently, these files are in /proc/sys/vm:
- dirty_writeback_centisecs
- max_map_count
- min_free_kbytes
- laptop_mode
- block_dump
==============================================================
dirty_ratio, dirty_background_ratio, dirty_expire_centisecs,
dirty_writeback_centisecs, vfs_cache_pressure:
dirty_writeback_centisecs, vfs_cache_pressure, laptop_mode,
block_dump:
See Documentation/filesystems/proc.txt
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment