We sometimes see failures in the jtreg test jdk/internal/platform/cgroup/TestCgroupMetrics.java .
Failures look like :
java.lang.RuntimeException: Test failed for - memory:getMemoryUsage, expected [56019386368], got [56200986624]
at jdk.test.lib.containers.cgroup.MetricsTester.fail(MetricsTester.java:207)
at jdk.test.lib.containers.cgroup.MetricsTester.testMemoryUsage(MetricsTester.java:597)
at TestCgroupMetrics.main(TestCgroupMetrics.java:53)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
at java.base/java.lang.Thread.run(Thread.java:830)
Looking at the coding in MetricsTester.java we expect that “memory.usage_in_bytes” gets larger after an additional allocation of 64 M.
However this is sometimes not the case. The reason is not fully clear.
Might be that a GC kicked in and freed space; or for some reasons OS pages were freed.
Maybe also the "memory.usage_in_bytes” counter is not so reliable (by design? or bug ?) .
Coding from MetricsTester.java :
public void testMemoryUsage() throws Exception {
Metrics metrics = Metrics.systemMetrics();
long memoryMaxUsage = metrics.getMemoryMaxUsage();
long memoryUsage = metrics.getMemoryUsage();
byte[] bb = new byte[64*1024*1024]; // 64M - here we expect an increase of memory.usage_in_bytes
long newMemoryMaxUsage = metrics.getMemoryMaxUsage();
long newMemoryUsage = metrics.getMemoryUsage();
if(newMemoryMaxUsage < memoryMaxUsage) {
fail(SubSystem.MEMORY, "getMemoryMaxUsage", newMemoryMaxUsage,
memoryMaxUsage);
}
if(newMemoryUsage < memoryUsage) {
fail(SubSystem.MEMORY, "getMemoryUsage", newMemoryUsage, memoryUsage); // line 597 triggers the failure in MetricsTester.java
}
}
probably we should make the test more reliable and add a little loop with allocations (and do not fail on the first one) .