-
Notifications
You must be signed in to change notification settings - Fork 721
Fix coreCount on Linux when using cgroup v2 with CFS throttling disabled #3462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix coreCount on Linux when using cgroup v2 with CFS throttling disabled #3462
Conversation
…ble colons in /proc/self/cgroup, and add more tests.
…remove some redundant test cases which were tripping up the formatter.
|
These compiler crashes on the static SDK are, unfortunately, relevant. They are hit when compiling |
|
This is great. @mitchellallison are you interested in also applying this change to https://github.com/swiftlang/swift-platform-executors? Which also has a core count calculating method. |
Fix coreCount on Linux when using cgroup v2 with CFS throttling disabled
Motivation:
When using
swift-nioon Linux with cgroup v2 enabled, but with CFS throttling disabled, it falls back to attempting to read the cpuset file at the cgroup v1 path. This does not exist, which in turns falls back to returning_SC_NPROCESSORS_ONLN, which will return the total number of cores available (ignoring cgroup assignments).This has unexpected effects, including the default behaviour of starting the
MultiThreadedEventLoopGroup.singletonwith significantly more event loops than cores available to the workload.Modifications:
SystemCalls.statfs, and associated constants, to determine the cgroup version.Linux.cgroupVersion()API to expose cgroup version.Linux.cgroupV2MountPointvariable to determine the cgroup v2 mount point.Linux.cpuSetPathV1&Linux.cpuSetPathV2(andLinux.cpuSetPathconvenience) variables to determine the correct cpu set path.System.coreCountto use the appropriate logic from above to ensure thatcpuset.cpusis parsed from the correct location.Result:
Linux.coreCountshould correctly parse and return the core count on Linux cgroup v2 enabled systems (when CFS throttling is disabled), while maintaining correctness for other configurations.