summaryrefslogtreecommitdiff
path: root/pm/power.d/readahead
blob: 2009c843fdd6f3533edfa7fbff129a072c76e3c3 (plain)
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
#!/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
	/sbin/blockdev --setfra $1 "$dev"
    done
}

case $1 in
    true) readahead "$DRIVE_READAHEAD_BAT" ;;
    false) readahead "$DRIVE_READAHEAD_AC" ;;
    help) help;;
    *) exit $NA ;;
esac

exit 0