1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!/bin/sh
[ -x /sbin/blockdev ] || exit $NA
# more readahead = (hopefully) less hard drive activity.
# less readahead = less trashing the page cache.
DRIVE_READAHEAD_AC=${DRIVE_READAHEAD_AC:-256}
DRIVE_READAHEAD_BAT=${DRIVE_READAHEAD_BAT:-3072}
help() {
cat <<EOF
--------
$0: Control drive readahead.
This hook tries to trade off the number of times we spin up a drive
to read for potentially wasted cache.
Drive readahead parameters:
DRIVE_READAHEAD_AC = Number of KB to speculatively read on AC.
Defaults to 256 KB.
DRIVE_READAHEAD_BAT = Number of KB to speculatively read on battery.
Defaults to 3072 KB.
EOF
}
readahead() {
# the intent here is to iterate through all filesystems
# mounted on a local block device. It Works For The Maintainer(tm).
# More sophistication in figuring out what exactly is a local block device
# would be welcome.
for dev in $(awk '/^\/dev\// {print $1}'</etc/mtab); do
printf "Setting readahead for %s to %d..." "$dev" "$1"
/sbin/blockdev --setfra $1 "$dev" && echo Done. || echo Failed.
done
}
case $1 in
true) readahead "$DRIVE_READAHEAD_BAT" ;;
false) readahead "$DRIVE_READAHEAD_AC" ;;
help) help;;
*) exit $NA ;;
esac
exit 0
|