[uClinux-dev] enable /proc/PID/smap

Jamie Lokier jamie at shareable.org
Thu Feb 5 13:13:59 EST 2009

Robert Wessels wrote:
> Just a bit more background on this. As we all know, applications  
> running in a nommu environment have a static stack size. although the  
> maximum stack size is determined by this, the stack usage grows and  
> shrinks. One can imagine that in a certain condition the given  
> application can run out of stack. Hence one needs to grow the stack  
> either by recompiling the application or by use of flthdr (I believe).

Threaded applications use an additional stack per thread, and possibly
one more for the master thread with pre-NPTL LinuxThreads.

What's more, the thread stack sizes are not determined by flthdr, and
they can be different per thread.  I've had to use this with threaded
'rsync', for example, because the thread stack size was too small,
even if I set a large stack size with flthdr.

> Rather than a trial and error way of doing this I am looking into  
> writing a tool that monitors the applications stack size for a period  
> of time and records the minimum and maximum stack usage. If the output  
> of this shows that the max stack usage comes close to the maximum  
> stack size, allocating a larger stack size is advisable.

That would be really useful.

Perhaps the thing to do is 'red-zone' the stack: during exec, fill the
stack with a byte sequence which is unlikely to be written by the
application itself.  Later, look at the stack to find the first byte
which doesn't match the red-zone pattern, to find how much stack was

Just sampling the stack pointer register on a timer, would miss large
transient stack usages.

You could also look at GCC's options for stack bounds checking, but
that would need the whole application and libraries to be compiled
with it.

-- Jamie

More information about the uClinux-dev mailing list