<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <div class="moz-cite-prefix">On 11/26/2015 03:25 PM, Li Wang wrote:<br>
    </div>
    <blockquote
cite="mid:CAEemH2fxCDRtB7jSazdBjAMzxaK0U2GwNZKLuAq00EDzbW679A@mail.gmail.com"
      type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote"><br>
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div>
                <div>
                  <blockquote class="gmail_quote" style="margin:0px 0px
                    0px 0.8ex;border-left:1px solid
                    rgb(204,204,204);padding-left:1ex">
                    +               tst_brkm(TBROK | TERRNO, cleanup,
                    "Cannot allocate hugepage");<br>
                    +       }<br>
                    +<br>
                    +       for (i = ARSZ - 1; i > 0; i--) {<br>
                  </blockquote>
                  <br>
                </div>
              </div>
              Why this is done in reverse order?<span><br>
              </span></blockquote>
            <div><br>
            </div>
            <div>well, as Jan pointed in the previous comments:<br>
              <br>
              "How about allocating the largest area first and then
              mmaping smaller ones<br>
              on top of it?<br>
              <br>
              That could prevent situation where first smallest area
              mmaps a gap between<br>
              existing libraries/heap/etc. and then larger ones with
              same start overlap<br>
              with those - since we write to those areas, bad things
              could happen."<br>
              <br>
            </div>
            <div>I think that is very clear to describe the potential
              issue. since I run the program on some s390x for many
              times, it is easily to get segment fault. after done in
              reverse order. the error gone. <br>
              <br>
            </div>
            <div>here I print the detailed mapings of the program, it
              show something that.<br>
              -----<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    OK, but I meant that either we need to remove "sz" variable and use
    "i * hpage_size" or<br>
    make it straightforward as "i" doesn't influence on the actual size
    passed to mmap and threads.<br>
    <br>
    So that both of the loops looks the same.<br>
    <br>
    Also to use the full range of declared arrays, we should do as
    follows or declare them as ARSZ - 1:<br>
    <br>
    struct mp mmap_sz[ARSZ];<br>
    pthread_t tid[ARSZ];<br>
    <br>
    sz = ARSZ + 1;<br>
    <br>
    ...<br>
    <br>
    for (i = 0; i < ARSZ; ++i, --sz) {<br>
        mmap_sz[i].sz = sz;<br>
        mmap_sz[i].addr = addr;<br>
        ...<br>
    }<br>
        <br>
    for (i = 0; i < ARSZ; ++i) {<br>
        pthread_join(...);<br>
    }<br>
    <br>
    <blockquote
cite="mid:CAEemH2fxCDRtB7jSazdBjAMzxaK0U2GwNZKLuAq00EDzbW679A@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>Program received signal SIGSEGV, Segmentation fault.<br>
              0x0000004cf80a68b0 in mmap64 () from /lib64/libc.so.6<br>
              (gdb) bt<br>
              #0  0x0000004cf80a68b0 in mmap64 () from /lib64/libc.so.6<br>
              Cannot access memory at address 0x70<br>
              <br>
              <br>
                        Start Addr           End Addr       Size    
              Offset objfile<br>
                        0x80000000         0x80001000    
              0x1000          0                              /root/a.out<br>
                        0x80001000         0x80002000     0x1000    
              0x1000                              /root/a.out<br>
                        0xb7a9b000         0xb7abc000   
              0x21000          0                                  
              [heap]<br>
                      0x4cf7f73000       0x4cf7f94000   
              0x21000          0                         /lib64/<a
                moz-do-not-send="true" href="http://ld-2.12.so">ld-2.12.so</a><br>
                      0x4cf7f94000       0x4cf7f95000     0x1000   
              0x20000                         /lib64/<a
                moz-do-not-send="true" href="http://ld-2.12.so">ld-2.12.so</a><br>
                      0x4cf7f95000       0x4cf7f96000     0x1000   
              0x21000                         /lib64/<a
                moz-do-not-send="true" href="http://ld-2.12.so">ld-2.12.so</a><br>
                      0x4cf7f96000       0x4cf7f97000    
              0x1000          0        <br>
                      0x4cf7f9d000       0x4cf814d000  
              0x1b0000          0                         /lib64/<a
                moz-do-not-send="true" href="http://libc-2.12.so">libc-2.12.so</a><br>
                      0x4cf814d000       0x4cf8151000     0x4000  
              0x1af000                         /lib64/<a
                moz-do-not-send="true" href="http://libc-2.12.so">libc-2.12.so</a><br>
                      0x4cf8151000       0x4cf8152000     0x1000  
              0x1b3000                         /lib64/<a
                moz-do-not-send="true" href="http://libc-2.12.so">libc-2.12.so</a><br>
                      0x4cf8152000       0x4cf8157000    
              0x5000          0        <br>
                      0x4cf8159000       0x4cf8176000   
              0x1d000          0                         /lib64/<a
                moz-do-not-send="true" href="http://libpthread-2.12.so">libpthread-2.12.so</a><br>
                      0x4cf8176000       0x4cf8177000     0x1000   
              0x1c000                         /lib64/<a
                moz-do-not-send="true" href="http://libpthread-2.12.so">libpthread-2.12.so</a><br>
                      0x4cf8177000       0x4cf8178000     0x1000   
              0x1d000                         /lib64/<a
                moz-do-not-send="true" href="http://libpthread-2.12.so">libpthread-2.12.so</a><br>
              <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"><span>
                <br>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  +               mmap_sz[i].sz = sz;<br>
                  +               mmap_sz[i].addr = addr;<br>
                  +<br>
                  +               TEST(pthread_create(tid + i, NULL,
                  thr, &mmap_sz[i]));<br>
                </blockquote>
                <br>
              </span>
              This is not right, use tid[i] ( = tid + sizeof(pthread_t)
              * i), not tid + i.<span><br>
              </span></blockquote>
            <div><br>
              sorry, probably you want say this:<br>
              <br>
                      (pthread_t *)((char *)tid + sizeof(pthread_t) * i)<br>
              <br>
              but I think the original way is right.<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Yes, you are right, sorry for misleading you.<br>
    <br>
    I would recommend to use the same style in one function, so<br>
    <br>
    <span>TEST(pthread_create(tid + i, NULL, thr, mmap_sz + i));<br>
      or </span><br>
    <span>TEST(pthread_create(&tid[i], NULL, thr, &mmap_sz[i]));<br>
      <br>
      <br>
    </span>
    <blockquote
cite="mid:CAEemH2fxCDRtB7jSazdBjAMzxaK0U2GwNZKLuAq00EDzbW679A@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>-----------<br>
              # cat a.c <br>
              #include <stdio.h><br>
              int main()<br>
              {<br>
                  int a[2];<br>
              <br>
                  *a = 'a';<br>
                  *(a + 1) = 'b';<br>
              <br>
                  printf("a[1] = %d\n", a[1]);<br>
              <br>
                  printf("&a[0] = %p\n", a);<br>
                  printf("&a[1] = %p\n", a + 1);<br>
              }<br>
              <br>
              --------<br>
              # ./a.out <br>
              a[1] = 98<br>
              &a[0] = 0x3ffffe25f18<br>
              &a[1] = 0x3ffffe25f1c<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"><span>
                <br>
              </span><br>
              <span>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  +       }<br>
                  +<br>
                  +       for (++i; i < ARSZ; i++) {<br>
                </blockquote>
                <br>
              </span>
              Could you initialize "i" here explicitly?</blockquote>
            <div> </div>
            <div>ok, no problem.<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">
              <div>
                <div><br>
                  <blockquote class="gmail_quote" style="margin:0px 0px
                    0px 0.8ex;border-left:1px solid
                    rgb(204,204,204);padding-left:1ex">
                    +       cleanup();<br>
                    +       tst_exit();<br>
                  </blockquote>
                  <br>
                </div>
              </div>
              Isn't tst_exit() calling cleanup?<br>
            </blockquote>
            <div><br>
            </div>
            <div>hmm, I checked the /lib/tst_res.c and got the function:<br>
              <br>
              ----<br>
              void tst_exit(void)<br>
              {<br>
                  pthread_mutex_lock(&tmutex);<br>
              <br>
              #if DEBUG<br>
                  printf("IN tst_exit\n");<br>
                  fflush(stdout);<br>
                  fflush(stdout);<br>
              #endif<br>
              <br>
                  /* Call tst_flush() flush any output in the buffer. */<br>
                  tst_flush();<br>
              <br>
                  /* Mask out TINFO result from the exit status. */<br>
                  exit(T_exitval & ~TINFO);<br>
              }<br>
              <br>
            </div>
            <div>I didn't saw there anyplace call the cleanup()
              function. :(<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Right, I've read the mail thread recently about changing cleanup()
    to be declared as a signal handler before<br>
    and somehow thought it is already implemented in LTP...<br>
    <br>
    Thanks,<br>
    Alexey<br>
    <br>
  </body>
</html>