<div dir="ltr">Hi,<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 16, 2015 at 8:12 PM, Jan Stancek <span dir="ltr"><<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5"><br>
<br>
<br>
<br>
----- Original Message -----<br>
> From: "Li Wang" <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>><br>
> To: <a href="mailto:ltp@lists.linux.it">ltp@lists.linux.it</a><br>
> Sent: Wednesday, 16 September, 2015 11:55:32 AM<br>
> Subject: [LTP] [PATCH v2] lib/mem.c: handle the case oom0{3,  5} exit with 'EAGAIN' situation<br>
><br>
> v1 --> v2<br>
>       1. limited the number of loops<br>
>       2. added the usleep(300) to wait resource freed<br>
><br>
> Sometimes oom0{3,5} failed as the following results:<br>
><br>
> oom05       0  TINFO  :  start OOM testing for mlocked pages.<br>
> oom05       0  TINFO  :  expected victim is 3371.<br>
> oom05       0  TINFO  :  thread (3fff788ff1c0), allocating 3221225472 bytes.<br>
> ...<br>
> oom05       5  TFAIL  :  mem.c:153: victim unexpectedly ended with retcode:<br>
> 11, expected: 12<br>
><br>
> In the OOM test, that tries to consume all memory. But the test doesn't retry<br>
> to mlock, it simply<br>
> exits with errno returned by mlock. At the moment testcase is expecting<br>
> either ENOMEM or getting<br>
> killed by kernel.<br>
><br>
> Here do retry the function if mlock() fail with 'EAGAIN' errno.<br>
><br>
> Signed-off-by: Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>><br>
> ---<br>
>  testcases/kernel/mem/lib/mem.c | 12 ++++++++++--<br>
>  1 file changed, 10 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c<br>
> index 8fe4bf0..b8a55e2 100644<br>
> --- a/testcases/kernel/mem/lib/mem.c<br>
> +++ b/testcases/kernel/mem/lib/mem.c<br>
> @@ -30,6 +30,7 @@ static int alloc_mem(long int length, int testcase)<br>
>  {<br>
>       char *s;<br>
>       long i, pagesz = getpagesize();<br>
> +     int loop = 10;<br>
><br>
>       tst_resm(TINFO, "thread (%lx), allocating %ld bytes.",<br>
>               (unsigned long) pthread_self(), length);<br>
> @@ -39,8 +40,15 @@ static int alloc_mem(long int length, int testcase)<br>
>       if (s == MAP_FAILED)<br>
>               return errno;<br>
><br>
> -     if (testcase == MLOCK && mlock(s, length) == -1)<br>
> -             return errno;<br>
> +     if (testcase == MLOCK) {<br>
> +             while (mlock(s, length) == -1 && loop > 0) {<br>
> +                     if (EAGAIN != errno)<br>
> +                             return errno;<br>
> +                     usleep(300);<br>
<br>
</div></div>usleep is in microseconds, so this wouldn't give system much time.<br></blockquote><div><br></div><div>Hmm, it has 10 times to attempt.  Anyway, Feel free to modify the time to a proper size.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Other than that it looks good to me.<br></blockquote><div><br></div><div>Thanks.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Regards,<br>
Jan<br>
<div class=""><div class="h5"><br>
> +                     loop--;<br>
> +             }<br>
> +     }<br>
> +<br>
>  #ifdef HAVE_MADV_MERGEABLE<br>
>       if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)<br>
>               return errno;<br>
> --<br>
> 1.8.3.1<br>
><br>
><br>
> --<br>
> Mailing list info: <a href="http://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">http://lists.linux.it/listinfo/ltp</a><br>
><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Regards,<br></div>Li Wang<br></div><div>Email: <a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a><br></div></div></div></div></div></div>
</div></div>