golang/go

runtime: bypass reading /proc/self/cgroup and /proc/self/mountinfo when GODEBUG=containermaxprocs=0

Open

#77,911 建立於 2026年3月3日

在 GitHub 查看
 (17 留言) (1 反應) (0 負責人)Go (133,883 star) (19,008 fork)batch import
LibraryProposalNeedsFixcompiler/runtimehelp wanted

描述

Hello,

The container-aware GOMAXPROCS that was introduced in go1.25 tries to read /proc/self/cgroup and /proc/self/mountinfo at startup.

These reads cause permission denials, when Go binaries built using go1.25 or later are run in a confined environment like snaps. Looking at the init function defaultGOMAXPROCSinit, I can see that /proc/self/cgroup and /proc/self/mountinfo are read unconditionally.

The GOMAXPROCS documentation shows that setting GODEBUG=containermaxprocs=0 and GODEBUG=updatemaxprocs=0 should disable context aware GOMAXPROCS and use runtime.NumCPU as the default value for the number of CPUs. However, since cgroup.OpenCPU runs every time on startup, we do not have an effective way to bypass this behavior using GODEBUG environment variables.

Would it be possible to allow for GODEBUG=containermaxprocs=0 to completely bypass the file reads and use runtime.NumCPU instead?

Thank you!

貢獻者指南