Split Stacks: Necessary or Unnecessary on AMD64 Architectures?
The notion that split stacks are unnecessary on 64-bit architectures, specifically AMD64, has surfaced in discussions without explicit statements. However, experts such as Ian Lance Taylor and bstrie have alluded to it.
What is the Implied Argument?
The implied argument is that the vast 64-bit virtual address space on AMD64 systems eliminates the need for split stacks. Taylor suggests that multi-threaded programs can run with significantly reduced memory usage, as each thread no longer has to reserve a substantial amount of stack space.
Bstrie acknowledges that the overhead of split stacks and their limited use case in 32-bit environments make them less appealing for modern systems.
Why Are Split Stacks Unnecessary?
Split stacks were developed as a solution to the limited address space available in 32-bit systems. In such systems, each thread requires its own stack, and the total stack size for all threads could quickly consume the available memory.
However, in AMD64 architectures, the 64-bit address space is exceptionally large, allowing for millions of separate stack address ranges, each with a size comparable to an entire 32-bit address space. This ample address space eliminates the need for split stacks to manage multiple threads effectively.
Implementation Details
On AMD64 systems, the flat memory model is employed, with virtual memory translations handled by the hardware memory management unit (MMU). It is significantly more efficient to reserve large virtual address space chunks for each stack, initially mapping only the first page (4 kB) to physical RAM.
This approach allows stacks to expand and contract as needed, using contiguous virtual addresses. The OS dynamically configures the MMU to map pages to actual RAM as the stack grows or shrinks, ensuring efficient memory usage.
The above is the detailed content of Split Stacks on AMD64: A Relic of the Past or Still Necessary?. For more information, please follow other related articles on the PHP Chinese website!