From: Li Wang <li.wang@linux.dev>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 1/2] shell: add optional OOM protection
Date: Sat, 1 Aug 2026 19:48:54 +0800 [thread overview]
Message-ID: <am3dJgE_4tMWnsh1@linux.dev> (raw)
In-Reply-To: <20260730-shell_oom_protection-v2-1-be1de2baa83d@suse.com>
Andrea Cervesato wrote:
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -28,6 +28,57 @@ export TST_USR_GID="${LTP_USR_GID:-65534}"
> trap "tst_brk TBROK 'test interrupted'" INT
> trap "unset _tst_setup_timer_pid; tst_brk TBROK 'test terminated'" TERM
>
> +_tst_set_oom_score_adj()
> +{
> + local value="$1"
> + local path="/proc/self/oom_score_adj"
> +
> + [ -e "$path" ] || return 0
> +
> + echo "$value" > "$path" 2>/dev/null || return 0
> +}
> +
> +_tst_enable_oom_protection()
> +{
> + _tst_set_oom_score_adj -1000
> +}
> +
> +_tst_disable_oom_protection()
> +{
> + _tst_set_oom_score_adj 0
> +}
> +
> +_tst_run_oom_protected()
> +{
> + local _tst_pid
> + local _tst_ret
> +
> + # Shield the harness from the OOM killer and run the test in a child.
> + # The child keeps the default oom_score_adj so that it, and any process
> + # it spawns, stay killable under memory pressure while the harness
> + # survives to report results.
> + _tst_enable_oom_protection
> +
> + (
> + _tst_disable_oom_protection
> + _TST_OOM_PROTECTION=0
> + export _TST_OOM_PROTECTION
> + tst_run "$@"
> + ) &
> + _tst_pid=$!
> +
> + wait "$_tst_pid"
> + _tst_ret=$?
> +
> + if [ "$_tst_ret" -eq 137 ]; then
> + tst_res TINFO "Test was SIGKILLed: OOM killer or timeout?"
> + tst_res TINFO "On a slow machine try exporting LTP_TIMEOUT_MUL > 1"
> + tst_brk TBROK "Test killed!"
> + fi
> +
> + exit "$_tst_ret"
> +}
> +
> _tst_do_cleanup()
> {
> if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$LTP_NO_CLEANUP" ]; then
> @@ -680,12 +731,16 @@ tst_run()
> local _tst_pattern='[='\''"} \t\/:`$\;|].*'
> local ret
>
> + if [ "$TST_OOM_PROTECTION" = 1 -a "$_TST_OOM_PROTECTION" != 0 ]; then
> + _tst_run_oom_protected "$@"
> + fi
In the C library, OOM protection for the LTP library and harness
is enabled by default. But in such Shell implementation, we have to
explicitly enable it via 'TST_OOM_PROTECTION=1'.
If we keep them consistent and remove the TST_OOM_PROTECTION
variable, things will become easier I guess :).
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-08-01 11:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 13:05 [LTP] [PATCH v2 0/2] OOM protection for shell tests Andrea Cervesato
2026-07-30 13:05 ` [LTP] [PATCH v2 1/2] shell: add optional OOM protection Andrea Cervesato
2026-07-30 14:10 ` [LTP] " linuxtestproject.agent
2026-07-31 13:03 ` [LTP] [PATCH v2 1/2] " Petr Vorel
2026-08-01 11:48 ` Li Wang [this message]
2026-08-01 12:04 ` Li Wang
2026-07-30 13:05 ` [LTP] [PATCH v2 2/2] memcg_stress: survive OOM by targeting the stressors Andrea Cervesato
2026-07-30 13:06 ` [LTP] [PATCH v2 0/2] OOM protection for shell tests Andrea Cervesato via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=am3dJgE_4tMWnsh1@linux.dev \
--to=li.wang@linux.dev \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox