kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: tobias@gambas-buch.de (Tobias Boege)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Method to calculate user space thread size
Date: Wed, 3 Apr 2013 15:38:43 +0200	[thread overview]
Message-ID: <20130403133843.GB1210@aurora> (raw)
In-Reply-To: <CAJ8eaTw+J6TgxeYObPDC4ojOwfH6HvhoF0iXAbg2rNGVwT=9vg@mail.gmail.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

      parent reply	other threads:[~2013-04-03 13:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130403133843.GB1210@aurora \
    --to=tobias@gambas-buch.de \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).