It's what the gemini-4-hydrogen says:
Summary
Linux Go applications (using
logs with
Linuxulator.
Root Cause
Summary
Linux Go applications (using
fsnotify / Go's netpoll epoll poller) spin at 800%+ CPU and floodlogs with
read : resource temporarily unavailable (EAGAIN) under FreeBSD 16.0-CURRENT'sLinuxulator.
Root Cause
- Non-blocking
inotifyfd creation:
Go'sfsnotifyopens aninotifydescriptor withIN_NONBLOCK | IN_CLOEXEC
(linux_inotify_init1()->linux_inotify_init_flags()in
sys/compat/linux/linux_file.c, which maps it toO_NONBLOCK). When the event queue is empty,
inotify_read()insys/kern/vfs_inotify.cimmediately returnsEWOULDBLOCK
(EAGAIN).
epoll_ctl(EPOLL_CTL_ADD)fails withEINVALwhenEPOLLOUTis included:
Go's Linuxnetpollregisters file descriptors intoepollwithEPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET.- In
sys/compat/linux/linux_event.c,epoll_to_kevent()emits both
EVFILT_READ(forLINUX_EPOLL_EVRD) andEVFILT_WRITE(for
LINUX_EPOLL_EVWR), andlinux_epoll_ctl()passes them tokern_kevent_fp(..., nevents = 0, ...). - However,
inotify_kqfilter()insys/kern/vfs_inotify.c(and similarly
timerfd_kqfilter()insys/kern/sys_timerfd.c) rejects any filter other than
EVFILT_READwithEINVAL. - Because
nevents == 0,kqueue_kevent()insys/kern/kern_event.cimmediately
fails the entireepoll_ctl()call withEINVAL. - On real Linux,
epoll_ctl()acceptsEPOLLOUToninotifyand
timerfddescriptors without error (it simply never reports them as writable).
- In
- Resulting busy loop:
Becauseepoll_ctl()fails, Go'sinternal/pollcannot park the goroutine via
epoll_wait. EveryRead()on theO_NONBLOCKinotifyfd immediately
returnsEAGAIN(resource temporarily unavailable), andfsnotify's event loop
retries in a tight infinite loop with no backoff, saturating multiple CPU cores and generating gigabytes of error
logs.