Re: Stack consumption in NPTL



Chetan <chetanaru@xxxxxxxxx> writes:
We have an application which creates multiple threads and has some
logging mechanism. We observed that the application crashes when
using NPTL but works just fine with LinuxThreads. The stack trace
analysis revealed that the crash is due to smaller stack size. We
are setting the stack size to 16K through the program
using pthread_attr_setstacksize() function. Increasing the stack
size to 128K did not reproduce the crash.

Is there a particular why you are creating threads with less room for
stack growth than they need?

What should be the stack size for the threads in NPTL?

By default, NPTL will reserve 8M of virtual address space per
thread. Memory will be allocated to the stack of each thread as
needed, so, unless you are creating a large number of threads, why not
just stick with the default? Otherwise, why not be somewhat more
careful wrt to reducing the size? Unless you restructure the program,
it will not work with less stack than it needs, anyway.

Since the compiler hasn't changed, the amount of stack space used per
subroutine should be the same. Presumably, NPTL puts some amount of
'thread management data' onto the stack of each thread.
U. Drepper's 'outdated' NPTL design paper states that:

5.6 Memory Allocation

One of the goals for the library is to have low startup costs
for threads. The biggest problem time-wise outside the kernel
is the memory needed for the thread data structures,
thread-local storage, and the stack. Optimizing the memory
allocation is done in two steps:

· The necessary memory blocks are merged. I.e., the thread
data structures and the thread-local storage are placed on the
stack. The usable stack array starts just below (or above in case
of an upward growing stack) the memory needed for the two.

[p. 9, http://people.redhat.com/drepper/nptl-design.pdf]

which suggests that there actually has been such a change.
.



Relevant Pages

  • Stack consumption in NPTL
    ... We observed that the application crashes when ... The stack trace analysis revealed that the crash is due to smaller ... NPTL with respect to stack size, ... void call_my_sprintf ...
    (comp.os.linux.development.apps)
  • Stack Size in NPTL
    ... The stack trace analysis revealed that the crash is due to smaller ... Increasing the stack size to 128K did not reproduce the crash. ... NPTL with respect to stack size, ... void call_my_sprintf ...
    (comp.programming.threads)
  • Re: reset memory size
    ... I have a program whose data structures probably need a good ... > size of memory to run, and when I declare the objects to the size I need ... Allocate on the heap rather than the stack? ... Tim Ward ...
    (microsoft.public.vc.mfc)
  • Re: controlling stack size in RHEL 3.0 pthreads
    ... smaller stack space. ... hardware designs in C++ for those of you familiar ... NPTL and LinuxThread's versions of pthreads? ... You probably have a bug in your program (or request illegal stack ...
    (comp.programming.threads)
  • Re: Stack consumption in NPTL
    ... NPTL but works just fine with LinuxThreads. ... The stack trace analysis revealed that the crash is due to smaller ... Increasing the stack size to 128K did not reproduce the crash. ... NPTL with respect to stack size, ...
    (comp.os.linux.development.apps)