linux maximum number of processes modification method
- 2020-09-28 09:18:40
- OfStack
The actual maximum number of system processes is affected by three configuration items:
1, max threads - (/ proc sys/kernel/threads_max)
This value represents the upper limit of the number of system processes determined by physical memory. fork_init has:
max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 8
2, pid_max (/ proc sys/kernel/pid_max)
This value represents the upper limit of process ID. For compatibility with older versions, the default is 32768 (that is, two bytes).
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">echo <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4194303</span> > <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/proc/sys</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/kernel/pid</span>_max</code>
3. RLIMIT_NPROC (ulimit-ES33en or getrlimit)
This value represents the maximum number of processes allowed for a single user. The default of the system is 1/2 of threads-max:
init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
Experiment:
In certain circumstances:
threads - max = 139264;
pid_max = 32768
RLIMIT_NPROC = 69632
1. At this point, the root user keeps creating processes and finally creates about 32378. Considering the original number of processes, it is close to the value of pid_max;
2. When pid_max was changed to 18000, 17,612 processes were finally created;
3. Modified pid_max to 80000, replaced it with ordinary users, and finally created 67,913 processes
conclusion