-
Notifications
You must be signed in to change notification settings - Fork 3
/
zram-fio-test.sh
executable file
·178 lines (137 loc) · 3.29 KB
/
zram-fio-test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
# Sergey Senozhatsky. sergey.senozhatsky@gmail.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Example:
#
# ZRAM_SIZE=2G ZRAM_COMP_ALG=lz4 LOG_SUFFIX=NEW MEM_HOGGER_SIZE=1G FIO_LOOPS=1 FIO_TEST=compbuf ./zram-fio-test.sh
#
LOG=/tmp/test-fio-zram
MEM_HOGGER_PID=0
EXT_LOG=0
PERF="perf"
FIO="fio"
function reset_zram
{
echo 1 > /sys/block/zram0/reset
rmmod zram
rmmod zsmalloc
}
function create_zram
{
modprobe zram
echo "$ZRAM_COMP_ALG" > /sys/block/zram0/comp_algorithm
cat /sys/block/zram0/comp_algorithm
echo "$ZRAM_SIZE" > /sys/block/zram0/disksize
if [ $? != 0 ]; then
return 1
fi
# don't mkfs/mount the device
return 0
}
function start_single_alloc
{
touch ./.single_alloc_init
./bin/bin-mem-hogger -m "$MEM_HOGGER_SIZE" -l ./.single_alloc_init&
MEM_HOGGER_PID=$!
while [ -e ./.single_alloc_init ]; do
echo "Waiting for single-alloc"
sleep 1s;
done
}
function exec_mem_hogger
{
if [ "z$MEM_HOGGER_SIZE" != "z" ]; then
start_single_alloc
fi
}
function signal_mem_hogger
{
if [ "z$MEM_HOGGER_SIZE" != "z" ]; then
kill -USR1 $MEM_HOGGER_PID
sleep 2s
fi
}
function kill_mem_hogger
{
if [ "z$MEM_HOGGER_SIZE" != "z" ]; then
kill -TERM $MEM_HOGGER_PID
fi
}
function main
{
local i
if [ "z$LOG_SUFFIX" == "z" ]; then
LOG_SUFFIX="UNSET"
fi
LOG=$LOG-$LOG_SUFFIX
if [ "z$MEM_HOGGER_SIZE" != "z" ]; then
EXT_LOG=1
fi
if [ "z$EXTENDED_LOG" != "z" ]; then
EXT_LOG=1
fi
if [ "z$ZRAM_SIZE" == "z" ]; then
ZRAM_SIZE=3G
fi
if [ "z$MAX_ITER" == "z" ]; then
MAX_ITER=10
fi
if [ "z$FIO_LOOPS" == "z" ]; then
FIO_LOOPS=1
fi
if [ "z$ZRAM_COMP_ALG" == "z" ]; then
ZRAM_COMP_ALG=lzo
fi
FIO_TEMPLATE=./conf/fio-template-static-buffer
if [ "z$FIO_TEST" == "zcompbuf" ]; then
FIO_TEMPLATE=./conf/fio-template-compressed-buffer
fi
echo "Using $FIO_TEMPLATE fio template"
for i in $(seq $MAX_ITER); do
echo "$i"
reset_zram
create_zram
if [ $? != 0 ]; then
echo "Unable to create zram device"
exit 1
fi
exec_mem_hogger
echo "#jobs$i fio"
echo "#jobs$i fio" >> $LOG
DISK_SIZE=$(cat /sys/block/zram0/disksize)
_NRFILES=$(($DISK_SIZE/(512 * 1024)))
echo "#files $_NRFILES"
## BLOCK_SIZE=4 SIZE=100% NUMJOBS=$i NRFILES=$_NRFILES FIO_LOOPS=$FIO_LOOPS \
BLOCK_SIZE=4 SIZE=100% NUMJOBS=$i NRFILES=$i FIO_LOOPS=$FIO_LOOPS \
$PERF stat -o $LOG-perf-stat $FIO ./$FIO_TEMPLATE >> $LOG
echo -n "perfstat jobs$i" >> $LOG
cat $LOG-perf-stat >> $LOG
cat /sys/block/zram0/debug_stat
if [ $EXT_LOG -eq 1 ]; then
echo -n "mm_stat (jobs$i): " >> $LOG-mm_stat
cat /sys/block/zram0/mm_stat >> $LOG-mm_stat
echo "buddyinfo (jobs$i): " >> $LOG-buddyinfo
cat /proc/buddyinfo >> $LOG-buddyinfo
fi
kill_mem_hogger
done
rm $LOG-perf-stat
echo -n "Log files created: $LOG "
if [ $EXT_LOG -eq 1 ]; then
echo -n " $LOG-mm_stat"
echo -n " $LOG-buddyinfo"
fi
echo
reset_zram
}
main