What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
Thread count limit:
$ cat /proc/sys/kernel/threads-max
How it is calculated:
max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
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 :
cat /proc/zoneinfo | grep spanned | awk '{totalpages=totalpages+$2} END {print totalpages}';
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?