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.
42 _supported_fs ext4 btrfs
47 smajor=$((0x`stat -L -c %t $SCRATCH_DEV`))
48 sminor=$((0x`stat -L -c %T $SCRATCH_DEV`))
51 iosize=$((1024 * 1024 * 8))
53 # Check cgroup read/write charges against expected values. Allow for some
54 # tolerance as different filesystems seem to account slightly differently.
58 cgname=$(basename $cgroot)
64 iobytes=`cat $cgroot/io.stat | grep $smajor:$sminor`
66 rbytes=`echo $iobytes | awk '{ print $2 }' | \
67 awk -F = '{ print $2 }'`
68 wbytes=`echo $iobytes | awk '{ print $3 }' | \
69 awk -F = '{ print $2 }'`
72 _within_tolerance "read" $rbytes $expectedread 5% -v
73 _within_tolerance "write" $wbytes $expectedwrite 5% -v
76 # Move current process to another cgroup.
80 echo $$ > $1/cgroup.procs
83 # Reset cgroup state for a new test.
86 echo $$ > $cgdir/cgroup.procs
87 rmdir $cgdir/$seq-cg* > /dev/null 2>&1
88 $XFS_IO_PROG -fc "pwrite 0 $iosize" $SCRATCH_MNT/file \
90 _scratch_cycle_mount || _fail "mount failed"
91 stat $SCRATCH_MNT/file > /dev/null
94 _scratch_mkfs >> $seqres.full 2>&1
97 echo "+io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
99 # Read and write from a single group.
102 switch_cg $cgdir/$seq-cg
103 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" -c fsync \
104 $SCRATCH_MNT/file >> $seqres.full 2>&1
106 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
107 check_cg $cgdir/$seq-cg $iosize $iosize
109 # Write from one cgroup then read and write from a second. Writes are charged to
110 # the first group and nothing to the second.
111 echo "write -> read/write"
113 switch_cg $cgdir/$seq-cg
114 $XFS_IO_PROG -c "pwrite 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
115 switch_cg $cgdir/$seq-cg-2
116 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
119 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
120 check_cg $cgdir/$seq-cg 0 $iosize
121 check_cg $cgdir/$seq-cg-2 0 0
123 # Read from one cgroup, read & write from a second. Both reads and writes are
124 # charged to the first group and nothing to the second.
125 echo "read -> read/write"
127 switch_cg $cgdir/$seq-cg
128 $XFS_IO_PROG -c "pread 0 $iosize" $SCRATCH_MNT/file >> $seqres.full 2>&1
129 switch_cg $cgdir/$seq-cg-2
130 $XFS_IO_PROG -c "pread 0 $iosize" -c "pwrite 0 $iosize" $SCRATCH_MNT/file \
133 $XFS_IO_PROG -c fsync $SCRATCH_MNT/file
134 check_cg $cgdir/$seq-cg $iosize $iosize
135 check_cg $cgdir/$seq-cg-2 0 0
137 echo "-io" > $cgdir/cgroup.subtree_control || _fail "subtree control"