8257901: ZGC: Take virtual memory usage into account when sizing heap

Reviewed-by: stefank, eosterlund, ayang, tschatzl
This commit is contained in:
Per Liden 2020-12-10 11:10:38 +00:00
parent 29ffffa7b9
commit 0a0691ebcf
7 changed files with 38 additions and 14 deletions

View File

@ -172,3 +172,7 @@ void GCArguments::initialize_heap_flags_and_sizes() {
DEBUG_ONLY(assert_flags();)
}
size_t GCArguments::heap_virtual_to_physical_ratio() {
return 1;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -46,6 +46,11 @@ protected:
public:
virtual void initialize();
virtual size_t conservative_max_heap_alignment() = 0;
// Used by heap size heuristics to determine max
// amount of address space to use for the heap.
virtual size_t heap_virtual_to_physical_ratio();
virtual CollectedHeap* create_heap() = 0;
// Allows GCs to tell external code if it's supported or not in the current setup.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,6 +24,7 @@
#include "precompiled.hpp"
#include "gc/z/zAddressSpaceLimit.hpp"
#include "gc/z/zGlobals.hpp"
#include "runtime/globals.hpp"
#include "runtime/os.hpp"
#include "utilities/align.hpp"
@ -46,6 +47,6 @@ size_t ZAddressSpaceLimit::mark_stack() {
size_t ZAddressSpaceLimit::heap_view() {
// Allow all heap views to occupy 50% of the address space
const size_t limit = address_space_limit() / 2 / ZHeapViews;
const size_t limit = address_space_limit() / MaxVirtMemFraction / ZHeapViews;
return align_up(limit, ZGranuleSize);
}

View File

@ -25,6 +25,7 @@
#include "gc/z/zAddressSpaceLimit.hpp"
#include "gc/z/zArguments.hpp"
#include "gc/z/zCollectedHeap.hpp"
#include "gc/z/zGlobals.hpp"
#include "gc/z/zHeuristics.hpp"
#include "gc/shared/gcArguments.hpp"
#include "runtime/globals.hpp"
@ -94,6 +95,10 @@ void ZArguments::initialize() {
}
}
size_t ZArguments::heap_virtual_to_physical_ratio() {
return ZHeapViews * ZVirtualToPhysicalRatio;
}
size_t ZArguments::conservative_max_heap_alignment() {
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ private:
virtual void initialize();
virtual size_t conservative_max_heap_alignment();
virtual size_t heap_virtual_to_physical_ratio();
virtual CollectedHeap* create_heap();
virtual bool is_supported() const;

View File

@ -1655,11 +1655,18 @@ jint Arguments::set_ergonomics_flags() {
return JNI_OK;
}
julong Arguments::limit_by_allocatable_memory(julong limit) {
julong Arguments::limit_heap_by_allocatable_memory(julong limit) {
julong max_allocatable;
julong result = limit;
if (os::has_allocatable_memory_limit(&max_allocatable)) {
result = MIN2(result, max_allocatable / MaxVirtMemFraction);
// The AggressiveHeap check is a temporary workaround to avoid calling
// GCarguments::heap_virtual_to_physical_ratio() before a GC has been
// selected. This works because AggressiveHeap implies UseParallelGC
// where we know the ratio will be 1. Once the AggressiveHeap option is
// removed, this can be cleaned up.
julong heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments()->heap_virtual_to_physical_ratio());
julong fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio;
result = MIN2(result, max_allocatable / fraction);
}
return result;
}
@ -1775,12 +1782,12 @@ void Arguments::set_heap_size() {
}
#endif // _LP64
reasonable_max = limit_by_allocatable_memory(reasonable_max);
reasonable_max = limit_heap_by_allocatable_memory(reasonable_max);
if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
// An initial heap size was specified on the command line,
// so be sure that the maximum size is consistent. Done
// after call to limit_by_allocatable_memory because that
// after call to limit_heap_by_allocatable_memory because that
// method might reduce the allocation size.
reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
} else if (!FLAG_IS_DEFAULT(MinHeapSize)) {
@ -1798,11 +1805,11 @@ void Arguments::set_heap_size() {
reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
reasonable_minimum = limit_heap_by_allocatable_memory(reasonable_minimum);
if (InitialHeapSize == 0) {
julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
reasonable_initial = limit_heap_by_allocatable_memory(reasonable_initial);
reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
@ -1846,7 +1853,7 @@ jint Arguments::set_aggressive_heap_flags() {
initHeapSize = MIN2(total_memory / (julong) 2,
total_memory - (julong) 160 * M);
initHeapSize = limit_by_allocatable_memory(initHeapSize);
initHeapSize = limit_heap_by_allocatable_memory(initHeapSize);
if (FLAG_IS_DEFAULT(MaxHeapSize)) {
if (FLAG_SET_CMDLINE(MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) {

View File

@ -363,9 +363,10 @@ class Arguments : AllStatic {
static void set_use_compressed_klass_ptrs();
static jint set_ergonomics_flags();
static jint set_shared_spaces_flags_and_archive_paths();
// limits the given memory size by the maximum amount of memory this process is
// currently allowed to allocate or reserve.
static julong limit_by_allocatable_memory(julong size);
// Limits the given heap size by the maximum amount of virtual
// memory this process is currently allowed to use. It also takes
// the virtual-to-physical ratio of the current GC into account.
static julong limit_heap_by_allocatable_memory(julong size);
// Setup heap size
static void set_heap_size();