tratto da
Höhere Akkulaufzeiten durch Festplattenshutdown di
Marc Schiffbauer
1. Il problema 2. Lo script per abilitare il laptop mode 3. Configurazione ACPI 4. noflushd
Spesso qualcuno gradirebbe che gli hard disc (non rimovibili) del proprio sistema andassero in standby, se il PC non fa nulla. Anche se si bloccano gli HD (per esempio con hdparm y/dev/hda ), questi riprendono le loro attività dopo pochi secondi. Anche l'utilizzo di un Demone, per esempio noflushd, che deve spegne l'HD dopo un certo idletime, non risolve ottimamente il problema in quanto avvengono ugualmente piccole attività sul disco.
Causa di questo sono i processi utente, che causano I/O sui dischi, e/o l'uso di un filesystem journaled (per esempio ext3 o reiserfs). Ed ci sono anche alcuni demoni come quello per l'aggiornamento del kernel(kupdated) che ogni cinque secondi sulla scrive sul disco.
Tutto questi "Flush" possono essere raggruppati in modo tale che sia ottimizzato il tempo di pausa degli HD.
La
laptop_mode Patch di Jens Axboe, che è contenuta nel Kernel a partire dalla versione 2.4.23, causes additionally still that, as soon as the plate raises times all "Dirty is written buffers" sui dischi. Linux non solo scrive i "Dirty buffers", di cui ha già calcolto il tempo di scadenza (expired), ma tutti, per concentrare le scritture sul disco.
My system: Debian Sid with own Kernel 2,4,25, ACPI Daemon (acpid) and disk shutdown Daemon (noflushd).
The following script I assembled myself and still supplemented from the
Doku to the laptop Patch and the
adjustment at ext3. Also little adjustment for the VM Tuning a parameter should function it also with Kernel 2,6 (guarda
questo thread per maggiori dettagli).
For me the additional mount option noatime was important . Without these the whole play had not brought much with me. This script best into a file /a usr/local/sbin/laptop_mode stores ( chmod 755/usr/local/sbin/laptop_mode does not forget!)
Script: laptop_mode
#!/bin/sh
# start or stop laptop mode, best run by a power management daemon when
# ac gets connected/disconnected from a laptop
#
# FIXME: assumes HZ == 100
# age time, in seconds. should be put into a sysconfig file
MAX_AGE=600
# kernel default dirty buffer age
DEF_AGE=30
DEF_UPDATE=5
if [ ! -w /proc/sys/vm/laptop_mode ]; then
echo "Kernel is not patched with laptop_mode patch"
exit 1
fi
parse_mount_opts () {
OPT="$1"
shift
echo "$*" |
sed 's/.*/,&,/' |
sed 's/,'"$OPT"'=[0-9]*,/,/g' |
sed 's/,,*/,/g' |
sed 's/^,//' |
sed 's/,$//' |
cat -
}
case "$1" in
stop)
# Now on AC power.
U_AGE=$((100*$DEF_UPDATE))
B_AGE=$((100*$DEF_AGE))
echo -n "Stopping laptop mode"
echo "0" > /proc/sys/vm/laptop_mode
echo "30 500 0 0 $U_AGE $B_AGE 60 20 0" > /proc/sys/vm/bdflush
cat /etc/mtab |
while read DEV MP FST OPTS DUMP PASS ; do
case "$FST" in
"ext3")
PARSEDOPTS="$(parse_mount_opts commit $OPTS)"
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$DEF_UPDATE
;;
"reiserfs")
PARSEDOPTS="$(parse_mount_opts transaction $OPTS)"
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,transaction=$DEF_UPDATE
;;
# No need to do anything for xfs
esac
done
echo "."
;;
start)
# Now off AC power.
AGE=$((100*$MAX_AGE))
echo -n "Starting laptop mode"
echo "1" > /proc/sys/vm/laptop_mode
echo "30 500 0 0 $AGE $AGE 60 20 0" > /proc/sys/vm/bdflush
cat /etc/mtab |
while read DEV MP FST OPTS DUMP PASS ; do
case "$FST" in
"ext3")
PARSEDOPTS="$(parse_mount_opts commit $OPTS)"
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_AGE,noatime
;;
"reiserfs")
PARSEDOPTS="$(parse_mount_opts transaction $OPTS)"
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,transaction=$MAX_AGE,noatime
;;
# No need to do anything for xfs
esac
done
echo "."
;;
*)
echo "Syntax: $(basename $0) "
;;
esac
exit 0
So that the laptop mode is activated automatically or deactivated depending upon current supply, I configured accordingly acpid. In addition one installs oneself for two further files:
# /etc/acpid/events/ac
# This detects changes to AC power status, and passes them to
# /etc/acpi/ac.sh for further processing.
# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.
event=ac_adapter
action=/etc/acpi/ac.sh
and:
#!/bin/sh
# /etc/acpid/ac.sh
# Detect loss of AC power and regaining of AC power, and take action
# appropriatly.
# On my laptop anyway, this script doesn't not get different parameters for
# loss of power and regained power. So, I have to use a separate program to
# tell what the adapter status is.
if on_ac_power; then
# Now on AC power.
/usr/local/sbin/laptop_mode stop
else
# Now off AC power.
/usr/local/sbin/laptop_mode start
fi
exit 0
(chmod 755 not forgotten) and starts acpid again ( /etc/init.d/acpid restart ).
If the plate raises still often again, there also any processes can be in the system to it debt which plate I/O cause. With the following small script one can come such processes on the schliche. It is important that klogd and syslogd are stopped before. The instructions in addition can vary depending upon distribution. This script functions under Debian. Please with caution use.
#!/bin/sh
#
trap clean_exit 1 2 3 6 15
clean_exit () {
echo 0 > /proc/sys/vm/block_dump
/etc/init.d/sysklogd start
echo "Adios"
exit 0
}
/etc/init.d/sysklogd stop
echo 1 > /proc/sys/vm/block_dump
while true; do
clear
date
dmesg | tail -n20
sleep 1
done
About the fact that the plate is also driven down after a certain time, worries noflushd. noflushd can be used to let the plates switch off after a bstimmten Idle time. It is configured under Debian over the file /etc/default/noflushd . Here one should adapt accordingly the variables "TIMEOUT" and "DISKS" to its desires and its system.
Notes: With these attitudes the plate remains maximally ten minutes out (600 seconds). This value can be adapted in laptop_mode script (MAX_AGE variable).
Note: In the worst case the last ten minutes at work can so also naturally be lost, if "Dirty Buffers" were not written on the plate and then the Akku the spirit give up suddenly unexpectedly. laptop_mode stop and sync the command are briefly before so an event good friends; -)
--
Copyright (C) Marc Schiffbauer
Appeared on
Pro-Linux, last change 2004-05-15
lib/WikiUser.php:59: Notice[8]: Only variables should be assigned by reference
lib/Template.php:112: Notice[8]: Only variables should be assigned by reference
lib/Template.php:114: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):112: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):114: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):112: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):114: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):112: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):114: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'top') (In template 'body') (In template 'html'):112: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'top') (In template 'body') (In template 'html'):114: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):112: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):114: Notice[8]: Only variables should be assigned by reference
lib/CachedMarkup.php (In template 'browse') (In template 'body') (In template 'html'):427: Notice[8]: Only variables should be assigned by reference