generic/551: Adjust the size argument for aio-dio-write-verify
authorMasayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Mon, 18 Nov 2019 17:40:37 +0000 (12:40 -0500)
committerEryu Guan <guaneryu@gmail.com>
Sun, 1 Dec 2019 15:46:15 +0000 (23:46 +0800)
generic/551 sometimes fails because it's killed by OOM killer.
That is because aio-dio-write-verify, which is called by
generic/551, tries to allocate memory even though the total
allocation size exceeds the available memory.

aio-dio-write-verify allocates memory according to the 'size'
argument, and generic/551 passes the argument.

Stop adding the argument when the total size is exceeds
the available memory.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc
tests/generic/551

index 4688f2368ee0a5cecb3fcf272ae5f94b1299ece9..6943f19f130c520c65ab00e0458d90ab1f321744 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -910,6 +910,17 @@ _free_memory_bytes()
     free -b | grep ^Mem | awk '{print $4}'
 }
 
+_available_memory_bytes()
+{
+       nf=`free -b | grep ^Mem | awk '{print NF}'`
+       if [[ nf -lt 7 ]]; then
+               # Doesn't have available field. Fallback.
+               _free_memory_bytes
+       else
+               free -b | grep ^Mem | awk '{print $7}'
+       fi
+}
+
 # Create fs of certain size on scratch device
 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
 _scratch_mkfs_sized()
index a2a5b51d66e3155c279a19c556b18502936e1616..a0dc9cd7fd11de091ebb662f143bed78ec9da91f 100755 (executable)
@@ -55,12 +55,18 @@ do_test()
        local size
        local off
        local truncsize
+       local total_size=0
+       local avail_mem=`_available_memory_bytes`
 
        # the number of AIO write operation
        num_oper=$((RANDOM % 64 + 1))
 
        for ((i=0; i<num_oper; i++)); do
                size=$(((RANDOM % max_io_size_b + 1) * diosize))
+               total_size=$((total_size + size*2))
+               if [[ $total_size -ge $avail_mem ]]; then
+                       break
+               fi
                off=$((RANDOM % max_io_size_b * diosize))
                oper_list="$oper_list -a size=$size,off=$off"
        done