Zio - async I/O framework based on libxev

Unlike goroutines in Go or virtual threads in Java, tasks in Zio have a fixed stack size. This is a big limitation, coming from the fact that Zig is a language with manual memory management.

One thing I’ve been wondering here, is whether it’s feasible to do circumvent this using virtual memory? What you can do is to map 8MiB stack, but rely on demand paging to allocate physical memory. This is not great still, because you have to do the work to setup memory maps for 8MiB worth of pages. But is there some way to directly reserve a penultimate level of page table, so that you pay for only one entry up-front, and setup virtual address mapping lazily as well?

Linux actually does something like that for the stack of the main thread as well, such that 8MiB of stack aren’t even present in the page table for the start (Stack probe puzzle), something like that should be possible for green threads, no? (though, the answer here might start with writing your own kernel…)

1 Like