Re: Coroutines, goroutines

"Stelian Ionescu" <[email protected]> Fri, 27 Feb 2026 21:18:30 -0700
Newsgroups gmane.lisp.steel-bank.devel
Message-ID <[email protected]>
> The reason I raised the stack size question is that it seems to be an important detail that affects how fibers can be used in practice.  Goroutines receive very small stacks by default (2kB), but the stacks are movable and growable.  This allows thousands or even millions of them to exist without excessive resource consumption.
> 
> I'm going to guess that movable stacks are out of scope for this project — or maybe not possible at all, in the presence of FFI — but here's another idea.  When a fiber is created, we allocate it a single 4kB stack page, placing the mprotect'ed guard page next to it, but we spread these out in address space at, say, 256kB intervals (configurable).  Then when the guard page is hit, we can grow the stack without moving it.  This way, at least we don't use up much physical memory for a fiber by default.  Does this make sense?

The resulting fragmentation of the virtual memory space will create all sorts of performance problems in the kernel, will prevent the use of hugepages (transparent or not), cause TLB pressure, etc...

--
Stelian Ionescu

_______________________________________________
Sbcl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-devel