How do I know my application's stack size?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux All

Issue

  • My application caused stack overflow to happen due to its recursive function and huge dataset.
  • Through some research I found the resource limit of 10MB for stack in limits.conf was too small for the application.
  • After resrtarting the application after changing stack limit to some larger value, the issue has gone away.
  • However I still doubt if it is unnecessarily too large.
  • How do I know how much stack the application uses?

Resolution

  • You can see how much stack space the application uses looking at /proc/PID/maps.
  • Please note "PID" means the process ID of the running application.
  • Here you can see the application is using about 11GB of stack in the following example output:
# cat /proc/<PID>/maps

00400000-00401000 r-xp 00000000 fd:00 925451                             /tmp/work-stack/stack.out
00600000-00601000 rw-p 00000000 fd:00 925451                             /tmp/work-stack/stack.out
2aaaaaaab000-2aaaaaacb000 r-xp 00000000 fd:00 21                         /lib64/ld-2.12.so
2aaaaaacb000-2aaaaaacc000 r-xp 00000000 00:00 0                          [vdso]
2aaaaaacc000-2aaaaaacd000 rw-p 00000000 00:00 0 
2aaaaacca000-2aaaaaccb000 r--p 0001f000 fd:00 21                         /lib64/ld-2.12.so
2aaaaaccb000-2aaaaaccc000 rw-p 00020000 fd:00 21                         /lib64/ld-2.12.so
2aaaaaccc000-2aaaaaccd000 rw-p 00000000 00:00 0 
2aaaaaccd000-2aaaaae58000 r-xp 00000000 fd:00 28                         /lib64/libc-2.12.so
2aaaaae58000-2aaaab057000 ---p 0018b000 fd:00 28                         /lib64/libc-2.12.so
2aaaab057000-2aaaab05b000 r--p 0018a000 fd:00 28                         /lib64/libc-2.12.so
2aaaab05b000-2aaaab05c000 rw-p 0018e000 fd:00 28                         /lib64/libc-2.12.so
2aaaab05c000-2aaaab063000 rw-p 00000000 00:00 0 
7ffd43de6000-7ffffffff000 rw-p 00000000 00:00 0                          [stack]  <<<-----------------
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

(gdb) p/d (0x7ffffffff000-0x7ffd43de6000)
$2 = 11746250752 <<--- About 11 GB

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments