blob: 4bd7e350df1dbaa657f08471c5f7b60679d25178 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/bin/bash
if [ "$1" = -f ]
then
FORCE=y
shift
fi
if [ $# = 0 ]
then
TARGET=/dev/stderr
else
TARGET=$1
fi
die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }
measure_write_speed()
{
MEASURE_PATH=$1/urandom.out
CACHED_RESULT=$2
if [ "$FORCE" -o ! -e "$CACHED_RESULT" ]
then
mkdir -p "$(dirname "$CACHED_RESULT")"
sync
begin=$(date +%s%N)
count=500
dd if=/dev/urandom of="$MEASURE_PATH" bs=1M count=$count conv=fdatasync
end=$(date +%s%N)
nanosecs=$(( end - begin ))
millisecs=$(( nanosecs / 1000 / 1000 ))
bytes=$(( count * 1000 * 1000 ))
bytes_per_second=$(( 1000 * bytes / millisecs ))
rm "$MEASURE_PATH"
printf "Sanity check: megabytes/second = %s\n" \
"$(( bytes_per_second / 1000 / 1000 ))" >&2
printf '%s\n' "$bytes_per_second" > "$CACHED_RESULT"
fi
cat "$CACHED_RESULT"
}
DIR=~/.mozilla
CONFDIR=$HOME/.config/firestart
if [ -e "$CONFDIR"/conf ]
then
. "$CONFDIR"/conf
fi
disk_write_speed=$(measure_write_speed "$DIR" "$CONFDIR"/diskspeed.dat)
WRITE_OPS=$(( disk_write_speed / 2 ))
READ_OPS=$WRITE_OPS
[ -e "$DIR" ] || die "does not exist: $DIR"
[ -d "$DIR" ] || die "not a directory: $DIR"
DEV=$(echo $(findmnt --target "$DIR" -o MAJ:MIN -n))
[ "$DEV" ] || die "could not determine backing device for $DIR"
cat > "$TARGET" <<END
[Service]
IOReadIOPSMax = $DEV $READ_OPS
IOWriteIOPSMax = $DEV $WRITE_OPS
END
|