Skip to content

Commit 80642dd

Browse files
Wang ZhuoD-D-H
Wang Zhuo
authored andcommitted
8324817: Parallel GC does not pre-touch all heap pages when AlwaysPreTouch enabled and large page disabled
Reviewed-by: ayang, tschatzl
1 parent 692c9f8 commit 80642dd

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

src/hotspot/share/gc/parallel/mutableSpace.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ void MutableSpace::initialize(MemRegion mr,
120120
}
121121

122122
if (AlwaysPreTouch) {
123+
size_t pretouch_page_size = UseLargePages ? page_size : os::vm_page_size();
123124
PretouchTask::pretouch("ParallelGC PreTouch head", (char*)head.start(), (char*)head.end(),
124-
page_size, pretouch_workers);
125+
pretouch_page_size, pretouch_workers);
125126

126127
PretouchTask::pretouch("ParallelGC PreTouch tail", (char*)tail.start(), (char*)tail.end(),
127-
page_size, pretouch_workers);
128+
pretouch_page_size, pretouch_workers);
128129
}
129130

130131
// Remember where we stopped so that we can continue later.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2014, 2024, Alibaba Group Holding Limited. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package gc.parallel;
25+
26+
/**
27+
* @test TestAlwaysPreTouchBehavior
28+
* @summary Tests AlwaysPreTouch Bahavior, pages of java heap should be pretouched with AlwaysPreTouch enabled. This test reads RSS of test process, which should be bigger than heap size(1g) with AlwaysPreTouch enabled.
29+
* @requires vm.gc.Parallel
30+
* @requires vm.debug != true
31+
* @requires os.family == "linux"
32+
* @requires os.maxMemory > 2G
33+
* @library /test/lib
34+
* @run main/othervm -Xmx1g -Xms1g -XX:+UseParallelGC -XX:+AlwaysPreTouch gc.parallel.TestAlwaysPreTouchBehavior
35+
*/
36+
import java.lang.management.ManagementFactory;
37+
import java.lang.management.ThreadInfo;
38+
import java.lang.management.ThreadMXBean;
39+
import java.nio.file.Files;
40+
import java.nio.file.Path;
41+
import java.nio.file.Paths;
42+
import java.io.IOException;
43+
import java.util.*;
44+
import javax.management.*;
45+
import java.lang.management.*;
46+
import jdk.test.lib.Utils;
47+
import jdk.test.lib.Asserts;
48+
import java.lang.management.*;
49+
import java.util.stream.*;
50+
import java.io.*;
51+
52+
public class TestAlwaysPreTouchBehavior {
53+
public static long getProcessRssInKb() throws IOException {
54+
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
55+
// Read RSS from /proc/$pid/status. Only available on Linux.
56+
String processStatusFile = "/proc/" + pid + "/status";
57+
BufferedReader reader = new BufferedReader(new FileReader(processStatusFile));
58+
String line = null;
59+
while ((line = reader.readLine()) != null) {
60+
if (line.startsWith("VmRSS:")) {
61+
break;
62+
}
63+
}
64+
reader.close();
65+
return Long.valueOf(line.split("\\s+")[1].trim());
66+
}
67+
public static void main(String [] args) {
68+
long rss = 0;
69+
Runtime runtime = Runtime.getRuntime();
70+
long committedMemory = runtime.totalMemory() / 1024; // in kb
71+
try {
72+
rss = getProcessRssInKb();
73+
} catch (Exception e) {
74+
System.out.println("cannot get RSS, just skip");
75+
return; // Did not get avaiable RSS, just ignore this test
76+
}
77+
Asserts.assertGreaterThanOrEqual(rss, committedMemory, "RSS of this process(" + rss + "kb) should be bigger than or equal to committed heap mem(" + committedMemory + "kb)");
78+
}
79+
}
80+

0 commit comments

Comments
 (0)