Maximum number of threads per process in Linux?

前端 未结 16 2829
轮回少年
轮回少年 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

    @dragosrsupercool

    Linux doesn't use the virtual memory to calculate the maximum of thread, but the physical ram installed on the system

     max_threads = totalram_pages / (8 * 8192 / 4096);
    

    http://kavassalis.com/2011/03/linux-and-the-maximum-number-of-processes-threads/

    kernel/fork.c

    /* The default maximum number of threads is set to a safe
     * value: the thread structures can take up at most half
     * of memory.
     */
    max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
    

    So thread max is different between every system, because the ram installed can be from different sizes, I know Linux doesn't need to increase the virtual memory, because on 32 bit we got 3 GB for user space and 1 GB for the kernel, on 64 bit we got 128 TB of virtual memory, that happen on Solaris, if you want increase the virtual memory you need to add swap space.

提交回复
热议问题