seanmonstar / num_cpus

Get the number of CPUs in Rust
Apache License 2.0
582 stars 91 forks source link

Feature Request: cgroupv2 support #130

Open PureWhiteWu opened 1 year ago

PureWhiteWu commented 1 year ago

Currently num_cpus doesn't support cgroupv2, maybe we should support it? Spec: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html K8s ref: https://kubernetes.io/docs/concepts/architecture/cgroups/

PureWhiteWu commented 1 year ago

We can refer to https://github.com/uber-go/automaxprocs/commit/ad6f05b8e9b6300affbe6411dbbf48768cbebe73 and https://github.com/uber-go/automaxprocs/commit/721b01340eb5194343487f073ea42e5de8fae8d2 .

I will take a look at this when I have time.

asfaltboy commented 1 year ago

According to this PR, cgroups v2 support was added.

@PureWhiteWu can you give an example of the issue?

For context, I'm debugging some odd behaviour with bad logical CPUs detection under Kubernetes, and I'm interested to see if there's still a bug in some case (when memory limit isn't specified in the pod.spec.container.resources.limits field).

PureWhiteWu commented 1 year ago

@asfaltboy Yes, the cgroups v2 seems not working correctly on our kubernetes environment. I'll find an example next week when I'm at work.

Dav1dde commented 5 months ago

@PureWhiteWu did you end up investigating this more?

PureWhiteWu commented 5 months ago

Sorry for the late reply, too busy these days.

I haven't find a standard way to get the cpu nums from k8s environment with different resource visibility plans (lxcfs or not).

I'll spend some time investigate this asap.