Why are pre-allocated stacks expensive, given 64-bit virtual memory?

45 views Asked by At

As https://without.boats/blog/why-async-rust/ puts it,

OS threads have a large pre-allocated stack, which increases per-thread memory overhead.

And the article goes on to argue that much of the difficulty and design effort in concurrency in modern programming languages is about avoiding that per-thread memory overhead.

But wait.

All modern servers have virtual memory, so it doesn't need to allocate physical memory for a thread stack, only address space; the minimum overhead is just one page.

All modern servers are 64-bit, so virtual address space is essentially inexhaustible.

Most modern servers run Linux, which is happy to overcommit address space allocation.

Given all this, why is a few megabytes of address space per thread, considered an expense worth trying hard to avoid?

0

There are 0 answers