More threads

Greg Lewis glewis at
Tue Dec 6 15:18:29 PST 2005

On Tue, Dec 06, 2005 at 06:33:31PM +0800, David Xu wrote:
> Michael Vince wrote:
> >But I just can't seem to get past that mark, I have a lot of memory 
> >currently the Tomcat is allocated 2gigs of memory.
> Number of threads you can create if you use libthr is limited by
> following factors:
> 1) sysctl:
> kern.threads.max_threads_per_proc
> kern.threads.max_groups_per_proc
> 2) stack
> per-thread userland stack, default number on 64 bits platform is 2M,
> on 32 bits platform, it is 1M. I don't know whether java supports
> adjusting default per-thread stack size. if can not, we may add
> an environment variable to thread libraries, for example:
> LIBPTHREAD_THREAD_STACKSIZE allows user to set default stack size.
> Thread also needs a kernel mode stack when it is in kernel, if
> I am right, it is 16K bytes per-thread. if you create too many
> threads, make sure both side won't exhaust address space, and
> because kernel stack can not be swapped out when process is
> running, you'd make sure physical memory can not be exhausted.
> 3) check memory limits
> type limits command:
> Resource limits (current):
>   cputime          infinity secs
>   filesize         infinity kB
>   datasize           524288 kB
>   stacksize           65536 kB
>   coredumpsize     infinity kB
>   memoryuse        infinity kB
>   memorylocked     infinity kB
>   maxprocesses         5547
>   openfiles           11095
>   sbsize           infinity bytes
>   vmemoryuse       infinity kB
> if address space is not large enough, you have to reconfigure kernel
> to allow larger space. Fix me if I am wrong.

I think that Michael's real problem is the amount of memory he has
allocated.  If he has 2GB allocated already then he is out of luck if
he needs to allocate more (e.g. to create another thread).  See mmap(2),
particularly the BUGS section.

Greg Lewis                          Email   : glewis at
Eyes Beyond                         Web     :
Information Technology              FreeBSD : glewis at

More information about the freebsd-threads mailing list