zbd: fix write zone accounting of trim workload
[fio.git] / t / zbd / test-zbd-support
index 7e2fff00dac6adc4cc8bc08b7423ab9b7081ab3f..996160e769476bc8a070af2c40f4d442380ff4b0 100755 (executable)
@@ -17,6 +17,7 @@ usage() {
        echo -e "\t-t <test #> Run only a single test case with specified number"
        echo -e "\t-q Quit the test run after any failed test"
        echo -e "\t-z Run fio with debug=zbd option"
+       echo -e "\t-u Use io_uring ioengine in place of libaio"
 }
 
 max() {
@@ -38,6 +39,8 @@ min() {
 ioengine() {
        if [ -n "$use_libzbc" ]; then
                echo -n "--ioengine=libzbc"
+       elif [ "$1" = "libaio" -a -n "$force_io_uring" ]; then
+               echo -n "--ioengine=io_uring"
        else
                echo -n "--ioengine=$1"
        fi
@@ -163,7 +166,7 @@ write_and_run_one_fio_job() {
     shift 2
     r=$(((RANDOM << 16) | RANDOM))
     write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
-                     --bs="${logical_block_size}" --zonemode=zbd \
+                     --bs="${min_seq_write_size}" --zonemode=zbd \
                      --zonesize="${zone_size}" --thread=1 --direct=1 \
                      --offset="${write_offset}" --size="${write_size}")
     write_opts+=("${job_var_opts[@]}")
@@ -229,6 +232,14 @@ require_regular_block_dev() {
        return 0
 }
 
+require_block_dev() {
+       if [[ -b "$realdev" ]]; then
+               return 0
+       fi
+       SKIP_REASON="$dev is not a block device"
+       return 1
+}
+
 require_seq_zones() {
        local req_seq_zones=${1}
        local seq_bytes=$((disk_size - first_sequential_zone_sector * 512))
@@ -251,8 +262,19 @@ require_conv_zones() {
        return 0
 }
 
-# Check whether buffered writes are refused.
+require_max_open_zones() {
+       local min=${1}
+
+       if ((max_open_zones !=0 && max_open_zones < min)); then
+               SKIP_REASON="max_open_zones of $dev is smaller than $min"
+               return 1
+       fi
+       return 0
+}
+
+# Check whether buffered writes are refused for block devices.
 test1() {
+    require_block_dev || return $SKIP_TESTCASE
     run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K        \
            "$(ioengine "psync")" --size="${zone_size}" --thread=1      \
            --zonemode=zbd --zonesize="${zone_size}" 2>&1 |
@@ -313,7 +335,7 @@ test4() {
     size=$((zone_size))
     [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
     opts+=("--name=$dev" "--filename=$dev" "--offset=$off")
-    opts+=(--bs="$(min $((logical_block_size * 256)) $size)")
+    opts+=(--bs="$(min $((min_seq_write_size * 256)) $size)")
     opts+=("--size=$size" "--thread=1" "--read_beyond_wp=1")
     opts+=("$(ioengine "psync")" "--rw=read" "--direct=1" "--disable_lat=1")
     opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
@@ -329,7 +351,7 @@ test5() {
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
-    bs=$(min "$(max $((zone_size / 64)) "$logical_block_size")" "$zone_cap_bs")
+    bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
     run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write        \
                   --bs="$bs" --do_verify=1 --verify=md5 \
                   >>"${logfile}.${test_number}" 2>&1 || return $?
@@ -345,7 +367,7 @@ test6() {
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
-    bs=$(min "$(max $((zone_size / 64)) "$logical_block_size")" "$zone_cap_bs")
+    bs=$(min "$(max $((zone_size / 64)) "$min_seq_write_size")" "$zone_cap_bs")
     write_and_run_one_fio_job \
            $((first_sequential_zone_sector * 512)) "${size}" \
            --offset="${off}" \
@@ -453,6 +475,8 @@ test12() {
 test13() {
     local size off capacity
 
+    require_max_open_zones 4 || return $SKIP_TESTCASE
+
     prep_write
     size=$((8 * zone_size))
     off=$((first_sequential_zone_sector * 512))
@@ -724,7 +748,7 @@ test30() {
     prep_write
     off=$((first_sequential_zone_sector * 512))
     run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw     \
-                   --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
+                   --bs="$(max $((zone_size / 128)) "$min_seq_write_size")"\
                    --zonemode=zbd --zonesize="${zone_size}" --offset=$off\
                    --loops=2 --time_based --runtime=30s --norandommap=1\
                    >>"${logfile}.${test_number}" 2>&1
@@ -789,7 +813,8 @@ test33() {
     local bs io_size size
     local off capacity=0;
 
-    prep_write
+    [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
     size=$((2 * zone_size))
@@ -798,20 +823,30 @@ test33() {
     run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write        \
                   --size=$size --io_size=$io_size --bs=$bs     \
                   >> "${logfile}.${test_number}" 2>&1 || return $?
-    check_written $(((io_size + bs - 1) / bs * bs)) || return $?
+    check_written $((io_size / bs * bs)) || return $?
 }
 
-# Write to sequential zones with a block size that is not a divisor of the
-# zone size and with data verification enabled.
+# Test repeated async write job with verify using two unaligned block sizes.
 test34() {
-    local size
+       local bs off zone_capacity
+       local -a block_sizes
 
-    prep_write
-    size=$((2 * zone_size))
-    run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
-                  --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
-                  >> "${logfile}.${test_number}" 2>&1 && return 1
-    grep -q 'not a divisor of' "${logfile}.${test_number}"
+       require_zbd || return $SKIP_TESTCASE
+       prep_write
+
+       off=$((first_sequential_zone_sector * 512))
+       zone_capacity=$(total_zone_capacity 1 $off $dev)
+       block_sizes=($((4096 * 7)) $(($(min ${zone_capacity} 4194304) - 4096)))
+
+       for bs in ${block_sizes[@]}; do
+               run_fio --name=job --filename="${dev}" --rw=randwrite \
+                       --bs="${bs}" --offset="${off}" \
+                       --size=$((4 * zone_size)) --iodepth=256 \
+                       "$(ioengine "libaio")" --time_based=1 --runtime=15s \
+                       --zonemode=zbd --direct=1 --zonesize="${zone_size}" \
+                       --verify=crc32c --do_verify=1 ${job_var_opts[@]} \
+                       >> "${logfile}.${test_number}" 2>&1 || return $?
+       done
 }
 
 # Test 1/4 for the I/O boundary rounding code: $size < $zone_size.
@@ -869,9 +904,9 @@ test38() {
     local bs off size
 
     prep_write
-    size=$((logical_block_size))
-    off=$((disk_size - logical_block_size))
-    bs=$((logical_block_size))
+    size=$((min_seq_write_size))
+    off=$((disk_size - min_seq_write_size))
+    bs=$((min_seq_write_size))
     run_one_fio_job --offset=$off --size=$size "$(ioengine "psync")"   \
                    --iodepth=1 --rw=write --do_verify=1 --verify=md5   \
                    --bs=$bs --zonemode=zbd --zonesize="${zone_size}"   \
@@ -889,7 +924,7 @@ read_one_block() {
        exit 1
     fi
     off=${result[0]}
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     run_one_fio_job --rw=read "$(ioengine "psync")" --offset=$off --bs=$bs \
                    --size=$bs "$@" 2>&1 |
        tee -a "${logfile}.${test_number}"
@@ -899,14 +934,14 @@ read_one_block() {
 test39() {
     require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=none >/dev/null || return $?
-    check_read $((logical_block_size)) || return $?
+    check_read $((min_seq_write_size)) || return $?
 }
 
 # Check whether fio accepts --zonemode=strided for zoned block devices.
 test40() {
     local bs
 
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=strided |
        grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
@@ -947,7 +982,7 @@ test45() {
 
     require_zbd || return $SKIP_TESTCASE
     prep_write
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
                    --offset=$((first_sequential_zone_sector * 512)) \
                    --size="$zone_size" --do_verify=1 --verify=md5 2>&1 |
@@ -972,7 +1007,7 @@ test47() {
     local bs
 
     prep_write
-    bs=$((logical_block_size))
+    bs=$((min_seq_write_size))
     run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
                    >> "${logfile}.${test_number}" 2>&1 && return 1
     grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
@@ -1075,8 +1110,8 @@ test51() {
        run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
 }
 
-# Verify that zone_reset_threshold only takes logical blocks from seq
-# zones into account, and logical blocks of conv zones are not counted.
+# Verify that zone_reset_threshold only accounts written bytes in seq
+# zones, and written data bytes of conv zones are not counted.
 test52() {
        local off io_size
 
@@ -1147,7 +1182,6 @@ test54() {
                --rw=randrw:2 --rwmixwrite=25 --bsrange=4k-${zone_size} \
                --zonemode=zbd --zonesize=${zone_size} \
                --verify=crc32c --do_verify=1 --verify_backlog=2 \
-               --experimental_verify=1 \
                --alloc-size=65536 --random_generator=tausworthe64 \
                ${job_var_opts[@]} --debug=zbd \
                >> "${logfile}.${test_number}" 2>&1 || return $?
@@ -1156,7 +1190,7 @@ test54() {
 # test 'z' suffix parsing only
 test55() {
        local bs
-       bs=$((logical_block_size))
+       bs=$((min_seq_write_size))
 
        require_zbd || return $SKIP_TESTCASE
        # offset=1z + offset_increment=10z + size=2z
@@ -1182,7 +1216,7 @@ test55() {
 # test 'z' suffix parsing only
 test56() {
        local bs
-       bs=$((logical_block_size))
+       bs=$((min_seq_write_size))
 
        require_regular_block_dev || return $SKIP_TESTCASE
        require_seq_zones 10 || return $SKIP_TESTCASE
@@ -1226,7 +1260,7 @@ test58() {
     require_seq_zones 128 || return $SKIP_TESTCASE
 
     size=$((zone_size * 128))
-    bs="$(max $((zone_size / 128)) "$logical_block_size")"
+    bs="$(max $((zone_size / 128)) "$min_seq_write_size")"
     prep_write
     off=$((first_sequential_zone_sector * 512))
     run_fio --zonemode=zbd --direct=1 --zonesize="${zone_size}" --thread=1 \
@@ -1245,6 +1279,88 @@ test58() {
            >>"${logfile}.${test_number}" 2>&1
 }
 
+# Test zone_reset_threshold with verify.
+test59() {
+       local off bs loops=2 size=$((zone_size)) w
+       local -a workloads=(write randwrite rw randrw)
+
+       prep_write
+       off=$((first_sequential_zone_sector * 512))
+
+       bs=$(min $((256*1024)) "$zone_size")
+       for w in "${workloads[@]}"; do
+               run_fio_on_seq "$(ioengine "psync")" --rw=${w} --bs="$bs" \
+                              --size=$size --loops=$loops --do_verify=1 \
+                              --verify=md5 --zone_reset_frequency=.9 \
+                              --zone_reset_threshold=.1 \
+                              >> "${logfile}.${test_number}" 2>&1 || return $?
+       done
+}
+
+# Test fio errors out experimental_verify option with zonemode=zbd.
+test60() {
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --size=$zone_size \
+                      --do_verify=1 --verify=md5 --experimental_verify=1 \
+                      >> "${logfile}.${test_number}" 2>&1 && return 1
+       grep -q 'not support experimental verify' "${logfile}.${test_number}"
+}
+
+# Test fio errors out zone_reset_threshold option for multiple jobs with
+# different write ranges.
+test61() {
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --size="$zone_size" \
+                      --numjobs=2 --offset_increment="$zone_size" \
+                      --zone_reset_threshold=0.1 --zone_reset_frequency=1 \
+                      --exitall_on_error=1 \
+                      >> "${logfile}.${test_number}" 2>&1 && return 1
+       grep -q 'different write ranges' "${logfile}.${test_number}"
+}
+
+# Test zone_reset_threshold option works for multiple jobs with same write
+# range.
+test62() {
+       local bs loops=2 size=$((zone_size))
+
+       [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
+       # Two jobs write to single zone twice. Reset zone happens at next write
+       # after half of the zone gets filled. So 2 * 2 * 2 - 1 = 7 times zone
+       # resets are expected.
+       bs=$(min $((256*1024)) $((zone_size / 4)))
+       run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
+                      --size=$size --loops=$loops --numjobs=2 \
+                      --zone_reset_frequency=1 --zone_reset_threshold=.5 \
+                      --group_reporting=1 \
+                      >> "${logfile}.${test_number}" 2>&1 || return $?
+       check_written $((size * loops * 2)) || return $?
+       check_reset_count -eq 7 || return $?
+}
+
+# Test zone_reset_threshold option works for a read job and a write job with
+# different IO range.
+test63() {
+       local bs loops=2 size=$((zone_size)) off1 off2
+
+       [ -n "$is_zbd" ] && reset_zone "$dev" -1
+
+       off1=$((first_sequential_zone_sector * 512))
+       off2=$((off1 + zone_size))
+       bs=$(min $((256*1024)) $((zone_size / 4)))
+
+       # One job writes to single zone twice. Reset zone happens at next write
+       # after half of the zone gets filled. So 2 * 2 - 1 = 3 times zone resets
+       # are expected.
+       run_fio "$(ioengine "psync")" --bs="$bs" --size=$size --loops=$loops \
+               --filename="$dev" --group_reporting=1 \
+               --zonemode=zbd --zonesize="$zone_size" --direct=1 \
+               --zone_reset_frequency=1 --zone_reset_threshold=.5 \
+               --name=r --rw=read --offset=$off1 "${job_var_opts[@]}" \
+               --name=w --rw=write --offset=$off2 "${job_var_opts[@]}" \
+                      >> "${logfile}.${test_number}" 2>&1 || return $?
+       check_written $((size * loops)) || return $?
+       check_reset_count -eq 3 || return $?
+}
+
 SECONDS=0
 tests=()
 dynamic_analyzer=()
@@ -1254,6 +1370,7 @@ use_libzbc=
 zbd_debug=
 max_open_zones_opt=
 quit_on_err=
+force_io_uring=
 
 while [ "${1#-}" != "$1" ]; do
   case "$1" in
@@ -1271,6 +1388,7 @@ while [ "${1#-}" != "$1" ]; do
        shift;;
     -q) quit_on_err=1; shift;;
     -z) zbd_debug=1; shift;;
+    -u) force_io_uring=1; shift;;
     --) shift; break;;
      *) usage; exit 1;;
   esac
@@ -1281,6 +1399,11 @@ if [ $# != 1 ]; then
     exit 1
 fi
 
+if [ -n "$use_libzbc" -a -n "$force_io_uring" ]; then
+    echo "Please specify only one of -l and -u options"
+    exit 1
+fi
+
 # shellcheck source=functions
 source "$(dirname "$0")/functions" || exit $?
 
@@ -1304,7 +1427,7 @@ if [[ -b "$realdev" ]]; then
                realsysfs=$(readlink "/sys/dev/block/$major:$minor")
                basename=$(basename "${realsysfs%/*}")
        fi
-       logical_block_size=$(<"/sys/block/$basename/queue/logical_block_size")
+       min_seq_write_size=$(min_seq_write_size "$basename")
        case "$(<"/sys/class/block/$basename/queue/zoned")" in
        host-managed|host-aware)
                is_zbd=true
@@ -1329,8 +1452,8 @@ if [[ -b "$realdev" ]]; then
                ;;
        *)
                first_sequential_zone_sector=$(((disk_size / 2) &
-                                               (logical_block_size - 1)))
-               zone_size=$(max 65536 "$logical_block_size")
+                                               (min_seq_write_size - 1)))
+               zone_size=$(max 65536 "$min_seq_write_size")
                sectors_per_zone=$((zone_size / 512))
                max_open_zones=128
                set_io_scheduler "$basename" none || exit $?
@@ -1353,8 +1476,8 @@ elif [[ -c "$realdev" ]]; then
                echo "Failed to determine disk size"
                exit 1
        fi
-       if ! logical_block_size=($(zbc_logical_block_size "$dev")); then
-               echo "Failed to determine logical block size"
+       if ! min_seq_write_size=($(zbc_physical_block_size "$dev")); then
+               echo "Failed to determine physical block size"
                exit 1
        fi
        if ! result=($(first_sequential_zone "$dev")); then