What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
To set permanently,
and add
Use
nbio
non-blocking i/o library or whatever, if you need more threads for doing I/O calls that blockTo retrieve it:
To set it:
123456789 = # of threads
For anyone looking at this now, on systemd systems (in my case, specifically Ubuntu 16.04) there is another limit enforced by the cgroup pids.max parameter.
This is set to 12,288 by default, and can be overriden in /etc/systemd/logind.conf
Other advice still applies including pids_max, threads-max, max_maps_count, ulimits, etc.
Thread count limit:
How it is calculated:
and: x86_64 page size (PAGE_SIZE) is 4K; Like all other architectures, x86_64 has a kernel stack for every active thread. These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big;
for mempages :
so actually the number is not related with limitation of thread memory stack size (
ulimit -s
).P.S: thread memory stack limitation is 10M in my rhel VM, and for 1.5G memory, this VM can only afford 150 threads?
You can see the current value by the following command- cat /proc/sys/kernel/threads-max
You can also set the value like
echo 100500 > /proc/sys/kernel/threads-max
The value you set would be checked against the available RAM pages. If the thread structures occupies more than 1/8th) of the available RAM pages, thread-max would be reduced accordingly.