Go

What is sysmon and what does it do?

Question 159HardGo 1.22 to 1.25

sysmon is a runtime thread that runs without a P, so it keeps working even when every P is busy or stuck. It wakes up adaptively, every 20 µs to 10 ms, backing off when the program is idle. Its jobs:

  • Retake Ps from syscalls: if a P has been in _Psyscall for more than one tick and there is work waiting, it hands the P to another M.
  • Preempt long-running goroutines: a G that has run for more than about 10 ms (forcePreemptNS) is flagged and sent an async preemption signal.
  • Poll the network if no one has polled for about 10 ms, and inject the ready goroutines.
  • Force GC if none has run for 2 minutes (forcegcperiod).
  • Wake the scavenger, which returns memory to the OS, and help with timers.

What the interviewer wants to hear: you understand that fairness in Go comes from sysmon plus async preemption, not from time slices handed out by the scheduler itself. This also explains why the scheduler "tick" is about 10 ms and why latency-sensitive loops can still see jitter at that scale.

More on Goroutines & the Scheduler

All 35 Goroutines & the Scheduler questions