Method to calculate user space thread size
Dear All, I have very complex user space application contain more then 400 threads. I want to limit the stack size in user space, for this I want to know how much stack size each thread use in worst case. To calculate this is I need to modify in kernel ? or current kernel have any support ? or is there a method I can get from smaps? Thanks
On Tue, Apr 2, 2013 at 7:55 PM, naveen yadav <yad.naveen@gmail.com> wrote:
Dear All,
I have very complex user space application contain more then 400 threads. I want to limit the stack size in user space, for this I want to know how much stack size each thread use in worst case.
To calculate this is I need to modify in kernel ? or current kernel have any support ? or is there a method I can get from smaps?
try to check /proc/<pid>/status on VmStk line. But IMHO that indicates the whole stack size (sum of all thread's stack size). BTW, sure what you want to do is safe? what if you miscalculate it? Certainly your application would crash some ways. So, maybe you need other workaround. If you need to reserve memory, perhaps what you need to do is doing malloc() wisely. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
On Tue, Apr 2, 2013 at 6:25 PM, naveen yadav <yad.naveen@gmail.com> wrote:
Dear All,
I have very complex user space application contain more then 400 threads. I want to limit the stack size in user space, for this I want to know how much stack size each thread use in worst case.
Well, this does not answer your question directly and is not related to the kernel but I want to suggest something. I have been using the Go programming language from Google for a few days and it allows you to spawn goroutines, which are similar to threads. But the underlying implementation does not create an OS thread for each go routine. As a result, your application can have thousands of goroutines. This model of threading was implemented so that thread space is not exhausted. You can consider using Go (or any other such lightweight threading library) if you need a lot of threads. Sorry if it is not useful. Sankar http://psankar.blogspot.com
Thanks for answer, I will explain bit more to explain my situation. I have code written, and I cannot modify. I want to fix user stack size for all threads in glibc, once I know how much stack size each thread take. Thanks On Wed, Apr 3, 2013 at 11:37 AM, Sankar P <sankar.curiosity@gmail.com>wrote:
On Tue, Apr 2, 2013 at 6:25 PM, naveen yadav <yad.naveen@gmail.com> wrote:
Dear All,
I have very complex user space application contain more then 400 threads. I want to limit the stack size in user space, for this I want to know how much stack size each thread use in worst case.
Well, this does not answer your question directly and is not related to the kernel but I want to suggest something.
I have been using the Go programming language from Google for a few days and it allows you to spawn goroutines, which are similar to threads. But the underlying implementation does not create an OS thread for each go routine. As a result, your application can have thousands of goroutines. This model of threading was implemented so that thread space is not exhausted. You can consider using Go (or any other such lightweight threading library) if you need a lot of threads.
Sorry if it is not useful.
Sankar http://psankar.blogspot.com
On Tue, 02 Apr 2013, naveen yadav wrote:
Dear All,
I have very complex user space application contain more then 400 threads. I want to limit the stack size in user space, for this I want to know how much stack size each thread use in worst case.
To calculate this is I need to modify in kernel ? or current kernel have any support ? or is there a method I can get from smaps?
I wouldn't go over the kernel in this case - mainly because I don't know where to look for the information. The easiest way I can think of, is to add some assembly to sensible points in your program. "Sensible points" would be end points of possibly long call chains - because you want to get the stack pointer of the highest possible stack frame of each thread. Then simply subtract the maximum of these values from the stack starting address (you may want to disable ASLR). On x86_64 I'd do it like: __thread void *highest = (void *) -1; register void *rsp asm("rsp"); /* * Note that the highest stack frame has the lowest address. */ #define CHECK_HIGHEST() (highest = rsp < highest ? rsp : highest) You have, nevertheless, the difficulty to ensure that the threads really never exceed the maximum you obtained which is IMHO the really difficult part here ;-) Regards, Tobi
participants (5)
-
Mulyadi Santosa -
naveen yadav -
Sankar P -
Tobias Boege -
Valdis.Kletnieks@vt.edu