`/sys/fs/cgroup/cpu/cpu.shares` default value is 2. Why?


Hi everyone,

I host my Java/JRuby apps in a Kubernetes cluster deployed thanks to AWS EKS.
My Kubernetes version is 1.11 (I don’t know the patch version. How can I know it ?)

I encountered a problem when I switched the version of my JVM from 8u181 to 8u202.

With the 8u181 version, my JVM booted 4 threads for one of my thread pool I configured to boot Runtime.getRuntime.availableProcessors() threads. Which is the correct value because my kubernetes node has 4 CPUs.

With the 8u202 version, my JVM booted only 1 thread for the same thread pool and code.

I searched a lot to understand why and now I know that this is related to 2 problems. One which concerns Kubernetes (that’s why I’m here), one concerning how the recent versions of the JVM detects the number of CPU.

Apparently, in its recent versions, the JVM uses the /sys/fs/cgroup/cpu/cpu.shares value to detect how many CPUs is can use. (I should precise that, for now, I don’t know the exact algorithm the modern JVM uses to detect the number of CPUs but I’m also working with the JVM folks to understand what’s happening)

And the reason the version 8u202 boot only 1 thread is because the default value, when we don’t set any resources.requests.cpu nor resources.limits.cpu restrictions, of /sys/fs/cgroup/cpu/cpu.shares is 2 instead of 0.

So, my question is why /sys/fs/cgroup/cpu/cpu.shares default value is 2 ?
Why not 0 ? or -1 like the /sys/fs/cgroup/cpu/cpu.cfs_quota_us default value ?

Thanks for your help :slight_smile:


Anyone can help ?


There are several things to take into account.

Although you may not set it in the yaml, it might be set. Try looking at the k8s object with kubectl get … And check it is not set.

Also, I don’t remember what 0 for cpu shares cgroups means. Does it have a special meaning?

I wouldn’t be surprised if that is used/passed to the cfs scheduler to assign resources in a proportional way between containers. I’m on my phone, but I’d look into docker option and more kubernetes docs.

But, more importantly, what do you want to achieve? Why is that value a problem?