title: mmap2 fails to allocate a stack for a thread, but works under GDB
body: <p>I am running application on ARMv7-A machine with Fedora 18, 2GB of RAM.</p>
  
  <p>The application terminates:</p>
  
  <pre><code>130413 15:49:34 19344 Xrd: PhyConnection: Can't run reader thread: out of system resources. Critical error.
  </code></pre>
  
  <p>If I <code>strace</code> that, I see that allocation of stack fails for a new thread:</p>
  
  <pre><code>mmap2(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = -1 ENOMEM (Cannot allocate memory)
  gettimeofday({1365921367, 588018}, NULL) = 0
  gettid()                                = 6309
  writev(2, [{"130414 02:36:07 6309 ", 21}, {"Xrd", 3}, {"", 0}, {": ", 2}, {"PhyConnection: Can't run reader "..., 80}, {"\n", 1}], 6130414 02:36:07 6309 Xrd: PhyConnection: Can't ru
  n reader thread: out of system resources. Critical error.
  ) = 107
  munmap(0x48172000, 292)                 = 0
  munmap(0x48225000, 292)                 = 0
  </code></pre>
  
  <p>Actual code:</p>
  
  <pre><code>253       if (fReaderthreadhandler[i]-&gt;Run(this)) {
  254          Error("PhyConnection",
  255                "Can't run reader thread: out of system resources. Critical error.");
  256 // HELP: what do we do here
  257          exit(-1);
  258       }
  </code></pre>
  
  <p>The application had 300-350MB in virtual memory size, and ~250MB is resident memory size. High memory limitation is 1.3GB. Virtual address space is not limited:</p>
  
  <pre><code>-t: cpu time (seconds)              unlimited
  -f: file size (blocks)              unlimited
  -d: data seg size (kbytes)          unlimited
  -s: stack size (kbytes)             8192
  -c: core file size (blocks)         0
  -m: resident set size (kbytes)      unlimited
  -u: processes                       1024
  -n: file descriptors                1024
  -l: locked-in-memory size (kbytes)  64
  -v: address space (kbytes)          unlimited
  -x: file locks                      unlimited
  -i: pending signals                 15870
  -q: bytes in POSIX msg queues       819200
  -e: max nice                        0
  -r: max rt priority                 0
  -N 15:                              unlimited
  </code></pre>
  
  <p>But it does work from GDB! I also looked what limits are reported from GDB and they are the same. Thus GDB does not adjust soft limits, which would be inherited.</p>
  
  <p>Summary:</p>
  
  <ul>
  <li>I have enough memory to run the application. It even works fine inside GDB.</li>
  <li>It doesn't seem that it hit any of the resource limits.</li>
  <li>Works in GDB, but not outside.</li>
  </ul>
  
  <p>Any hints of what could be wrong here?</p>