Whamcloud - gitweb
LU-5241 tests: speed up sanity-lfsck and sanity-scrub tests
[fs/lustre-release.git] / lustre / tests / lfsck-performance.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 ALWAYS_EXCEPT="$LFSCK_PERFORMANCE_EXCEPT"
7 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
14 init_logging
15
16 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
17         skip "lfsck performance only for ldiskfs" && exit 0
18
19 require_dsh_mds || exit 0
20
21 [ "$SLOW" = "no" ] &&
22         skip "skip lfsck performance test under non-SLOW mode" && exit 0
23
24 NTHREADS=${NTHREADS:-0}
25 UNIT=${UNIT:-1048576}
26 MINCOUNT=${MINCOUNT:-8192}
27 MAXCOUNT=${MAXCOUNT:-32768}
28 MINCOUNT_REPAIR=${MINCOUNT_REPAIR:-8192}
29 MAXCOUNT_REPAIR=${MAXCOUNT_REPAIR:-32768}
30 BASE_COUNT=${BASE_COUNT:-1048576}
31 FACTOR=${FACTOR:-2}
32 INCFACTOR=${INCFACTOR:-25} #percent
33
34 RCMD="do_facet ${SINGLEMDS}"
35 RLCTL="${RCMD} ${LCTL}"
36 MDT_DEV="${FSNAME}-MDT0000"
37 MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
38 START_NAMESPACE="${RLCTL} lfsck_start -M ${MDT_DEV} -t namespace"
39 STOP_LFSCK="${RLCTL} lfsck_stop -M ${MDT_DEV}"
40 SHOW_NAMESPACE="${RLCTL} get_param -n mdd.${MDT_DEV}.lfsck_namespace"
41 MNTOPTS_NOSCRUB="-o user_xattr,noscrub"
42 remote_mds && ECHOCMD=${RCMD} || ECHOCMD="eval"
43
44 if [ ${NTHREADS} -eq 0 ]; then
45         CPUCORE=$(${RCMD} cat /proc/cpuinfo | grep "processor.*:" | wc -l)
46         NTHREADS=$((CPUCORE * 2))
47 fi
48
49 lfsck_attach() {
50         ${ECHOCMD} "${LCTL} <<-EOF
51                 attach echo_client lfsck-MDT0000 lfsck-MDT0000_UUID
52                 setup ${MDT_DEV} mdd
53         EOF"
54 }
55
56 lfsck_detach() {
57         ${ECHOCMD} "${LCTL} <<-EOF
58                 device lfsck-MDT0000
59                 cleanup
60                 detach
61         EOF"
62 }
63
64 lfsck_create() {
65         local echodev=$(${RLCTL} dl | grep echo_client|awk '{print $1}')
66         local j
67
68         ${ECHOCMD} "${LCTL} <<-EOF
69                 cfg_device ${echodev}
70                 test_mkdir ${tdir}
71         EOF"
72
73         for ((j = 1; j < ${threads}; j++)); do
74                 ${ECHOCMD} "${LCTL} <<-EOF
75                         cfg_device ${echodev}
76                         test_mkdir ${tdir}${j}
77                 EOF"
78         done
79
80         ${ECHOCMD} "${LCTL} <<-EOF
81                 cfg_device ${echodev}
82                 --threads ${threads} 0 ${echodev} test_create \
83                 -d ${tdir} -D ${threads} -b ${lbase} -c 0 -n ${usize}
84         EOF"
85 }
86
87 lfsck_cleanup() {
88         do_rpc_nodes $(facet_active_host $SINGLEMDS) unload_modules
89         formatall
90 }
91
92 lfsck_create_nfiles() {
93         local total=$1
94         local lbase=$2
95         local threads=$3
96         local linkea=$4
97         local ldir="/test-${lbase}"
98         local cycle=0
99         local count=${UNIT}
100
101         while true; do
102                 [ ${count} -eq 0 -o  ${count} -gt ${total} ] && count=${total}
103                 local usize=$((count / NTHREADS))
104                 [ ${usize} -eq 0 ] && break
105                 local tdir=${ldir}-${cycle}-
106
107                 echo "[cycle: ${cycle}] [threads: ${threads}]"\
108                      "[files: ${count}] [basedir: ${tdir}]"
109                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB ||
110                         error "Fail to start MDS!"
111                 #define OBD_FAIL_FID_IGIF       0x1504
112                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x1504
113
114                 lfsck_attach
115                 lfsck_create
116                 lfsck_detach
117
118                 [ ! -z $linkea ] && ${RLCTL} set_param fail_loc=0x0
119                 stop ${SINGLEMDS} || error "Fail to stop MDS!"
120
121                 total=$((total - usize * NTHREADS))
122                 [ ${total} -eq 0 ] && break
123                 lbase=$((lbase + usize))
124                 cycle=$((cycle + 1))
125         done
126 }
127
128 build_test_filter
129
130 test_0() {
131         local BCOUNT=0
132         local i
133
134         stopall
135         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
136         reformat_external_journal
137         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
138                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
139                 error "Fail to reformat the MDS!"
140
141         for ((i = $MINCOUNT; i <= $MAXCOUNT; i = $((i * FACTOR)))); do
142                 local nfiles=$((i - BCOUNT))
143
144                 echo "+++ start to create for ${i} files set at: $(date) +++"
145                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
146                         error "Fail to create files!"
147                 echo "+++ end to create for ${i} files set at: $(date) +++"
148
149                 BCOUNT=${i}
150                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
151                         error "Fail to start MDS!"
152
153                 echo "start lfsck_namespace for ${i} files set at: $(date)"
154                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
155
156                 while true; do
157                         local STATUS=$($SHOW_NAMESPACE |
158                                         awk '/^status/ { print $2 }')
159                         [ "$STATUS" == "completed" ] && break
160                         sleep 3 # check status every 3 seconds
161                 done
162
163                 echo "end lfsck_namespace for ${i} files set at: $(date)"
164                 SPEED=$($SHOW_NAMESPACE |
165                         awk '/^average_speed_phase1/ { print $2 }')
166                 echo "lfsck_namespace speed is ${SPEED}/sec"
167                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
168         done
169 }
170 run_test 0 "lfsck performance test (routine case) without load"
171
172 test_1() {
173         local BCOUNT=0
174         local i
175
176         stopall
177         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
178         reformat_external_journal
179         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
180                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
181                 error "Fail to reformat the MDS!"
182
183         for ((i = $MINCOUNT_REPAIR; i <= $MAXCOUNT_REPAIR;
184               i = $((i * FACTOR)))); do
185                 local nfiles=$((i - BCOUNT))
186
187                 echo "+++ start to create for ${i} files set at: $(date) +++"
188                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
189                         error "Fail to create files!"
190                 echo "+++ end to create for ${i} files set at: $(date) +++"
191
192                 BCOUNT=${i}
193                 local stime=$(date +%s)
194                 echo "backup/restore ${i} files start at: $(date)"
195                 mds_backup_restore $SINGLEMDS || error "Fail to backup/restore!"
196                 echo "backup/restore ${i} files end at: $(date)"
197                 local etime=$(date +%s)
198                 local delta=$((etime - stime))
199                 [ $delta -gt 0 ] || delta=1
200                 echo "backup/restore ${i} files used ${delta} seconds"
201                 echo "backup/restore speed is $((i / delta))/sec"
202
203                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
204                         error "Fail to start MDS!"
205
206                 echo "start lfsck_namespace for ${i} files set at: $(date)"
207                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
208
209                 while true; do
210                         local STATUS=$($SHOW_NAMESPACE |
211                                         awk '/^status/ { print $2 }')
212                         [ "$STATUS" == "completed" ] && break
213                         sleep 3 # check status every 3 seconds
214                 done
215
216                 echo "end lfsck_namespace for ${i} files set at: $(date)"
217                 local SPEED=$($SHOW_NAMESPACE |
218                               awk '/^average_speed_phase1/ { print $2 }')
219                 echo "lfsck_namespace speed is ${SPEED}/sec"
220                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
221         done
222 }
223 run_test 1 "lfsck performance test (backup/restore) without load"
224
225 test_2() {
226         local i
227
228         for ((i = $MINCOUNT_REPAIR; i <= $MAXCOUNT_REPAIR;
229               i = $((i * FACTOR)))); do
230                 stopall
231                 do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
232                 reformat_external_journal
233                 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) \
234                         --backfstype ldiskfs --reformat ${MDT_DEVNAME} \
235                         $(mdsvdevname 1) > /dev/null ||
236                         error "Fail to reformat the MDS!"
237
238                 echo "+++ start to create for ${i} files set at: $(date) +++"
239                 lfsck_create_nfiles ${i} 0 ${NTHREADS} 1 ||
240                         error "Fail to create files!"
241                 echo "+++ end to create for ${i} files set at: $(date) +++"
242
243                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
244                         error "Fail to start MDS!"
245
246                 echo "start lfsck_namespace for ${i} files set at: $(date)"
247                 $START_NAMESPACE || error "Fail to start lfsck_namespace!"
248
249                 while true; do
250                         local STATUS=$($SHOW_NAMESPACE |
251                                         awk '/^status/ { print $2 }')
252                         [ "$STATUS" == "completed" ] && break
253                         sleep 3 # check status every 3 seconds
254                 done
255
256                 echo "end lfsck_namespace for ${i} files set at: $(date)"
257                 local SPEED=$($SHOW_NAMESPACE |
258                               awk '/^average_speed_phase1/ { print $2 }')
259                 echo "lfsck_namespace speed is ${SPEED}/sec"
260                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
261         done
262 }
263 run_test 2 "lfsck performance test (simulate upgrade from 1.8) without load"
264
265 test_3() {
266         [ $MDSSIZE -lt 4000000 ] &&
267                 skip "MDT device is too small, expect at last 4GB" && exit 0
268
269         [ $BASE_COUNT -lt 1048576 ] && BASE_COUNT=1048576
270         [ $INCFACTOR -gt 25 ] && INCFACTOR=25
271
272         local inc_count=$((BASE_COUNT * INCFACTOR / 100))
273         local BCOUNT=0
274         local i
275
276         stopall
277         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules_local
278         reformat_external_journal
279         add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS} ${MDT_DEVNAME}) --backfstype \
280                 ldiskfs --reformat ${MDT_DEVNAME} $(mdsvdevname 1) > /dev/null ||
281                 error "Fail to reformat the MDS!"
282
283         for ((i = $inc_count; i <= $BASE_COUNT; i = $((i + inc_count)))); do
284                 local nfiles=$((i - BCOUNT))
285
286                 echo "+++ start to create for ${i} files set at: $(date) +++"
287                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
288                         error "Fail to create files!"
289                 echo "+++ end to create for ${i} files set at: $(date) +++"
290                 BCOUNT=${i}
291         done
292
293         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
294                 error "Fail to start MDS!"
295
296         echo "start lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
297         $START_NAMESPACE || error "Fail to start lfsck_namespace!"
298
299         while true; do
300                 local STATUS=$($SHOW_NAMESPACE |
301                                 awk '/^status/ { print $2 }')
302                 [ "$STATUS" == "completed" ] && break
303                 sleep 3 # check status every 3 seconds
304         done
305
306         echo "end lfsck_namespace for ${BASE_COUNT} files set at: $(date)"
307         local FULL_SPEED=$($SHOW_NAMESPACE |
308                       awk '/^average_speed_phase1/ { print $2 }')
309         echo "lfsck_namespace full_speed is ${FULL_SPEED}/sec"
310         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
311         local inc_speed=$((FULL_SPEED * INCFACTOR / 100))
312         local j
313
314         for ((j = $inc_speed; j < $FULL_SPEED; j = $((j + inc_speed)))); do
315                 start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
316                         error "Fail to start MDS!"
317
318                 $STOP_LFSCK > /dev/null 2>&1
319                 echo "start lfsck_namespace with speed ${j} at: $(date)"
320                 $START_NAMESPACE --reset -s ${j} ||
321                         error "Fail to start lfsck_namespace with speed ${j}!"
322                 # lfsck_namespace will be paused when MDS stop,
323                 # and will be restarted automatically when mount up again.
324                 stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
325
326                 local nfiles=$(((i - BCOUNT) / 2))
327
328                 echo "+++ start to create for ${i} files set at: $(date) +++"
329                 lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
330                         error "Fail to create files!"
331                 echo "+++ end to create for ${i} files set at: $(date) +++"
332                 BCOUNT=${i}
333                 i=$((i + inc_count))
334         done
335
336         start ${SINGLEMDS} $MDT_DEVNAME $MNTOPTS_NOSCRUB > /dev/null ||
337                 error "Fail to start MDS!"
338
339         $STOP_LFSCK /dev/null 2>&1
340         echo "start lfsck_namespace with full speed at: $(date)"
341         $START_NAMESPACE --reset -s 0 ||
342                 error "Fail to start lfsck_namespace with full speed!"
343         stop ${SINGLEMDS} > /dev/null || error "Fail to stop MDS!"
344
345         local nfiles=$(((i - BCOUNT) / 2))
346
347         echo "+++ start to create for ${i} files set at: $(date) +++"
348         lfsck_create_nfiles ${nfiles} ${BCOUNT} ${NTHREADS} ||
349                 error "Fail to create files!"
350         echo "+++ end to create for ${i} files set at: $(date) +++"
351 }
352 run_test 3 "lfsck performance test (routine case) without load"
353
354 # cleanup the system at last
355 lfsck_cleanup
356 complete $SECONDS
357 exit_status