Skip to content

Commit 0a0691e

Browse files
committedDec 10, 2020
8257901: ZGC: Take virtual memory usage into account when sizing heap
Reviewed-by: stefank, eosterlund, ayang, tschatzl
1 parent 29ffffa commit 0a0691e

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed
 

‎src/hotspot/share/gc/shared/gcArguments.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ void GCArguments::initialize_heap_flags_and_sizes() {
172172

173173
DEBUG_ONLY(assert_flags();)
174174
}
175+
176+
size_t GCArguments::heap_virtual_to_physical_ratio() {
177+
return 1;
178+
}

‎src/hotspot/share/gc/shared/gcArguments.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -46,6 +46,11 @@ class GCArguments {
4646
public:
4747
virtual void initialize();
4848
virtual size_t conservative_max_heap_alignment() = 0;
49+
50+
// Used by heap size heuristics to determine max
51+
// amount of address space to use for the heap.
52+
virtual size_t heap_virtual_to_physical_ratio();
53+
4954
virtual CollectedHeap* create_heap() = 0;
5055

5156
// Allows GCs to tell external code if it's supported or not in the current setup.

‎src/hotspot/share/gc/z/zAddressSpaceLimit.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
#include "precompiled.hpp"
2525
#include "gc/z/zAddressSpaceLimit.hpp"
2626
#include "gc/z/zGlobals.hpp"
27+
#include "runtime/globals.hpp"
2728
#include "runtime/os.hpp"
2829
#include "utilities/align.hpp"
2930

@@ -46,6 +47,6 @@ size_t ZAddressSpaceLimit::mark_stack() {
4647

4748
size_t ZAddressSpaceLimit::heap_view() {
4849
// Allow all heap views to occupy 50% of the address space
49-
const size_t limit = address_space_limit() / 2 / ZHeapViews;
50+
const size_t limit = address_space_limit() / MaxVirtMemFraction / ZHeapViews;
5051
return align_up(limit, ZGranuleSize);
5152
}

‎src/hotspot/share/gc/z/zArguments.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "gc/z/zAddressSpaceLimit.hpp"
2626
#include "gc/z/zArguments.hpp"
2727
#include "gc/z/zCollectedHeap.hpp"
28+
#include "gc/z/zGlobals.hpp"
2829
#include "gc/z/zHeuristics.hpp"
2930
#include "gc/shared/gcArguments.hpp"
3031
#include "runtime/globals.hpp"
@@ -94,6 +95,10 @@ void ZArguments::initialize() {
9495
}
9596
}
9697

98+
size_t ZArguments::heap_virtual_to_physical_ratio() {
99+
return ZHeapViews * ZVirtualToPhysicalRatio;
100+
}
101+
97102
size_t ZArguments::conservative_max_heap_alignment() {
98103
return 0;
99104
}

‎src/hotspot/share/gc/z/zArguments.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@ class ZArguments : public GCArguments {
3434

3535
virtual void initialize();
3636
virtual size_t conservative_max_heap_alignment();
37+
virtual size_t heap_virtual_to_physical_ratio();
3738
virtual CollectedHeap* create_heap();
3839

3940
virtual bool is_supported() const;

‎src/hotspot/share/runtime/arguments.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,18 @@ jint Arguments::set_ergonomics_flags() {
16551655
return JNI_OK;
16561656
}
16571657

1658-
julong Arguments::limit_by_allocatable_memory(julong limit) {
1658+
julong Arguments::limit_heap_by_allocatable_memory(julong limit) {
16591659
julong max_allocatable;
16601660
julong result = limit;
16611661
if (os::has_allocatable_memory_limit(&max_allocatable)) {
1662-
result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1662+
// The AggressiveHeap check is a temporary workaround to avoid calling
1663+
// GCarguments::heap_virtual_to_physical_ratio() before a GC has been
1664+
// selected. This works because AggressiveHeap implies UseParallelGC
1665+
// where we know the ratio will be 1. Once the AggressiveHeap option is
1666+
// removed, this can be cleaned up.
1667+
julong heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments()->heap_virtual_to_physical_ratio());
1668+
julong fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio;
1669+
result = MIN2(result, max_allocatable / fraction);
16631670
}
16641671
return result;
16651672
}
@@ -1775,12 +1782,12 @@ void Arguments::set_heap_size() {
17751782
}
17761783
#endif // _LP64
17771784

1778-
reasonable_max = limit_by_allocatable_memory(reasonable_max);
1785+
reasonable_max = limit_heap_by_allocatable_memory(reasonable_max);
17791786

17801787
if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
17811788
// An initial heap size was specified on the command line,
17821789
// so be sure that the maximum size is consistent. Done
1783-
// after call to limit_by_allocatable_memory because that
1790+
// after call to limit_heap_by_allocatable_memory because that
17841791
// method might reduce the allocation size.
17851792
reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
17861793
} else if (!FLAG_IS_DEFAULT(MinHeapSize)) {
@@ -1798,11 +1805,11 @@ void Arguments::set_heap_size() {
17981805

17991806
reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
18001807

1801-
reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
1808+
reasonable_minimum = limit_heap_by_allocatable_memory(reasonable_minimum);
18021809

18031810
if (InitialHeapSize == 0) {
18041811
julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
1805-
reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1812+
reasonable_initial = limit_heap_by_allocatable_memory(reasonable_initial);
18061813

18071814
reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
18081815
reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
@@ -1846,7 +1853,7 @@ jint Arguments::set_aggressive_heap_flags() {
18461853
initHeapSize = MIN2(total_memory / (julong) 2,
18471854
total_memory - (julong) 160 * M);
18481855

1849-
initHeapSize = limit_by_allocatable_memory(initHeapSize);
1856+
initHeapSize = limit_heap_by_allocatable_memory(initHeapSize);
18501857

18511858
if (FLAG_IS_DEFAULT(MaxHeapSize)) {
18521859
if (FLAG_SET_CMDLINE(MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) {

‎src/hotspot/share/runtime/arguments.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,10 @@ class Arguments : AllStatic {
363363
static void set_use_compressed_klass_ptrs();
364364
static jint set_ergonomics_flags();
365365
static jint set_shared_spaces_flags_and_archive_paths();
366-
// limits the given memory size by the maximum amount of memory this process is
367-
// currently allowed to allocate or reserve.
368-
static julong limit_by_allocatable_memory(julong size);
366+
// Limits the given heap size by the maximum amount of virtual
367+
// memory this process is currently allowed to use. It also takes
368+
// the virtual-to-physical ratio of the current GC into account.
369+
static julong limit_heap_by_allocatable_memory(julong size);
369370
// Setup heap size
370371
static void set_heap_size();
371372

0 commit comments

Comments
 (0)
Please sign in to comment.