How Much Virtual Memory Does a Linux Thread Actually Consume?
This article reviews Linux virtual memory layouts for 32‑bit and 64‑bit systems, explains the different memory segments, shows how the default 8 MiB thread stack impacts virtual address consumption, and calculates practical thread limits based on virtual memory and kernel parameters.
Introduction
The article revisits Linux virtual memory concepts, starting with a high‑level mind map that outlines the division between kernel space and user space and sets the stage for a detailed examination of address layouts on 32‑bit and 64‑bit architectures.
Virtual Memory Layout
In Linux, the virtual address space is split into kernel space (reserved for the OS) and user space (available to applications). The address range differs by architecture: 32‑bit systems expose a 4 GiB space, while 64‑bit systems theoretically expose 16 EiB, but current implementations use only the lower 48 bits, giving 256 TiB of usable virtual memory.
32‑bit Address Space
The 32‑bit layout reserves the lowest 0x0000 0000–0x0804 8000 region as inaccessible, then defines six distinct segments from low to high addresses:
Reserved (unaddressable) region
Code segment (binary executable code)
Data segment (initialized static data and globals)
BSS segment (uninitialized static data and globals)
Heap segment (dynamic allocations, grows upward)
Memory‑mapped segment (shared libraries, mmap‑ed files, grows upward)
Stack segment (local variables, function call context, fixed size, typically 8 MiB)
64‑bit Address Space
64‑bit systems allocate 128 TiB for user space and 128 TiB for kernel space, with the same segment ordering as the 32‑bit layout. Although the theoretical range is 0x0000 0000 0000 0000–0xFFFF FFFF FFFF FFFF, only the lower 48 bits (256 TiB) are currently used.
Thread Stack Memory Consumption
Each thread receives a dedicated stack, defaulting to 8 MiB on most Linux distributions. The command ulimit -a displays the current stack size limit. Reducing the stack size (e.g., ulimit -s 512) can increase the maximum number of threads a process can create.
ulimit -s 512Factors Limiting Thread Count
Beyond virtual memory, Linux imposes system‑wide limits:
/proc/sys/kernel/threads-max – maximum threads the kernel supports (default ≈ 14553)
/proc/sys/kernel/pid_max – maximum PID value (default ≈ 32768)
/proc/sys/vm/max_map_count – maximum number of VMA (virtual memory areas) per process (default ≈ 65530)
Calculations
On a 32‑bit system, usable user space is 3 GiB (4 GiB total minus 1 GiB kernel). Dividing by the 8 MiB stack yields roughly 380 threads per process.
On a 64‑bit system, user space can reach 128 TiB. In theory, 128 TiB / 8 MiB ≈ 10 million threads, but real limits are governed by the kernel parameters above and overall system performance.
Conclusion
In summary, a 32‑bit Linux process can create about 380 threads with the default stack size, while a 64‑bit process is limited more by kernel configuration than by virtual memory size. Adjusting stack size and tuning kernel parameters are essential for high‑concurrency workloads.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
