Skip to content
Calcrivo

Thread Count Calculator

Sum per-process thread counts and check usage against kernel.threads-max.

Inputs

Check with: cat /proc/sys/kernel/threads-max

Total Threads (estimated)

3,600

Usage of kernel.threads-max

5.746%

Remaining Thread Capacity

59,048

Status

Healthy — comfortable headroom below kernel.threads-max.

Step by step

  1. Values used

    Number of Processes = 300; Average Threads per Process = 12; kernel.threads-max = 62,648

  2. Total threads and usage

    total_threads = process_count × avg_threads_per_process; usage% = total_threads / threads_max × 100

  3. Total Threads (estimated)

    = 3,600

  4. Usage of kernel.threads-max

    = 5.746

  5. Remaining Thread Capacity

    = 59,048

  6. Status

    = Healthy — comfortable headroom below kernel.threads-max.

How it works

Every thread on Linux is represented internally as a task_struct, the same structure used for whole processes, and the kernel caps the total system-wide count via kernel.threads-max (auto-tuned at boot based on RAM, but overridable via sysctl). Summing threads across all processes and comparing to this limit reveals headroom before hitting 'can't create thread'/'resource temporarily unavailable' errors, which commonly surface first in thread-heavy applications like JVM-based services or connection-per-thread servers, well before other resource limits are reached.

Formula

Total threads and usage

total_threads = process_count × avg_threads_per_process; usage% = total_threads / threads_max × 100

P
process count
"\\bar{t}"
average threads per process
T_{max}
kernel.threads-max

Frequently Asked Questions

How is kernel.threads-max determined by default?

The kernel auto-calculates a default at boot based on available RAM (roughly proportional to total pages divided by a per-thread-stack-size factor), so systems with more RAM get a higher default ceiling automatically. It can be overridden directly via `sysctl -w kernel.threads-max=<value>` if the workload needs more.

What happens when the system hits kernel.threads-max?

Attempts to create new threads or processes (both go through the same underlying clone() mechanism and consume from the same limit) fail, typically surfacing as 'fork: retry: Resource temporarily unavailable' or similar errors in applications, even if CPU and memory both still have headroom.

How do I count actual live threads on a running system?

`ps -eLf | wc -l` counts all threads across all processes (each row is one thread), and `cat /proc/sys/kernel/threads-max` alongside `ps -eLf | wc -l` lets you compute current usage percentage directly rather than relying on estimated averages.

You might also need