8299858: [Metrics] Swap memory limit reported incorrectly when too large

Reviewed-by: stuefe
This commit is contained in:
Severin Gehwolf 2023-01-26 14:50:46 +00:00
parent 28545dcf2b
commit 64ddf9536f
3 changed files with 67 additions and 3 deletions

View file

@ -122,9 +122,11 @@ public class CgroupMetrics implements Metrics {
@Override
public long getMemoryLimit() {
long subsMem = subsystem.getMemoryLimit();
long systemTotal = getTotalMemorySize0();
assert(systemTotal > 0);
// Catch the cgroup memory limit exceeding host physical memory.
// Treat this as unlimited.
if (subsMem >= getTotalMemorySize0()) {
if (subsMem >= systemTotal) {
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
}
return subsMem;
@ -142,7 +144,15 @@ public class CgroupMetrics implements Metrics {
@Override
public long getMemoryAndSwapLimit() {
return subsystem.getMemoryAndSwapLimit();
long totalSystemMemSwap = getTotalMemorySize0() + getTotalSwapSize0();
assert(totalSystemMemSwap > 0);
// Catch the cgroup memory and swap limit exceeding host physical swap
// and memory. Treat this case as unlimited.
long subsSwapMem = subsystem.getMemoryAndSwapLimit();
if (subsSwapMem >= totalSystemMemSwap) {
return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
}
return subsSwapMem;
}
@Override
@ -185,5 +195,6 @@ public class CgroupMetrics implements Metrics {
private static native boolean isUseContainerSupport();
private static native long getTotalMemorySize0();
private static native long getTotalSwapSize0();
}