by codeflo · 3y ago · 0 comments
It should be noted that AFAIK on all modern operating systems, only one page of the stack is actually allocated on thread creation, and the rest is merely reserved address space that will be allocated on demand.
That doesn't make this point wrong: 4 KB is still a lot more than the couple of bytes a future might need. And setting up the page table is part of what makes spawning threads so expensive.
That was one way to scale up to a large number of clients when memory was more limited.
It makes the memory usage acceptable in many contexts. E.g., 4 KiB is small compared to a socket buffer. YMMV.
> And setting up the page table is part of what makes spawning threads so expensive.
Stacks can be reused.