[LTP] [PATCH v2 2/3] lib: enable OOM protection for the main process

Cyril Hrubis chrubis@suse.cz
Fri Dec 17 15:49:51 CET 2021


Hi!
> Here invoke OOM protection in fork_testrun, since it is the key point
> to distiguish many process branches. We do protect main ($PID) process
> from killing by OOM Killer, hope this can help to get the completed
> correct report for all of LTP tests.
> 
> Fundamental principle:
> 
>                    ltp test harness --> library process
>   (oom protection)   main --> tst_run_tcases --> ... --> fork_testrun
>   (cancel protection)  testrun --> run_tests --> ... --> testname
>                          child_test --> ... --> end
> 
> Signed-off-by: Li Wang <liwang@redhat.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
> 
> Notes:
>     Changes v1->v2:
>         * remove the protection for parent process as suggested by Martin
> 
>  lib/tst_test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index ce2b8239d..0b370e691 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1441,11 +1441,14 @@ static int fork_testrun(void)
>  
>  	SAFE_SIGNAL(SIGINT, sigint_handler);
>  
> +	tst_enable_oom_protection(getpid());
> +
>  	test_pid = fork();
>  	if (test_pid < 0)
>  		tst_brk(TBROK | TERRNO, "fork()");
>  
>  	if (!test_pid) {
> +		tst_cancel_oom_protection(getpid());
>  		SAFE_SIGNAL(SIGALRM, SIG_DFL);
>  		SAFE_SIGNAL(SIGUSR1, SIG_DFL);
>  		SAFE_SIGNAL(SIGINT, SIG_DFL);

The fork_testrun() function is called in a loop, it would be a bit
cleaner to put the tst_enable_protection() call to the tst_run_tcases()
instead since we don't have to enable it over and over.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list