run_io_throttle_test.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2 of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public
  14. # License along with this program; if not, write to the
  15. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. # Boston, MA 021110-1307, USA.
  17. #
  18. # Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
  19. #
  20. # Usage: ./run_io_throttle_test.sh
  21. # Description: test block device I/O bandwidth controller functionalities
  22. . ./myfunctions-io.sh
  23. trap cleanup SIGINT
  24. BUFSIZE=16m
  25. DATASIZE=64m
  26. setup
  27. # get the device name of the entire mounted block device
  28. dev=`df -P . | sed '1d' | cut -d' ' -f1 | sed 's/[p]*[0-9]*$//'`
  29. # evaluate device bandwidth
  30. export MYGROUP=
  31. phys_bw=`./iobw -direct 1 $BUFSIZE $DATASIZE | grep TOTAL | awk '{print $7}'`
  32. if [ $? -ne 0 ]; then
  33. echo "ERROR: could not evaluate i/o bandwidth of $dev. Exiting test."
  34. cleanup
  35. exit 1
  36. fi
  37. echo ">> physical i/o bandwidth limit is: $phys_bw KiB/s"
  38. # show cgroup i/o bandwidth limits
  39. for i in `seq 1 3`; do
  40. MYGROUP=cgroup-$i
  41. echo "($MYGROUP) max i/o bw: " \
  42. "$(($phys_bw / `echo 2^$i | bc`)) KiB/s + O_DIRECT"
  43. done
  44. for tasks in 1 2 4; do
  45. for strategy in 0 1; do
  46. # set bw limiting rules
  47. if [ -f /dev/blockioctl/blockio.bandwidth ]; then
  48. io_throttle_file=blockio.bandwidth
  49. elif [ -f /dev/blockioctl/blockio.bandwidth-max ]; then
  50. io_throttle_file=blockio.bandwidth-max
  51. else
  52. echo "ERROR: unknown kernel ABI. Exiting test."
  53. cleanup
  54. exit 1
  55. fi
  56. for i in `seq 1 3`; do
  57. limit=$(($phys_bw * 1024 / `echo 2^$i | bc`))
  58. IOBW[$i]=$(($limit / 1024))
  59. /bin/echo $dev:$limit:$strategy:$limit > \
  60. /dev/blockioctl/cgroup-$i/${io_throttle_file}
  61. if [ $? -ne 0 ]; then
  62. echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
  63. cleanup
  64. exit 1
  65. fi
  66. done
  67. # run benchmark
  68. if [ $tasks -eq 1 ]; then
  69. stream="stream"
  70. else
  71. stream="streams"
  72. fi
  73. echo -n ">> testing $tasks parallel $stream per cgroup "
  74. if [ $strategy -eq 0 ]; then
  75. echo "(leaky-bucket i/o throttling)"
  76. else
  77. echo "(token-bucket i/o throttling)"
  78. fi
  79. for i in `seq 1 3`; do
  80. MYGROUP=cgroup-$i
  81. /bin/echo $$ > /dev/blockioctl/$MYGROUP/tasks
  82. if [ $? -ne 0 ]; then
  83. echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
  84. cleanup
  85. exit 1
  86. fi
  87. # exec i/o benchmark
  88. ./iobw -direct $tasks $BUFSIZE $DATASIZE > /tmp/$MYGROUP.out &
  89. PID[$i]=$!
  90. done
  91. /bin/echo $$ > /dev/blockioctl/tasks
  92. # wait for children completion
  93. for i in `seq 1 3`; do
  94. MYGROUP=cgroup-$i
  95. wait ${PID[$i]}
  96. ret=$?
  97. if [ $ret -ne 0 ]; then
  98. echo "ERROR: error code $ret during test $tasks.$strategy.$i. Exiting test."
  99. cleanup
  100. exit 1
  101. fi
  102. iorate=`grep parent /tmp/${MYGROUP}.out | awk '{print $7}'`
  103. diff=$((${IOBW[$i]} - $iorate))
  104. echo "($MYGROUP) i/o-bw ${IOBW[$i]} KiB/s, i/o-rate $iorate KiB/s, err $diff KiB/s"
  105. if [ ${IOBW[$i]} -ge $iorate ]; then
  106. echo "TPASS Block device I/O bandwidth controller: test $tasks.$strategy.$i PASSED";
  107. else
  108. echo "TFAIL Block device I/O bandwidth controller: test $tasks.$strategy.$i FAILED";
  109. fi
  110. done
  111. done
  112. done
  113. cleanup