Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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.
@@ -48,11 +48,6 @@ public long getKernelMemoryFailCount() {
return metrics.getKernelMemoryFailCount();
}

@Override
public long getKernelMemoryLimit() {
return metrics.getKernelMemoryLimit();
}

@Override
public long getKernelMemoryMaxUsage() {
return metrics.getKernelMemoryMaxUsage();
@@ -68,11 +63,6 @@ public long getTcpMemoryFailCount() {
return metrics.getTcpMemoryFailCount();
}

@Override
public long getTcpMemoryLimit() {
return metrics.getTcpMemoryLimit();
}

@Override
public long getTcpMemoryMaxUsage() {
return metrics.getTcpMemoryMaxUsage();
@@ -332,10 +332,6 @@ public long getKernelMemoryFailCount() {
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 long getTcpMemoryFailCount() {
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");
}
@@ -39,9 +39,6 @@ public static void main(String[] args) {
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 @@ private static void testMemorySoftLimit(String softLimit) {
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);
@@ -61,18 +61,14 @@ public static void main(String[] args) throws Exception {
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 @@ private static void testMemoryAndSwapLimit(String memory, String memandswap) thr
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 =
@@ -247,13 +247,6 @@ public void testMemorySubsystem() {
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 void testMemorySubsystem() {
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)) {