unix: add CPUSetDynamic for systems with more than 1024 CPUs

The existing CPUSet type is a fixed-size array limited to 1024 CPUs,
which makes it problematic to use for large systems (such as Google's
X4 instances with 1440 and 1920 vCPUs), see e.g.
https://github.com/opencontainers/runc/issues/5023.

Introduce CPUSetDynamic type and NewCPUSet constructor to support large
systems. The bit-managing routines (set/clear/isset/fill/count) are
separated and reused.

Add variants of SchedGetaffinity, SchedSetaffinity and SetMemPolicy
that accept the new type.

Amend the documentation for CPUSet.

Amend the existing TestSchedSetaffinity to:
 - test set.Fill;
 - use t.Cleanup to restore the affinity.

Add tests for new functionality (mostly a copy of existing tests).

This is an alternative to CL 727540 / CL 727541.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Change-Id: I51bba0305b8dfa7a88a4e7fb8758d73f798574f1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/735380
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
4 files changed
tree: 7c94449c3f7671ab53be06bacb69c08dcafbc0d4
  1. cpu/
  2. execabs/
  3. plan9/
  4. unix/
  5. windows/
  6. .gitattributes
  7. .gitignore
  8. codereview.cfg
  9. CONTRIBUTING.md
  10. go.mod
  11. LICENSE
  12. PATENTS
  13. README.md
README.md

sys

Go Reference

This repository holds supplemental Go packages for low-level interactions with the operating system.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/sys.

The main issue tracker for the sys repository is located at https://go.dev/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.