public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] mtest01 parent/child process synchronization issue
Date: Mon, 23 Nov 2015 11:10:50 +0100	[thread overview]
Message-ID: <5652E62A.3090403@redhat.com> (raw)
In-Reply-To: <564CACAF.1080201@redhat.com>

On 11/18/2015 05:51 PM, Jiri Vohanka wrote:
> Hello,
> 
> I discovered a problem in mtest01 which causes it to freeze on some occasions.

Hi,

> diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c
> index 8c9e81c..06f41d5 100644
> --- a/testcases/kernel/mem/mtest01/mtest01.c
> +++ b/testcases/kernel/mem/mtest01/mtest01.c
> @@ -51,9 +51,12 @@
>  char *TCID = "mtest01";
>  int TST_TOTAL = 1;
>  int pid_count = 0;
> +int oom_count = 0;

both of these should be static

>  
>  void handler(int signo)
>  {
> +	if (signo == SIGCHLD)
> +		oom_count++;
>  	pid_count++;
>  }
>  
> @@ -77,6 +80,7 @@ int main(int argc, char *argv[])
>  	act.sa_flags = 0;
>  	sigemptyset(&act.sa_mask);
>  	sigaction(SIGRTMIN, &act, 0);
> +	sigaction(SIGCHLD, &act, 0);
>  
>  	while ((c = getopt(argc, argv, "c:b:p:wvh")) != -1) {
>  		switch (c) {
> @@ -268,7 +272,7 @@ int main(int argc, char *argv[])
>  
>  			while ((((unsigned long long)pre_mem - post_mem) <
>  				(unsigned long long)original_maxbytes) &&
> -			       pid_count < pid_cntr) {
> +			       pid_count < pid_cntr && !oom_count) {
>  				sleep(1);
>  				sysinfo(&sstats);
>  				post_mem =
> @@ -284,7 +288,9 @@ int main(int argc, char *argv[])
>  			kill(pid_list[i], SIGKILL);
>  			i++;
>  		}
> -		if (dowrite)
> +		if (oom_count)
> +			tst_resm(TFAIL, "the child process was killed");


I wouldn't combine two "if"s into one if else block, the information how
much was allocated could be useful even when we hit OOM.

But mainly, problem here is that ~6 lines above child processes get killed,
so you are racing with SIGCHLD here. I'd suggest to move this TFAIL before
kill() loop.

Regards,
Jan


> +		else if (dowrite)
>  			tst_resm(TPASS, "%llu kbytes allocated and used.",
>  				 original_maxbytes / 1024);
>  		else
> -- 
> 2.4.3



  reply	other threads:[~2015-11-23 10:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18 16:51 [LTP] mtest01 parent/child process synchronization issue Jiri Vohanka
2015-11-23 10:10 ` Jan Stancek [this message]
2015-11-25 10:47   ` Jiri Vohanka
2015-11-26 14:38     ` Jan Stancek
2015-11-26 14:50     ` Cyril Hrubis

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=5652E62A.3090403@redhat.com \
    --to=jstancek@redhat.com \
    --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