public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ritesh Kumar <digitalove@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: NPTL: stack limit limiting number of threads
Date: Fri, 13 May 2005 20:02:48 -0400	[thread overview]
Message-ID: <fc67f8b705051317023859c443@mail.gmail.com> (raw)
In-Reply-To: <20050513202346.GG17420@devserv.devel.redhat.com>

On 5/13/05, Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, May 13, 2005 at 03:49:48PM -0400, Ritesh Kumar wrote:
> > However, I was most amazed to see that the limit on stack size on
> > FreeBSD (5.3 Release) was 64M by default! I was just wondering, how is
> > FreeBSD able to create about a 1000 threads with that kind of a stack
> > limit. Also, is there anything specific in its implementation which
> > makes it difficult to incorporate in Linux? Wouldn't it be a good idea
> > to remove this "trade-off" between stack limit and number of threads
> > and fail thread creation only when we have run out of address space
> > being *actually used* in the stacks in a process.
> 
> On FreeBSD the default thread stack size is not computed from ulimit -s,
> but is constant.  They apparently only recently increased it to 1MB
> (resp. 2MB on 64-bit arches), from 64K.
> 
> On Linux, the default thread stack size (except with fixed stack LinuxThreads)
> is determined from ulimit -s (with a constant default if ulimit -s is
> unlimited).
> 
> If your threaded application has specific needs for stack sizes, it can
> always pthread_attr_setstacksize to whatever you find appropriate.
> 
> The thread library needs to know the stack size limit before creating
> the thread, that can't be changed dynamically.
> 
>         Jakub
> 

Hi Jakub,
    Thanks for your reply. I actually went ahead after getting your
mail and coded up a small program to check the stack limit
deliberately. The program is shown inline.

#include <stdio.h>

#define BUF_SIZE 1024000

void recurse(int n){
	char ch[BUF_SIZE];
	if(n<=0)
		return;
	else
		recurse(n-1);
}

int main(argc, argv)
	int argc;
	char **argv;
{
	if(argc!=2){
		printf("Usage: %s <n (megabytes)>\n", argv[0]);
		return 1;
	}
	printf("Checking for %dMB\n", atoi(argv[1]));
	recurse(atoi(argv[1]));
}

Its a fairly crude way to find out the actual stack limit. Basically,
the resurse function recurses each time allocating ~1MB of space on
the stack. The program segfaults exactly at the ulimit -s value of
stack size on both linux and freebsd. So it does seem that the ulimit
-s is the value of stack limit used on FreeBSD.


Ritesh
-- 
http://www.cs.unc.edu/~ritesh/

  reply	other threads:[~2005-05-14  0:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-13 19:49 NPTL: stack limit limiting number of threads Ritesh Kumar
2005-05-13 20:23 ` Jakub Jelinek
2005-05-14  0:02   ` Ritesh Kumar [this message]
2005-05-14  0:06     ` Jakub Jelinek
2005-05-14  0:53       ` Ritesh Kumar

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=fc67f8b705051317023859c443@mail.gmail.com \
    --to=digitalove@gmail.com \
    --cc=jakub@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh@cs.unc.edu \
    /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