News for hackers. Stuff that matters.
Re:How much memory do you need in 2024 to run 1M concurrent ... by cperciva on Friday November 29, 2024 @01:12AM (#42271308)
Aha, 2k stacks. I figured that stacks would be page size (or more) so 2500 seemed both too small for the thread to have a stack and too large for it to not have a stack.

2k stacks are an interesting design choice though... presumably they're packed, in which case stack overflow is a serious concern. Most threading systems will do something like allocating a single page for the stack but reserving 31 guard pages in case it needs to grow.

Re:How much memory do you need in 2024 to run 1M concurrent ... by masklinn on Friday November 29, 2024 @01:28AM (#42271407)
Goroutines being go structures, the runtime can cooperate with itself so it doesn't need to do any sort of probing: function prologues can check if there's enough stack space for its frame, and grow the stack if not.

In reality it does use a guard area (technically I think it's more of a redzone? It doesn't cause access errors and functions with known small static frames can use it without checking).

Re:How much memory do you need in 2024 to run 1M concurrent ... by uluyol on Friday November 29, 2024 @01:32AM (#42271431)
Go stacks are dynamically copied and resized. Stack overflow is not a concern.
Re:How much memory do you need in 2024 to run 1M concurrent ... by cperciva on Friday November 29, 2024 @01:40AM (#42271474)
Oh yuck. Invalidating all the pointers to the stack? That's got to be expensive.

I guess if you're already doing garbage collection moving the stack doesn't make things all that much worse though... still, yuck.

Re:How much memory do you need in 2024 to run 1M concurrent ... by masklinn on Friday November 29, 2024 @02:11AM (#42271619)
Yeah it’s the drawback, originally it used segmented stacks but that has its own issues.

And it’s probably not the worst issue because deep stacks and stack pointers will mostly be relevant for long running routines which will stabilise their stack use after a while (even if some are likely subject to threshold effects if they’re at the edge, I would not be surprised if some codebases ballasted stacks ahead of time). Also because stack pointers will get promoted to the heap if they escape so the number of stack pointers is not unlimited, and the pointer has to live downwards on the stack.

Re:How much memory do you need in 2024 to run 1M concurrent ... by YZF on Friday November 29, 2024 @01:22AM (#42271375)
A goroutine stack can grow. (EDIT: With stack copying AFAICT... so no virtual pages reserved for a stack to grow... probably some reason for this design?)