Google proposes user threads for Linux
lore.kernel.org
lore.kernel.org
Yeah, that reply made me laugh. Never change Kernel mailing list, never change.
That'd be one of the most welcome additions to the kernel in years IMO. And the change is fairly minimal.
What's different about this attempt that puts it over the old? An honest question
There's still a syscall, but it doesn't enter the kernel scheduler or other machinery, which is where most of the time is spent.
Linux syscall overhead (switching into ring 0) was and remains (apparently[1]) miniscule, which is why Linux ended up with 1:1 thread scheduling. But everything else--what those syscalls do--has grown in complexity. The original calculus for rejecting userspace scheduler activations and M:N threading for 1:1 threading no longer holds. What's old is new again.
[1] Would be interesting to know if Google's kernels employ all the new Spectre mitigations.
The reason why you would want this instead of the traditional implementation of goroutines is that it's compatible with existing code. When you buy into an M:N framework you lose compatibility with all existing libraries, because they could use things like blocking I/O, thread-local storage, or signals. The traditional solution to this that e.g. Go uses is to have some OS threads that you proxy all such calls from your userland M:N threads to. This works, but it's slow, and if you forget to use that mechanism you can end up starving your OS threads or worse. With the switchto patches here, you can get the best of both worlds: fast and precise control over thread scheduling from userland and compatibility with existing libraries. Ideally, it'd enable interoperability among different threading implementations: you could imagine that calling C++ or Rust functions from Go goroutines could become as fast as calling Go functions (though you would still have to deal with the small stack problem).