All of lore.kernel.org
 help / color / mirror / Atom feed
* Method to calculate user space thread size
@ 2013-04-02 12:55 naveen yadav
  2013-04-03  5:36 ` Mulyadi Santosa
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: naveen yadav @ 2013-04-02 12:55 UTC (permalink / raw)
  To: kernelnewbies

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130402/31558081/attachment.html 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Method to calculate user space thread size
  2013-04-02 12:55 Method to calculate user space thread size naveen yadav
@ 2013-04-03  5:36 ` Mulyadi Santosa
  2013-04-03  6:07 ` Sankar P
  2013-04-03 13:38 ` Tobias Boege
  2 siblings, 0 replies; 6+ messages in thread
From: Mulyadi Santosa @ 2013-04-03  5:36 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Method to calculate user space thread size
  2013-04-02 12:55 Method to calculate user space thread size naveen yadav
  2013-04-03  5:36 ` Mulyadi Santosa
@ 2013-04-03  6:07 ` Sankar P
  2013-04-03  8:33   ` naveen yadav
  2013-04-03 13:38 ` Tobias Boege
  2 siblings, 1 reply; 6+ messages in thread
From: Sankar P @ 2013-04-03  6:07 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Method to calculate user space thread size
  2013-04-03  6:07 ` Sankar P
@ 2013-04-03  8:33   ` naveen yadav
  2013-04-03 13:16     ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 6+ messages in thread
From: naveen yadav @ 2013-04-03  8:33 UTC (permalink / raw)
  To: kernelnewbies

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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130403/59fe3183/attachment.html 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Method to calculate user space thread size
  2013-04-03  8:33   ` naveen yadav
@ 2013-04-03 13:16     ` Valdis.Kletnieks at vt.edu
  0 siblings, 0 replies; 6+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-04-03 13:16 UTC (permalink / raw)
  To: kernelnewbies

On Wed, 03 Apr 2013 14:03:40 +0530, naveen yadav said:

> I have code written, and I cannot modify. I want to fix user stack size for
> all threads in glibc,

'man ulimit'?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130403/d6e971d2/attachment.bin 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Method to calculate user space thread size
  2013-04-02 12:55 Method to calculate user space thread size naveen yadav
  2013-04-03  5:36 ` Mulyadi Santosa
  2013-04-03  6:07 ` Sankar P
@ 2013-04-03 13:38 ` Tobias Boege
  2 siblings, 0 replies; 6+ messages in thread
From: Tobias Boege @ 2013-04-03 13:38 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-03 13:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-02 12:55 Method to calculate user space thread size naveen yadav
2013-04-03  5:36 ` Mulyadi Santosa
2013-04-03  6:07 ` Sankar P
2013-04-03  8:33   ` naveen yadav
2013-04-03 13:16     ` Valdis.Kletnieks at vt.edu
2013-04-03 13:38 ` Tobias Boege

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.