There is a formula for calculating the maximum number of active PIDs or threads. Excerpt from kernel/fork.c
:
/*
* set_max_threads
*/
static void set_max_threads(unsigned int max_threads_suggested)
{
u64 threads;
/*
* The number of threads shall be limited such that the thread
* structures may only consume a small part of the available memory.
*/
if (fls64(totalram_pages) + fls64(PAGE_SIZE) > 64)
threads = MAX_THREADS;
else
threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
(u64) THREAD_SIZE * 8UL);
if (threads > max_threads_suggested)
threads = max_threads_suggested;
max_threads = clamp_t(u64, threads, MIN_THREADS, MAX_THREADS);
}
However, normally other limits will be hit first. If RAM and other resources last, then some cgroup limits will likely be first, where basically the limit is:
$ cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max
12288
The number, 12288, is the same on both my older 3 gigabyte server and my newer 16 gigabyte server.
And I can test by trying to spin out more than the maximum number, resulting in a message in /var/log/kern.log
:
Feb 12 15:49:11 s15 kernel: [ 135.742278] cgroup: fork rejected by pids controller in /user.slice/user-1000.slice
And checking the number I had at the time:
$ cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.current
12287
top
said about 12479
But after those processes ended, I got:
$ cat /sys/fs/cgroup/pids/user.slice/pids.current
15
top
said about 205, and note: 12479 - 205 + 15 = 12289
or
Cannot fork` or ... once your system has exhausted all available resources. My system seems to do this around 12479 tasks (for sudo or normal). – Doug Smythies Feb 12 '17 at 19:52ulimit -a
. – Doug Smythies Feb 13 '17 at 15:03max user processes (-u) 7982
, does that means thats the max for user root only? – MohammedSimba Feb 14 '17 at 17:17