Skip to content

Commit 97e1075

Browse files
committed
8354358: ZGC: ZPartition::prime handle discontiguous reservations correctly
Reviewed-by: stefank, jsikstro, eosterlund
1 parent 51ce312 commit 97e1075

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

src/hotspot/share/gc/z/zPageAllocator.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,36 +1003,43 @@ bool ZPartition::prime(ZWorkers* workers, size_t size) {
10031003
return true;
10041004
}
10051005

1006+
ZArray<ZVirtualMemory> vmems;
1007+
10061008
// Claim virtual memory
1007-
const ZVirtualMemory vmem = claim_virtual(size);
1009+
const size_t claimed_size = claim_virtual(size, &vmems);
1010+
1011+
// The partition must have size available in virtual memory when priming.
1012+
assert(claimed_size == size, "must succeed %zx == %zx", claimed_size, size);
10081013

10091014
// Increase capacity
1010-
increase_capacity(size);
1015+
increase_capacity(claimed_size);
10111016

1012-
// Claim the backing physical memory
1013-
claim_physical(vmem);
1017+
for (ZVirtualMemory vmem : vmems) {
1018+
// Claim the backing physical memory
1019+
claim_physical(vmem);
10141020

1015-
// Commit the claimed physical memory
1016-
const size_t committed = commit_physical(vmem);
1021+
// Commit the claimed physical memory
1022+
const size_t committed = commit_physical(vmem);
10171023

1018-
if (committed != vmem.size()) {
1019-
// This is a failure state. We do not cleanup the maybe partially committed memory.
1020-
return false;
1021-
}
1024+
if (committed != vmem.size()) {
1025+
// This is a failure state. We do not cleanup the maybe partially committed memory.
1026+
return false;
1027+
}
10221028

1023-
map_virtual(vmem);
1029+
map_virtual(vmem);
10241030

1025-
check_numa_mismatch(vmem, _numa_id);
1031+
check_numa_mismatch(vmem, _numa_id);
10261032

1027-
if (AlwaysPreTouch) {
1028-
// Pre-touch memory
1029-
ZPreTouchTask task(vmem.start(), vmem.end());
1030-
workers->run_all(&task);
1031-
}
1033+
if (AlwaysPreTouch) {
1034+
// Pre-touch memory
1035+
ZPreTouchTask task(vmem.start(), vmem.end());
1036+
workers->run_all(&task);
1037+
}
10321038

1033-
// We don't have to take a lock here as no other threads will access the cache
1034-
// until we're finished
1035-
_cache.insert(vmem);
1039+
// We don't have to take a lock here as no other threads will access the cache
1040+
// until we're finished
1041+
_cache.insert(vmem);
1042+
}
10361043

10371044
return true;
10381045
}

test/hotspot/jtreg/gc/z/TestZForceDiscontiguousHeapReservations.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ public class TestZForceDiscontiguousHeapReservations {
3939
private static void testValue(int n) throws Exception {
4040
/**
4141
* Xmx is picked so that it is divisible by 'ZForceDiscontiguousHeapReservations * ZGranuleSize'
42-
* Xms is picked so that it is less than '16 * Xmx / ZForceDiscontiguousHeapReservations' as ZGC
43-
* cannot currently handle a discontiguous heap with an initial size larger than the individual
44-
* reservations.
42+
* Xms is picked to be the same as Xmx
4543
*/
4644
final int XmxInM = 2000;
47-
final int XmsInM = Math.min(16 * XmxInM / (n + 1), XmxInM);
45+
final int XmsInM = XmxInM;
4846
OutputAnalyzer oa = ProcessTools.executeTestJava(
4947
"-XX:+UseZGC",
5048
"-Xms" + XmsInM + "M",

test/hotspot/jtreg/gc/z/TestZNMT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public static void main(String[] args) throws Exception {
6363
private static void testValue(int zForceDiscontiguousHeapReservations) throws Exception {
6464
/**
6565
* Xmx is picked so that it is divisible by 'ZForceDiscontiguousHeapReservations * ZGranuleSize'
66-
* Xms is picked so that it is less than '16 * Xmx / ZForceDiscontiguousHeapReservations' as ZGC
67-
* cannot currently handle a discontiguous heap with an initial size larger than the individual
68-
* reservations.
66+
* Xms is picked so that it is less than '16 * Xmx / ZForceDiscontiguousHeapReservations'
6967
*/
7068
final int XmsInM = Math.min(16 * XmxInM / (zForceDiscontiguousHeapReservations + 1), XmxInM);
7169
OutputAnalyzer oa = ProcessTools.executeTestJava(

0 commit comments

Comments
 (0)