All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] move_pages12: handle errno EBUSY for madvise(..., MADV_SOFT_OFFLINE)
Date: Fri, 26 Jul 2019 14:12:55 +0200	[thread overview]
Message-ID: <20190726121255.GA28028@rei.lan> (raw)
In-Reply-To: <20190725033713.8551-1-liwang@redhat.com>

Hi!
>  static void do_test(unsigned int n)
>  {
> -	int i;
> +	int i, ret, retrys;
> +	void *ptr;
>  	pid_t cpid = -1;
>  	int status;
>  	unsigned int twenty_percent = (tst_timeout_remaining() / 5);
> @@ -135,19 +136,37 @@ static void do_test(unsigned int n)
>  	if (cpid == 0)
>  		do_child(tcases[n].tpages);
>  
> -	for (i = 0; i < LOOPS; i++) {
> -		void *ptr;
> +	for (i = 0; i < LOOPS; retrys = 0, i++) {
> +retry:
> +		ptr = mmap(NULL, tcases[n].tpages * hpsz,
> +				PROT_READ | PROT_WRITE,
> +				MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
> +		if (ptr == MAP_FAILED) {
> +			if (errno == ENOMEM) {
> +				if (retrys < LOOPS) {
> +					retrys++;
> +					usleep(1000);
> +					goto retry;
> +				}
> +
> +				if (i > 0) {
> +					tst_res(TINFO, "Test run %d times", i);
> +					goto out;
> +				}
> +			}
> +
> +			tst_brk(TBROK | TERRNO, "Cannot allocate hugepage");
> +		}

Why so complicated?

What about just doing usleep() and continue in case of the failure?


	for (i = 0; i < LOOPS; i++) {
		ptr = mmap(...);
		if (ptr == MAP_FAILED) {
			if (errno == ENOMEM) {
				usleep(1000);
				continue;
			}

			tst_brk(...);
		}

		...
	}


> -		ptr = SAFE_MMAP(NULL, tcases[n].tpages * hpsz,
> -			PROT_READ | PROT_WRITE,
> -			MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
>  		if (ptr != addr)
>  			tst_brk(TBROK, "Failed to mmap at desired addr");
>  
>  		memset(addr, 0, tcases[n].tpages * hpsz);
>  
>  		if (tcases[n].offline) {
> -			if (do_soft_offline(tcases[n].tpages) == EINVAL) {
> +			ret = do_soft_offline(tcases[n].tpages);
> +
> +			if (ret == EINVAL) {
>  				SAFE_KILL(cpid, SIGKILL);
>  				SAFE_WAITPID(cpid, &status, 0);
>  				SAFE_MUNMAP(addr, tcases[n].tpages * hpsz);
> @@ -163,6 +182,7 @@ static void do_test(unsigned int n)
>  			break;
>  	}
>  
> +out:
>  	SAFE_KILL(cpid, SIGKILL);
>  	SAFE_WAITPID(cpid, &status, 0);
>  	if (!WIFEXITED(status))
> -- 
> 2.20.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-07-26 12:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-25  3:37 [LTP] [PATCH v2] move_pages12: handle errno EBUSY for madvise(..., MADV_SOFT_OFFLINE) Li Wang
2019-07-26 12:12 ` Cyril Hrubis [this message]
2019-07-26 13:21   ` Li Wang
2019-07-26 13:31     ` Cyril Hrubis
2019-07-29  4:53       ` Li Wang

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=20190726121255.GA28028@rei.lan \
    --to=chrubis@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.