title: Processes exceeding thread stack size limit on RedHat Enterprise Linux 6?
body: <p>I have a couple of processes running on RHEL 6.3, but for some reason they are exceeding the thread stack sizes. </p>
  
  <p>For example, the Java process is given the stack size of -Xss256k at runtime on startup, and the C++ process is given a thread stack size of 1MB using pthread_attr_setstacksize() in the actual code.</p>
  
  <p>For some reason however, these processes are not sticking to these limits, and I'm not sure why.</p>
  
  <p>For example, when I run</p>
  
  <pre><code>pmap -x &lt;pid&gt; 
  </code></pre>
  
  <p>for the C++ and Java process, I can see hundreds of 'anon' threads for each (which I have confirmed are the internal worker threads created by each of these processes), but these have an allocated value of 64MB each, not the limits set above:</p>
  
  <pre><code>00007fa4fc000000 168 40 40 rw--- [ anon ] 
  00007fa4fc02a000 65368 0 0 ----- [ anon ] 
  00007fa500000000 168 40 40 rw--- [ anon ] 
  00007fa50002a000 65368 0 0 ----- [ anon ] 
  00007fa504000000 168 40 40 rw--- [ anon ] 
  00007fa50402a000 65368 0 0 ----- [ anon ] 
  00007fa508000000 168 40 40 rw--- [ anon ] 
  00007fa50802a000 65368 0 0 ----- [ anon ] 
  00007fa50c000000 168 40 40 rw--- [ anon ] 
  00007fa50c02a000 65368 0 0 ----- [ anon ] 
  00007fa510000000 168 40 40 rw--- [ anon ] 
  00007fa51002a000 65368 0 0 ----- [ anon ] 
  00007fa514000000 168 40 40 rw--- [ anon ] 
  00007fa51402a000 65368 0 0 ----- [ anon ] 
  00007fa518000000 168 40 40 rw--- [ anon ] 
  ...
  </code></pre>
  
  <p>But when I run the following on the above process with all the 64MB 'anon' threads</p>
  
  <pre><code>cat /proc/&lt;pid&gt;/limits | grep stack 
  
  Max stack size 1048576 1048576 bytes 
  </code></pre>
  
  <p>it shows a max thread stack size of 1MB, so am a bit confused as to what is going on here. Also, the script that calls these programs sets 'ulimit -s 1024' as well.</p>
  
  <p>It should be noted that this only seems to occur when using a very high end machines (e.g. 48GB RAM, 24 CPU cores). The issue does not appear on less powerful machines (e.g. 4GB RAM, 2 CPU cores).</p>
  
  <p>Any help understanding what is happening here would be much appreciated.</p>