Monday, July 16, 2012

Maximum number of processes/threads in Linux

In Linux there are three variables that define how many threads one process can create:
  1. /proc/sys/kernel/threads-max
  2. /proc/sys/kernel/pid_max
  3. /proc/sys/vm/max_map_count

threads-max

Threads max defines how many threads / process can be created (if the other two parameters do not limit it to a lower number). The default value is calculated at boot time as

max_threads = totalram_pages / (8 * THREAD_SIZE / PAGE_SIZE) 

pid_max 

This  setting simply sets the maximum number that can be used a process identifier (pid). Since threads are also processes (Light Weight Processes to be correct) they also use up pids. This means that if the other two parameters are not limiting, this parameter will define the maximum number of threads one can create in the system. Of course, this is a system wide limitation.

Reaching this limit results that the system is not able to clone new processes (whether new process or thread). This leads to unstable system behavior.

 

max_map_count

This parameter sets the maximum number of Virtual Memory Areas (VMAs) that one process can own. VMA is a contiguous area of virtual address space. One can check these areas by cat /proc/PID/maps. Each new thread need new stack, created by calling malloc typically implicitly. These mallocs need these VMAs to be allocated to the process. If the other two parameters are not limiting, this parameter will define the maximum number of threads one process can start. 

More information:

http://www.novell.com/support/kb/doc.php?id=7000830
http://www.redhat.com/magazine/001nov04/features/vm/

No comments:

Post a Comment