|
|
Subscribe / Log in / New account

User-managed concurrency groups

User-managed concurrency groups

Posted Dec 31, 2021 16:11 UTC (Fri) by foom (subscriber, #14868)
In reply to: User-managed concurrency groups by Cyberax
Parent article: User-managed concurrency groups

The mechanism go uses for this today is ugly. It must surround every syscall which might block with "entersyscall"/"exitsyscall". "Enter" effectively sets a timer -- if "exit" isn't reached within 20μs and there are runnable goroutines waiting, it's assumed that the syscall blocked and an additional OS thread should be started/resumed to allow one of those other goroutines to run.

Yet, a syscall could take longer than that on-cpu (without blocking), in which case you've over-scheduled work vs number of cpus. Alternately, a syscall might block immediately, in which case you've wasted time, where you could've run another goroutine.

To ameliorate those issues in common cases, there's two other variants of syscall entry, one for invoking a syscall that "never" blocks, and another for syscalls that are considered to very likely immediately block, which resumes another goroutine immediately.)

This mechanism clearly works, but it really doesn't seem ideal. If the kernel could, instead, notify the go scheduler when a thread has blocked, all this guessing and heuristics could be eliminated.


to post comments

User-managed concurrency groups

Posted Dec 31, 2021 22:47 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link]

> This mechanism clearly works, but it really doesn't seem ideal. If the kernel could, instead, notify the go scheduler when a thread has blocked, all this guessing and heuristics could be eliminated.

I'm not sure if it would help. You still need a scheduler thread and checking for a stuck thread right now is pretty fast. I guess one thing that might be helpful is ability to force-preempt threads. Right now Go uses signals for that, and signals have their drawbacks.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds