8275735: [linux] Remove deprecated Metrics api (kernel memory limit)

Reviewed-by: hseigel, mchung
This commit is contained in:
Severin Gehwolf 2021-11-02 10:39:41 +00:00
parent b7a06be98d
commit 9971a2cab3
6 changed files with 4 additions and 104 deletions

View File

@ -53,16 +53,6 @@ public interface CgroupV1Metrics extends Metrics {
*/
public long getKernelMemoryFailCount();
/**
* Returns the maximum amount of kernel physical memory, in bytes, that
* can be allocated in the Isolation Group.
*
* @return The maximum amount of memory in bytes or -1 if
* there is no limit set.
*
*/
public long getKernelMemoryLimit();
/**
* Returns the largest amount of kernel physical memory, in bytes, that
* have been allocated in the Isolation Group.
@ -93,16 +83,6 @@ public interface CgroupV1Metrics extends Metrics {
*/
public long getTcpMemoryFailCount();
/**
* Returns the maximum amount of networking physical memory, in bytes,
* that can be allocated in the Isolation Group.
*
* @return The maximum amount of memory in bytes or -1 if
* there is no limit.
*
*/
public long getTcpMemoryLimit();
/**
* Returns the largest amount of networking physical memory, in bytes,
* that have been allocated in the Isolation Group.

View File

@ -48,11 +48,6 @@ public class CgroupV1MetricsImpl extends CgroupMetrics implements CgroupV1Metric
return metrics.getKernelMemoryFailCount();
}
@Override
public long getKernelMemoryLimit() {
return metrics.getKernelMemoryLimit();
}
@Override
public long getKernelMemoryMaxUsage() {
return metrics.getKernelMemoryMaxUsage();
@ -68,11 +63,6 @@ public class CgroupV1MetricsImpl extends CgroupMetrics implements CgroupV1Metric
return metrics.getTcpMemoryFailCount();
}
@Override
public long getTcpMemoryLimit() {
return metrics.getTcpMemoryLimit();
}
@Override
public long getTcpMemoryMaxUsage() {
return metrics.getTcpMemoryMaxUsage();

View File

@ -332,10 +332,6 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
return getLongValue(memory, "memory.kmem.failcnt");
}
public long getKernelMemoryLimit() {
return CgroupV1SubsystemController.longValOrUnlimited(getLongValue(memory, "memory.kmem.limit_in_bytes"));
}
public long getKernelMemoryMaxUsage() {
return getLongValue(memory, "memory.kmem.max_usage_in_bytes");
}
@ -348,10 +344,6 @@ public class CgroupV1Subsystem implements CgroupSubsystem, CgroupV1Metrics {
return getLongValue(memory, "memory.kmem.tcp.failcnt");
}
public long getTcpMemoryLimit() {
return CgroupV1SubsystemController.longValOrUnlimited(getLongValue(memory, "memory.kmem.tcp.limit_in_bytes"));
}
public long getTcpMemoryMaxUsage() {
return getLongValue(memory, "memory.kmem.tcp.max_usage_in_bytes");
}

View File

@ -39,9 +39,6 @@ public class MetricsMemoryTester {
case "memoryswap":
testMemoryAndSwapLimit(args[1], args[2]);
break;
case "kernelmem":
testKernelMemoryLimit(args[1]);
break;
case "oomkill":
testOomKillFlag(Boolean.parseBoolean(args[2]));
break;
@ -119,23 +116,6 @@ public class MetricsMemoryTester {
System.out.println("TEST PASSED!!!");
}
private static void testKernelMemoryLimit(String value) {
Metrics m = Metrics.systemMetrics();
if (m instanceof CgroupV1Metrics) {
CgroupV1Metrics mCgroupV1 = (CgroupV1Metrics)m;
System.out.println("TEST PASSED!!!");
long limit = getMemoryValue(value);
long kmemlimit = mCgroupV1.getKernelMemoryLimit();
if (kmemlimit != UNLIMITED && limit != kmemlimit) {
throw new RuntimeException("Kernel Memory limit not equal, expected : ["
+ limit + "]" + ", got : ["
+ kmemlimit + "]");
}
} else {
throw new RuntimeException("kernel memory limit test not supported for cgroups v2");
}
}
private static void testMemoryAndSwapLimit(String memory, String memAndSwap) {
long expectedMem = getMemoryValue(memory);
long expectedMemAndSwap = getMemoryValue(memAndSwap);

View File

@ -61,18 +61,14 @@ public class TestDockerMemoryMetrics {
testMemoryAndSwapLimit("100m", "200m");
Metrics m = Metrics.systemMetrics();
// kernel memory, '--kernel-memory' switch, and OOM killer,
// '--oom-kill-disable' switch, tests not supported by cgroupv2
// runtimes
// OOM killer disable, '--oom-kill-disable' switch, test not supported
// by cgroupv2
if (m != null) {
if ("cgroupv1".equals(m.getProvider())) {
testKernelMemoryLimit("100m");
testKernelMemoryLimit("1g");
testOomKillFlag("100m", false);
} else {
System.out.println("kernel memory tests and OOM Kill flag tests not " +
"possible with cgroupv2.");
System.out.println("OOM kill disable test not " +
"supported with cgroupv2.");
}
}
testOomKillFlag("100m", true);
@ -149,30 +145,6 @@ public class TestDockerMemoryMetrics {
DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
}
private static void testKernelMemoryLimit(String value) throws Exception {
Common.logNewTestCase("testKernelMemoryLimit, value = " + value);
DockerRunOptions opts =
new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
.addDockerOpts("--kernel-memory=" + value)
.addJavaOpts("-cp", "/test-classes/")
.addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
.addClassOptions("kernelmem", value);
OutputAnalyzer oa = DockerTestUtils.dockerRunJava(opts);
// Some container runtimes (e.g. runc, docker 18.09)
// have been built without kernel memory accounting. In
// that case, the runtime issues a message on stderr saying
// so. Skip the test in that case.
if (oa.getStderr().contains("kernel memory accounting disabled")) {
System.out.println("Kernel memory accounting disabled, " +
"skipping the test case");
return;
}
oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
}
private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception {
Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag);
DockerRunOptions opts =

View File

@ -247,13 +247,6 @@ public class MetricsTesterCgroupV1 implements CgroupMetricsTester {
fail(Controller.MEMORY, "memory.kmem.failcnt", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.limit_in_bytes");
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryMaxUsage();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.max_usage_in_bytes");
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
@ -273,13 +266,6 @@ public class MetricsTesterCgroupV1 implements CgroupMetricsTester {
fail(Controller.MEMORY, "memory.kmem.tcp.failcnt", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes");
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED: newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryMaxUsage();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.max_usage_in_bytes");
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {