ext3-perf.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # ensure that "rm -rf DIR-with-many-entries" is not O(N^2)
  3. # Copyright (C) 2008-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  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
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ rm
  16. very_expensive_
  17. # Using rm -rf to remove a 400k-entry directory takes:
  18. # - 9 seconds with the patch, on a 2-yr-old system
  19. # - 350 seconds without the patch, on a high-end system (disk 20-30% faster)
  20. threshold_seconds=60
  21. # The number of entries in our test directory.
  22. n=400000
  23. # Choose a value that is large enough to ensure an accidentally
  24. # regressed rm would require much longer than $threshold_seconds to remove
  25. # the directory. With n=400k, pre-patch GNU rm would require about 350
  26. # seconds even on a fast disk. On a relatively modern system, the
  27. # patched version of rm requires about 10 seconds, so even if you
  28. # choose to enable very expensive tests with a disk that is much slower,
  29. # the test should still succeed.
  30. # Skip unless "." is on an ext[34] file system.
  31. # FIXME-maybe: try to find a suitable file system or allow
  32. # the user to specify it via an envvar.
  33. df -T -t ext3 -t ext4dev -t ext4 . \
  34. || skip_ 'this test runs only on an ext3 or ext4 file system'
  35. # Skip if there are too few inodes free. Require some slack.
  36. free_inodes=$(stat -f --format=%d .) || framework_failure_
  37. min_free_inodes=$(expr 12 \* $n / 10)
  38. test $min_free_inodes -lt $free_inodes \
  39. || skip_ "too few free inodes on '.': $free_inodes;" \
  40. "this test requires at least $min_free_inodes"
  41. ok=0
  42. start=$(date +%s)
  43. mkdir d &&
  44. cd d &&
  45. seq $n | xargs touch &&
  46. test -f 1 &&
  47. test -f $n &&
  48. cd .. &&
  49. ok=1
  50. test $ok = 1 || framework_failure_
  51. setup_duration=$(expr $(date +%s) - $start)
  52. echo creating a $n-entry directory took $setup_duration seconds
  53. # If set-up took longer than the default $threshold_seconds,
  54. # use the longer set-up duration as the limit.
  55. test $threshold_seconds -lt $setup_duration \
  56. && threshold_seconds=$setup_duration
  57. start=$(date +%s)
  58. timeout ${threshold_seconds}s rm -rf d; err=$?
  59. duration=$(expr $(date +%s) - $start)
  60. case $err in
  61. 124) fail=1; echo rm took longer than $threshold_seconds seconds;;
  62. 0) ;;
  63. *) fail=1;;
  64. esac
  65. echo removing a $n-entry directory took $duration seconds
  66. Exit $fail