Maximum number of threads per process in Linux?

前端 未结 16 2781
轮回少年
轮回少年 2020-11-22 02:16

What is the maximum number of threads that can be created by a process under Linux?

How (if possible) can this value be modified?

16条回答
  •  囚心锁ツ
    2020-11-22 02:33

    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?

提交回复
热议问题