selftests: mm: stop relying on killall in charge_reserved_hugetlb
Subsystems (3)
PATCH 1/1 selftests: mm: stop relying on killall in charge_reserved_hugetlb
charge_reserved_hugetlb.sh tears down background writers with killall -2 --wait write_to_hugetlbfs. That depends on killall from psmisc, which is not installed on minimal Ubuntu images, so the test fails in cleanup with "killall: command not found".
Track the writer PIDs we start ourselves and signal them directly during cleanup instead. Make write_hugetlb_memory.sh exec write_to_hugetlbfs so the recorded PID names the long-lived test process, and redirect async output straight to the temporary log file instead of going through a tee pipeline.
--- .../selftests/mm/charge_reserved_hugetlb.sh | 25 +++++++++++++++---- .../selftests/mm/write_hugetlb_memory.sh | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-)
tools/testing/selftests/mm/charge_reserved_hugetlb.sh +20 -5
@@ -44,6 +44,8 @@ else fi export cgroup_path +write_pids=() + function cleanup() { if [[ $cgroup2 ]]; then echo $$ >$cgroup_path/cgroup.procs
@@ -193,10 +195,12 @@ function write_hugetlbfs_and_get_usage() { [[ "$private" == "-r" ]] && [[ "$expect_failure" != 1 ]]; then bash write_hugetlb_memory.sh "$size" "$populate" "$write" \ - "$cgroup" "$path" "$method" "$private" "-l" "$reserve" 2>&1 | tee $output & + "$cgroup" "$path" "$method" "$private" "-l" "$reserve" \ + >"$output" 2>&1 & local write_result=$? local write_pid=$! + write_pids+=("$write_pid") until grep -q -i "DONE" $output; do echo waiting for DONE signal.
@@ -261,10 +265,21 @@ function write_hugetlbfs_and_get_usage() { function cleanup_hugetlb_memory() { set +e local cgroup="$1" - if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then - echo killing write_to_hugetlbfs - killall -2 --wait write_to_hugetlbfs - wait_for_hugetlb_memory_to_get_depleted $cgroup + local write_pid + + if (( ${#write_pids[@]} )); then + for write_pid in "${write_pids[@]}"; do + if kill -0 "$write_pid" 2>/dev/null; then + echo killing write_to_hugetlbfs pid "$write_pid" + kill -2 "$write_pid" + wait "$write_pid" + fi + done + write_pids=() + + if [[ -n "$cgroup" ]]; then + wait_for_hugetlb_memory_to_get_depleted "$cgroup" + fi fi set -e
tools/testing/selftests/mm/write_hugetlb_memory.sh +1 -1
@@ -19,5 +19,5 @@ echo $$ > ${cgroup_path:-/dev/cgroup/memory}/"$cgroup"/cgroup.procs echo "Method is $method" set +e -./write_to_hugetlbfs -p "$path" -s "$size" "$write" "$populate" -m "$method" \ +exec ./write_to_hugetlbfs -p "$path" -s "$size" "$write" "$populate" -m "$method" \ "$private" "$want_sleep" "$reserve"
Signature · 1 line
2.39.5 (Apple Git-154)
Mike Rapoport
reviewerHi,
Quoted 4 lines · CaoRuichuang
charge_reserved_hugetlb.shtears down background writers with killall -2 --waitwrite_to_hugetlbfs. That depends on killall from psmisc, which is not installed on minimal Ubuntu images, so the test fails in cleanup with "killall: command not found".
Can't we just skip the test if killall is not available just like we skip it if it's not run as root?
Quoted 79 lines
Track the writer PIDs we start ourselves and signal them directly during cleanup instead. Make
write_hugetlb_memory.shexecwrite_to_hugetlbfsso the recorded PID names the long-lived test process, and redirect async output straight to the temporary log file instead of going through a tee pipeline.Signed-off-by CaoRuichuang <[email protected]>--- .../selftests/mm/charge_reserved_hugetlb.sh | 25 +++++++++++++++---- .../selftests/mm/write_hugetlb_memory.sh | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-)tools/testing/selftests/mm/charge_reserved_hugetlb.sh +20
-5@@ -44,6 +44,8 @@ else fi export cgroup_path +write_pids=() + function cleanup() { if [[ $cgroup2 ]]; then echo $$ >$cgroup_path/cgroup.procs@@ -193,10 +195,12 @@ function write_hugetlbfs_and_get_usage() { [[ "$private" == "-r" ]] && [[ "$expect_failure" != 1 ]]; then bash write_hugetlb_memory.sh "$size" "$populate" "$write" \ - "$cgroup" "$path" "$method" "$private" "-l" "$reserve" 2>&1 | tee $output & + "$cgroup" "$path" "$method" "$private" "-l" "$reserve" \ + >"$output" 2>&1 & local write_result=$? local write_pid=$! + write_pids+=("$write_pid") until grep -q -i "DONE" $output; do echo waiting for DONE signal.@@ -261,10 +265,21 @@ function write_hugetlbfs_and_get_usage() { function cleanup_hugetlb_memory() { set +e local cgroup="$1" - if [[ "$(pgrep -f write_to_hugetlbfs)" != "" ]]; then - echo killing write_to_hugetlbfs - killall -2 --wait write_to_hugetlbfs - wait_for_hugetlb_memory_to_get_depleted $cgroup + local write_pid + + if (( ${#write_pids[@]} )); then + for write_pid in "${write_pids[@]}"; do + if kill -0 "$write_pid" 2>/dev/null; then + echo killing write_to_hugetlbfs pid "$write_pid" + kill -2 "$write_pid" + wait "$write_pid" + fi + done + write_pids=() + + if [[ -n "$cgroup" ]]; then + wait_for_hugetlb_memory_to_get_depleted "$cgroup" + fi fi set -etools/testing/selftests/mm/write_hugetlb_memory.sh +1
-1@@ -19,5 +19,5 @@ echo $$ > ${cgroup_path:-/dev/cgroup/memory}/"$cgroup"/cgroup.procs echo "Method is $method" set +e -./write_to_hugetlbfs -p "$path" -s "$size" "$write" "$populate" -m "$method" \ +exec ./write_to_hugetlbfs -p "$path" -s "$size" "$write" "$populate" -m "$method" \ "$private" "$want_sleep" "$reserve"Signature · 1 line
2.39.5 (Apple Git-154)
Signature · 2 lines
Sincerely yours, Mike.