2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc. All Rights Reserved.
7 # This test verifies that cgroup aware writeback properly accounts I/Os in
8 # various scenarios. We perform reads/writes from different combinations of
9 # cgroups and verify that pages are accounted against the group that brought
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
27 echo $$ > $cgdir/cgroup.procs
28 rmdir $cgdir/$seq-cg* > /dev/null 2>&1
31 # get standard environment, filters and checks
36 # remove previous $seqres.full before test
39 # real QA test starts here
41 # Modify as appropriate.
46 # cgroup v2 writeback is only support on block devices so far
47 _require_block_device $SCRATCH_DEV
49 smajor=$((0x`stat -L -c %t $SCRATCH_DEV`))
50 sminor=$((0x`stat -L -c %T $SCRATCH_DEV`))
53 iosize=$((1024 * 1024 * 8))
55 # Check cgroup read/write charges against expected values. Allow for some
56 # tolerance as different filesystems seem to account slightly differently.
60 cgname=$(basename $cgroot)
66 iobytes=`cat $cgroot/io.stat | grep $smajor:$sminor`
68 rbytes=`echo $iobytes | awk '{ print $2 }' | \
69 awk -F = '{ print $2 }'`
70 wbytes=`echo $iobytes | awk '{ print $3 }' | \
71 awk -F = '{ print $2 }'`
74 _within_tolerance "read" $rbytes $expectedread 5% -v
75 _within_tolerance "write" $wbytes $expectedwrite 5% -v
78 # Move current process to another cgroup.
82 echo $$ > $1/cgroup.procs
85 # Reset cgroup state for a new test.
88 echo $$ > $cgdir/cgroup.procs
89 rmdir $cgdir/$seq-cg* > /dev/null 2>&1
90 $XFS_IO_PROG -fc "pwrite 0 $iosize" $SCRATCH_MNT/file \
92 _scratch_cycle_mount || _fail "mount failed"
93 stat $SCRATCH_MNT/file > /dev/null
96 _scratch_mkfs >> $seqres.full 2>&1
99 echo "+io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
101 # Read and write from a single group.
104 switch_cg $cgdir/$seq-cg
105 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" -c fsync \
106 $SCRATCH_MNT/file >> $seqres.full 2>&1
108 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
109 check_cg $cgdir/$seq-cg $iosize $iosize
111 # Write from one cgroup then read and write from a second. Writes are charged to
112 # the first group and nothing to the second.
113 echo "write -> read/write"
115 switch_cg $cgdir/$seq-cg
116 $XFS_IO_PROG -c "pwrite 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
117 switch_cg $cgdir/$seq-cg-2
118 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
121 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
122 check_cg $cgdir/$seq-cg 0 $iosize
123 check_cg $cgdir/$seq-cg-2 0 0
125 # Read from one cgroup, read & write from a second. Both reads and writes are
126 # charged to the first group and nothing to the second.
127 echo "read -> read/write"
129 switch_cg $cgdir/$seq-cg
130 $XFS_IO_PROG -c "pread 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
131 switch_cg $cgdir/$seq-cg-2
132 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
135 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
136 check_cg $cgdir/$seq-cg $iosize $iosize
137 check_cg $cgdir/$seq-cg-2 0 0
139 echo "-io" > $cgdir/cgroup.subtree_control || _fail "subtree control"