Skip to content

Commit

Permalink
If isCgroupV1() return true, add docker run opts --memory-swappiness=60
Browse files Browse the repository at this point in the history
  • Loading branch information
sendaoYan committed Apr 12, 2024
1 parent 4a9f388 commit ecb7159
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions test/hotspot/jtreg/containers/docker/TestJFREvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* @modules java.base/jdk.internal.misc
* java.management
* jdk.jartool/sun.tools.jar
* @build JfrReporter
* @build JfrReporter jdk.test.whitebox.WhiteBox PrintContainerInfo
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox
* @run driver TestJFREvents
*/
import java.util.List;
Expand All @@ -60,6 +61,7 @@ public static void main(String[] args) throws Exception {
}

DockerTestUtils.buildJdkContainerImage(imageName);
Common.prepareWhiteBox();

try {

Expand Down Expand Up @@ -216,14 +218,24 @@ private static void testMemory(String valueToSet, String expectedValue) throws E


private static void testSwapMemory(String memValueToSet, String swapValueToSet, String expectedTotalValue, String expectedFreeValue) throws Exception {
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet);
OutputAnalyzer out = DockerTestUtils.dockerRunJava(
commonDockerOpts()
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
// The default memory-swappiness vaule is inherited from the host machine, which maybe 0
.addDockerOpts("--memory-swappiness=60")
.addClassOptions("jdk.SwapSpace"));
OutputAnalyzer out;
if (isCgroupV1(memValueToSet)) {
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet + " --memory-swappiness = 60");
out = DockerTestUtils.dockerRunJava(
commonDockerOpts()
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
// With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0
.addDockerOpts("--memory-swappiness=60")
.addClassOptions("jdk.SwapSpace"));
} else {
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet);
out = DockerTestUtils.dockerRunJava(
commonDockerOpts()
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
.addClassOptions("jdk.SwapSpace"));
}
out.shouldHaveExitValue(0)
.shouldContain("totalSize = " + expectedTotalValue)
.shouldContain("freeSize = ");
Expand Down Expand Up @@ -289,4 +301,17 @@ private static void testEnvironmentVariables() throws Exception {
.shouldNotContain(TEST_ENV_VARIABLE)
.shouldNotContain(TEST_ENV_VALUE);
}

private static boolean isCgroupV1(String memValueToSet) throws Exception {
DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo")
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + memValueToSet); // no swap
Common.addWhiteBoxOpts(opts);

OutputAnalyzer out = Common.run(opts);
if (out.contains("cgroupv1")) {
return true;
}
return false;
}
}

0 comments on commit ecb7159

Please sign in to comment.