Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

On a host using cgroup v2, a service built on an old JDK 8 update reports Runtime.availableProcessors() equal to the node's 64 cores and sizes its heap from the node's memory instead of the pod limits. Explain the impact and fix.

The old JDK 8 build only understands cgroup v1, or has no container support at all, so on a cgroup v2 node it cannot find the pod limits and reads the host instead: 64 CPUs and the node's full memory. It then starts dozens of GC and JIT threads and sizes thread pools for 64 cores, which hit the CFS quota and get throttled, and it allows a heap of a quarter of the node's memory, which can exceed the pod limit and get the process OOM killed by the kernel. The real fix is a JDK update with cgroup v2 support (JDK 15 and later, and backports in later JDK 11 and JDK 8 updates; check your vendor's notes); as a stopgap, set -Xmx and -XX:ActiveProcessorCount explicitly.

Why this question is asked

Node upgrades are often done by an infrastructure team that does not know which JDK each service uses. When the nodes move from cgroup v1 to v2, services on old runtimes suddenly see the whole machine, and the symptoms look like a mysterious performance regression or random restarts. Interviewers ask this because it tests whether we can connect symptoms in the JVM to a change in the platform underneath it. In this answer, we will see why the old JDK reads host values, what the wrong CPU count does under a CPU quota, what the wrong memory size does, how to confirm the diagnosis, and how to fix it now and permanently.

1Why the Old JDK Sees the Whole Node

Container limits live in cgroup files. Under cgroup v1 the memory limit is in a file such as /sys/fs/cgroup/memory/memory.limit_in_bytes and the CPU quota in cpu.cfs_quota_us. Under cgroup v2 there is one unified hierarchy, and the same information is in memory.max and cpu.max, with a different layout. Container support in JDK 8 first arrived in later updates and only knew the v1 layout. cgroup v2 support arrived in JDK 15 and was backported later to JDK 11 and JDK 8 updates, so the exact update depends on the vendor.

When a v1-only JVM starts on a v2 node, it looks for files that do not exist, concludes that there is no container limit, and falls back to the operating system's view of the machine. That view is the whole node: 64 CPUs and, say, 256 GB of memory. A build from before any container support behaves the same way on any node.

2Impact 1: Too Many Threads Under a CPU Quota

With 64 visible CPUs, the JVM's ergonomics creates many threads. The parallel GC thread count is the CPU count up to 8, then 8 plus five eighths of the rest, which is 43 threads for 64 CPUs. The JIT gets many more compiler threads than it would with 2 CPUs. The ForkJoinPool common pool gets 63 workers, and frameworks that size their pools from availableProcessors(), such as Netty event loops or a database driver's thread pool, multiply too.

But the pod still has its CPU limit, say 2 CPUs, enforced by the Completely Fair Scheduler (CFS) as a quota of 200 ms of CPU time per 100 ms period. When a GC starts, 43 threads run in parallel and use the whole 200 ms of quota in about 5 ms of wall-clock time. Then the kernel throttles the container for the remaining 95 ms of the period. A GC pause that should take 20 ms stretches to several hundred, and request latency spikes in the same way.

What the JVM believes versus the pod's real limits
ValueOld JDK 8 on cgroup v2JDK with v2 support
availableProcessors()64 (node)2 (pod limit)
ParallelGCThreads432
ForkJoinPool common parallelism631
Default max heapabout 64 GB (25 percent of 256 GB)about 1 GB (25 percent of 4 GiB)
ResultCPU throttling, OOMKilled podssized to the pod

3Impact 2: A Heap Larger Than the Pod

The default maximum heap is a quarter of the memory the JVM sees. Seen from a 256 GB node, that is 64 GB, while the pod limit might be 4 GiB. The JVM does not allocate it all at once; it grows the heap as needed. As long as the live data is small, nothing happens. But under load the collector prefers to grow the heap rather than collect harder, because it believes there is plenty of room. When the process's resident memory crosses 4 GiB, the kernel's out-of-memory killer ends the process.

This failure gives no Java OutOfMemoryError, no heap dump and no stack trace. Kubernetes reports the container as OOMKilled with exit code 137, and the pod restarts. Teams often misread it as a memory leak in the application.

4Confirming the Diagnosis

Three quick checks inside the pod confirm it: the node's cgroup version, what the JVM thinks it has, and evidence of throttling.

Java
stat -fc %T /sys/fs/cgroup/ # cgroup2fs -> the node uses cgroup v2
java -version # openjdk version "1.8.0_212" (an old update)
# what the running JVM believes
jcmd 1 VM.flags | tr ' ' '\n' | grep -E 'MaxHeapSize|ParallelGCThreads'
# -XX:MaxHeapSize=68719476736 (64 GB in a 4 GiB pod)
# -XX:ParallelGCThreads=43
cat /sys/fs/cgroup/cpu.stat | grep throttled
# nr_throttled 18234
# throttled_usec 912345678 (a lot of time spent throttled)

If the JVM reports a heap bigger than the pod and a GC thread count that matches the node, the diagnosis is certain. In Kubernetes, the container's last state showing OOMKilled and a rising container_cpu_cfs_throttled_periods_total metric tell the same story from the outside.

5The Fix and the Stopgap

The real fix is to upgrade the runtime to a release that understands cgroup v2: a current JDK 17, 21 or 25, or at least a JDK 8 or 11 update that includes the backport. That restores correct detection for memory, CPUs and everything derived from them, and it also brings years of other container fixes. After the upgrade we confirm the detected values with -XshowSettings:system, which prints the provider and the effective limits (on JDK 8, check whether your update has this option).

If the upgrade cannot happen today, we tell the JVM the truth explicitly: a fixed heap that fits the pod and an explicit processor count.

YAML
# stopgap for a 4 GiB, 2 CPU pod on an old JDK 8 update
java -Xmx2800m -Xms2800m -XX:ActiveProcessorCount=2 -jar legacy.jar
# availableProcessors() -> 2, ParallelGCThreads -> 2, heap capped at 2.8 GB

There is a catch: ActiveProcessorCount itself only exists from the same later JDK 8 update that added container support. On a build older than that, the flag is unrecognized, and we have to cap the important values individually with -XX:ParallelGCThreads, -XX:CICompilerCount and the pool sizes in the application's configuration. This is fragile and one more reason to treat the upgrade as urgent. For the platform, the lesson is to couple node changes with a minimum JDK version and to check it before migrating nodes.

6Follow-up questions

Why does throttling make GC pauses longer rather than just slower overall?

Because the quota is per period. Many GC threads burn the whole period's quota in a few milliseconds, then all threads in the container, including the application, are paused until the next period starts. A stop-the-world pause therefore includes the throttled time, which can be up to the rest of the 100 ms period, repeated.

Would setting -Xmx alone be enough?

It fixes the OOM kills but not the CPU problem. The JVM would still create GC and JIT threads and size pools for 64 CPUs and suffer throttling. Both the heap and the processor count need to be correct.

How do we find all affected services before a node migration?

Inventory the JDK version of every running image, for example from an image scanner or a startup log line, and compare it with the minimum release that supports cgroup v2 for each vendor. Running -XshowSettings:system in each image on a v2 test node also shows whether detection works.

7Conclusion

In this answer, we saw that an old JDK 8 build only understands cgroup v1 or no containers at all, so on a v2 node it reads the node's 64 CPUs and full memory. That creates far too many GC, JIT and pool threads, which then exhaust the CFS quota and get throttled, and a heap default far larger than the pod, which ends in kernel OOM kills. We confirmed it with the cgroup type, VM.flags and throttling counters, fixed it by upgrading to a JDK with cgroup v2 support, and used -Xmx with ActiveProcessorCount, where the build supports it, as a stopgap.

What to say in the interviewAbout 90 seconds aloud

Open with

The JDK 8 build is older than cgroup v2 support. Container awareness in JDK 8 came in later updates and only knew the v1 file layout; v2 support arrived in JDK 15 and was backported to later 11 and 8 updates, depending on the vendor.

Then, if they want more

So on a v2 node it can't find the limits and falls back to the node: 64 CPUs and the node's memory. Two things go wrong. On CPU, it starts around 43 parallel GC threads, lots of JIT threads, a common pool of 63, and frameworks size their pools for 64 cores.

But the pod still has a CFS quota, say two CPUs, which is 200 milliseconds per 100 millisecond period. 43 GC threads burn that in a few milliseconds and then the whole container is throttled for the rest of the period, so GC pauses and latency explode.

On memory, the default max heap is a quarter of the node, maybe 64 gigabytes in a 4 gigabyte pod. The heap grows under load, RSS crosses the limit, and the kernel kills it with exit 137, no Java error, no heap dump. I'd confirm with the cgroup type, jcmd VM.flags and the throttling counters.

The fix is upgrading to a JDK with v2 support. As a stopgap, set Xmx to fit the pod and ActiveProcessorCount to the CPU limit, keeping in mind that very old builds don't even have ActiveProcessorCount.

About this answer

Last updated
12 November 2026
Versions it names
Java 8, Java 11, Java 15, Java 17
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "On a host using cgroup v2, a service built on an old JDK 8 update reports...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/60d49d32bc/