-
Notifications
You must be signed in to change notification settings - Fork 3
/
snapshot-balance.sh
66 lines (56 loc) · 1.12 KB
/
snapshot-balance.sh
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
#!/bin/bash
COMPILEBENCH=/root/compilebench-0.6/
DEV=/dev/nvme1n1
MNT=/mnt/test
SNAP_INTERVAL=1
NUM_SNAPS=10
_fail() {
echo $1
exit 1
}
_snap_thread() {
local i=0
local del=0
local DEL_MOD=$(( NUM_SNAPS * 2 ))
local DEL_SNAPS=$NUM_SNAPS
while [ 1 ]
do
sleep $SNAP_INTERVAL
btrfs sub snap $MNT $MNT/snaps/snap$i > /dev/null || \
_fail "failed to create snap$i"
i=$(( i + 1 ))
if [ "$(( i % DEL_MOD))" -eq "0" ]
then
for c in $(seq 1 $DEL_SNAPS)
do
btrfs subvolume delete $MNT/snaps/snap$del || \
_fail "failed to delete snap$del"
del=$((del + 1 ))
done
btrfs balance start --full-balance --bg $MNT
DEL_SNAPS=20
fi
done
}
_balance_thread() {
while [ 1 ]
do
sleep $SNAP_INTERVAL
btrfs balance start --full-balance $MNT || \
_fail "failed to balance"
done
}
mkfs.btrfs -f -n 4096 $DEV || _fail "couldn't mkfs"
mount $DEV $MNT || _fail "couldn't mount"
mkdir $MNT/snaps
_snap_thread &
SNAP_PID=$!
cd $COMPILEBENCH
for i in $(seq 0 100)
do
./compilebench -i 300 -m -D $MNT || break
done
[ "$?" -ne "0"] && echo "compilebench failed"
btrfs balance cancel $MNT
kill -9 $SNAP_PID
wait