From 7744b0046af4dbacb7068ae819d8a973cfbf8e40 Mon Sep 17 00:00:00 2001 From: SendaoYan Date: Wed, 17 Apr 2024 08:39:12 +0000 Subject: [PATCH] 8327946: containers/docker/TestJFREvents.java fails when host kernel config vm.swappiness=0 after JDK-8325139 Reviewed-by: sgehwolf --- .../containers/docker/TestJFREvents.java | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/test/hotspot/jtreg/containers/docker/TestJFREvents.java b/test/hotspot/jtreg/containers/docker/TestJFREvents.java index 19bbce1c547..abc9de45db8 100644 --- a/test/hotspot/jtreg/containers/docker/TestJFREvents.java +++ b/test/hotspot/jtreg/containers/docker/TestJFREvents.java @@ -30,6 +30,7 @@ * Also make sure that PIDs are based on value provided by container, * not by the host system. * @requires (docker.support & os.maxMemory >= 2g) + * @modules java.base/jdk.internal.platform * @library /test/lib * @modules java.base/jdk.internal.misc * java.management @@ -44,6 +45,7 @@ import jdk.test.lib.containers.docker.DockerTestUtils; import jdk.test.lib.Asserts; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.Utils; +import jdk.internal.platform.Metrics; public class TestJFREvents { @@ -52,6 +54,7 @@ public class TestJFREvents { private static final String TEST_ENV_VALUE = "unique_value_abc592903xyz"; private static final int availableCPUs = Runtime.getRuntime().availableProcessors(); private static final int UNKNOWN = -100; + private static boolean isCgroupV1 = false; public static void main(String[] args) throws Exception { System.out.println("Test Environment: detected availableCPUs = " + availableCPUs); @@ -59,6 +62,14 @@ public class TestJFREvents { return; } + // If cgroups is not configured, report success. + Metrics metrics = Metrics.systemMetrics(); + if (metrics == null) { + System.out.println("TEST PASSED!!!"); + return; + } + isCgroupV1 = "cgroupv1".equals(metrics.getProvider()); + DockerTestUtils.buildJdkContainerImage(imageName); try { @@ -217,32 +228,36 @@ public class TestJFREvents { 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) - .addClassOptions("jdk.SwapSpace")); - out.shouldHaveExitValue(0) + DockerRunOptions opts = commonDockerOpts(); + opts.addDockerOpts("--memory=" + memValueToSet) + .addDockerOpts("--memory-swap=" + swapValueToSet) + .addClassOptions("jdk.SwapSpace"); + if (isCgroupV1) { + // With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0 + opts.addDockerOpts("--memory-swappiness=60"); + } + OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts); + out.shouldHaveExitValue(0) .shouldContain("totalSize = " + expectedTotalValue) .shouldContain("freeSize = "); - List ls = out.asLinesWithoutVMWarnings(); - for (String cur : ls) { - int idx = cur.indexOf("freeSize = "); - if (idx != -1) { - int startNbr = idx+11; - int endNbr = cur.indexOf(' ', startNbr); - if (endNbr == -1) endNbr = cur.length(); - String freeSizeStr = cur.substring(startNbr, endNbr); - long freeval = Long.parseLong(freeSizeStr); - long totalval = Long.parseLong(expectedTotalValue); - if (0 <= freeval && freeval <= totalval) { - System.out.println("Found freeSize value " + freeval + " is fine"); - } else { - System.out.println("Found freeSize value " + freeval + " is bad"); - throw new Exception("Found free size value is bad"); - } - } - } + List ls = out.asLinesWithoutVMWarnings(); + for (String cur : ls) { + int idx = cur.indexOf("freeSize = "); + if (idx != -1) { + int startNbr = idx+11; + int endNbr = cur.indexOf(' ', startNbr); + if (endNbr == -1) endNbr = cur.length(); + String freeSizeStr = cur.substring(startNbr, endNbr); + long freeval = Long.parseLong(freeSizeStr); + long totalval = Long.parseLong(expectedTotalValue); + if (0 <= freeval && freeval <= totalval) { + System.out.println("Found freeSize value " + freeval + " is fine"); + } else { + System.out.println("Found freeSize value " + freeval + " is bad"); + throw new Exception("Found free size value is bad"); + } + } + } }