Processes and Threads in Linux

Linux /var/log/messages show the following info and the host hung:

automount[4483]: expire_proc: expire thread create for /misc failed
https://access.redhat.com/solutions/147923
Why does a server crash with automount failing to create threads ?

The issue is related to the maximum number of processes respectively the kernel parameter kernel.pid_max

The following is the explanation of pid_max:

/proc/sys/kernel/pid_max (since Linux 2.5.34)
This file specifies the value at which PIDs wrap around (i.e.,
the value in this file is one greater than the maximum PID).
The default value for this file, 32768, results in the same
range of PIDs as on earlier kernels. On 32-bit platforms, 32768
is the maximum value for pid_max. On 64-bit systems, pid_max
can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately
4 million).

From our observation, it was threads number that increased, not process number. Does pid_max have effect on threads as well?

https://en.wikipedia.org/wiki/Thread_(computing)

1:1 (kernel-level threading)[edit]
Threads created by the user in a 1:1 correspondence with schedulable entities in the kernel[10] are the simplest possible threading implementation. OS/2 and Win32 used this approach from the start, while on Linux the usual C library implements this approach (via the NPTL or older LinuxThreads). This approach is also used by Solaris, NetBSD, FreeBSD, OS X, and iOS.

Effectively, pid-max puts a limit on kernel scheduleable entities, which corresponds to either user process or threads. In addition, it seems that Linux does not have a separate threads per process limit.

After resolving the above questions, we can now answer these two questions:

What is the maximum threads that one can create on Linux host?
What is the maximum threads within a user process on Linux?

Essentially they are the same question and the answer is (to my best knowledge but not verified):

MIN(threads-max, pid-max, nproc - number of simultaneous processes)

In addition, it seems that threads-max is effective for total threads of all users and it only controls the number of threads, no processes.

Reference:

http://unix.stackexchange.com/questions/124040/how-to-determine-the-max-user-process-value
how to determine the max user process value?

https://access.redhat.com/solutions/2674
What causes stale NFS file handles?

http://nfs.sourceforge.net
Linux NFS Overview, FAQ and HOWTO Documents

http://www.thegeekstuff.com/2013/11/linux-process-and-threads/
What are Linux Processes, Threads, Light Weight Processes, and Process State

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/Kernel_Crash_Dump_Guide/Red_Hat_Enterprise_Linux-7-Kernel_Crash_Dump_Guide-en-US.pdf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s