8292541: [Metrics] Reported memory limit may exceed physical machine memory

Reviewed-by: stuefe, sgehwolf
This commit is contained in:
Jonathan Dowland 2022-08-26 16:22:14 +00:00 committed by Severin Gehwolf
parent c74b6d4552
commit 9a0d1e7ce8
3 changed files with 52 additions and 16 deletions

View file

@ -121,7 +121,13 @@ public class CgroupMetrics implements Metrics {
@Override
public long getMemoryLimit() {
return subsystem.getMemoryLimit();
long subsMem = subsystem.getMemoryLimit();
// Catch the cgroup memory limit exceeding host physical memory.
// Treat this as unlimited.
if (subsMem >= getTotalMemorySize0()) {
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
}
return subsMem;
}
@Override
@ -178,5 +184,6 @@ public class CgroupMetrics implements Metrics {
}
private static native boolean isUseContainerSupport();
private static native long getTotalMemorySize0();
}

View file

@ -22,6 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <unistd.h>
#include "jni.h"
#include "jvm.h"
@ -33,3 +34,10 @@ Java_jdk_internal_platform_CgroupMetrics_isUseContainerSupport(JNIEnv *env, jcla
{
return JVM_IsUseContainerSupport();
}
JNIEXPORT jlong JNICALL
Java_jdk_internal_platform_CgroupMetrics_getTotalMemorySize0
(JNIEnv *env, jclass ignored)
{
return sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE);
}