summaryrefslogtreecommitdiff
path: root/src/edit-firefox@
blob: e190ffc92f17b137aea5e9be7d8571046375d958 (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
#!/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; }

# uses $DIR
measure_write_speed()
{
    if [ "$FORCE" -o ! -e "$1" ]
    then
        mkdir -p "$(dirname "$1")"
        sync
        begin=$(date +%s%N)
        count=500
        dd if=/dev/urandom of="$DIR"/urandom.out 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 "$DIR"/urandom.out
        printf "Sanity check: megabytes/second = %s\n" \
               "$(( bytes_per_second / 1000 / 1000 ))" >&2
        printf '%s\n' "$bytes_per_second" > "$1"
    fi
    cat "$1"
}

DIR=~/.mozilla
CONFDIR=$HOME/.config/firestart

if [ -e "$CONFDIR"/conf ]
then
    . "$CONFDIR"/conf
fi

disk_write_speed=$(measure_write_speed "$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