public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH] selftests: mm: stop relying on killall in charge_reserved_hugetlb
@ 2026-04-05 21:31 CaoRuichuang
  2026-04-09 10:48 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: CaoRuichuang @ 2026-04-05 21:31 UTC (permalink / raw)
  To: akpm, david
  Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, shuah, linux-mm,
	linux-kselftest, linux-kernel, CaoRuichuang

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.

Signed-off-by: CaoRuichuang <create0818@163.com>
---
 .../selftests/mm/charge_reserved_hugetlb.sh   | 25 +++++++++++++++----
 .../selftests/mm/write_hugetlb_memory.sh      |  2 +-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
index 447769657..757df4878 100755
--- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
+++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
@@ -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
 
diff --git a/tools/testing/selftests/mm/write_hugetlb_memory.sh b/tools/testing/selftests/mm/write_hugetlb_memory.sh
index 3d2d2eb9d..49164bbfc 100755
--- a/tools/testing/selftests/mm/write_hugetlb_memory.sh
+++ b/tools/testing/selftests/mm/write_hugetlb_memory.sh
@@ -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"
-- 
2.39.5 (Apple Git-154)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: mm: stop relying on killall in charge_reserved_hugetlb
  2026-04-05 21:31 [PATCH] selftests: mm: stop relying on killall in charge_reserved_hugetlb CaoRuichuang
@ 2026-04-09 10:48 ` Mike Rapoport
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2026-04-09 10:48 UTC (permalink / raw)
  To: CaoRuichuang
  Cc: akpm, david, ljs, Liam.Howlett, vbabka, surenb, mhocko, shuah,
	linux-mm, linux-kselftest, linux-kernel

Hi,

On Mon, Apr 06, 2026 at 05:31:26AM +0800, CaoRuichuang wrote:
> 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".

Can't we just skip the test if killall is not available just like we skip
it if it's not run as root?

> 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.
> 
> Signed-off-by: CaoRuichuang <create0818@163.com>
> ---
>  .../selftests/mm/charge_reserved_hugetlb.sh   | 25 +++++++++++++++----
>  .../selftests/mm/write_hugetlb_memory.sh      |  2 +-
>  2 files changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> index 447769657..757df4878 100755
> --- a/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> +++ b/tools/testing/selftests/mm/charge_reserved_hugetlb.sh
> @@ -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
>  
> diff --git a/tools/testing/selftests/mm/write_hugetlb_memory.sh b/tools/testing/selftests/mm/write_hugetlb_memory.sh
> index 3d2d2eb9d..49164bbfc 100755
> --- a/tools/testing/selftests/mm/write_hugetlb_memory.sh
> +++ b/tools/testing/selftests/mm/write_hugetlb_memory.sh
> @@ -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"
> -- 
> 2.39.5 (Apple Git-154)
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-09 10:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-05 21:31 [PATCH] selftests: mm: stop relying on killall in charge_reserved_hugetlb CaoRuichuang
2026-04-09 10:48 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox