Hasty Briefsbeta

Bilingual

Epoll and Kqueue: How Operating Systems Learned to Wait Efficiently

4 hours ago
  • The hardest part of I/O is knowing when to stop waiting, not reading data, and early OS handled waiting poorly.
  • select and poll require scanning all file descriptors each call, making cost linear with connections.
  • epoll and kqueue use a registration model: tell kernel once, kernel notifies on events, making waiting proportional to activity.
  • epoll (Linux) supports level-triggered and edge-triggered modes; kqueue (BSD) is more general, monitoring files, signals, timers, etc.
  • These APIs shift from user-space polling to kernel-driven notification, enabling handling of tens of thousands of connections.
  • Go’s runtime uses epoll/kqueue to block goroutines without blocking OS threads, achieving massive concurrency transparently.