[heap] Add a flag for setting the initial heap size

When the --initial-heap-size flag is set V8's heap will grow to that
value without full GCs. Additionally, full GCs will be skipped
if the heap size drops below that value.

This patch also adds a comment for the initial_heap_size_in_bytes
parameter of ResourceConstraints:ConfigureDefaultsFromHeapSize

Change-Id: I85fda14bc6422af7bf2193d530efbc9b0bd0553d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1728622
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63054}
This commit is contained in:
Ulan Degenbaev 2019-08-02 12:28:42 +02:00 committed by Commit Bot
parent e17ac92556
commit f391faf1d1
3 changed files with 30 additions and 3 deletions

View File

@ -6467,11 +6467,18 @@ class V8_EXPORT ResourceConstraints {
* provided heap size limit. The heap size includes both the young and
* the old generation.
*
* \param initial_heap_size_in_bytes The initial heap size or zero.
* By default V8 starts with a small heap and dynamically grows it to
* match the set of live objects. This may lead to ineffective
* garbage collections at startup if the live set is large.
* Setting the initial heap size avoids such garbage collections.
* Note that this does not affect young generation garbage collections.
*
* \param maximum_heap_size_in_bytes The hard limit for the heap size.
* When the heap size approaches this limit, V8 will perform series of
* garbage collections and invoke the NearHeapLimitCallback.
* If the garbage collections do not help and the callback does not
* increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
* garbage collections and invoke the NearHeapLimitCallback. If the garbage
* collections do not help and the callback does not increase the limit,
* then V8 will crash with V8::FatalProcessOutOfMemory.
*/
void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes,
size_t maximum_heap_size_in_bytes);

View File

@ -783,6 +783,7 @@ DEFINE_SIZE_T(
"max size of the heap (in Mbytes) "
"both max_semi_space_size and max_old_space_size take precedence. "
"All three flags cannot be specified at the same time.")
DEFINE_SIZE_T(initial_heap_size, 0, "initial size of the heap (in Mbytes)")
DEFINE_BOOL(huge_max_old_generation_size, false,
"Increase max size of the old space to 4 GB for x64 systems with"
"the physical memory bigger than 16 GB")

View File

@ -4480,6 +4480,14 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
initial_semispace_size_ = SemiSpaceSizeFromYoungGenerationSize(
constraints.initial_young_generation_size_in_bytes());
}
if (FLAG_initial_heap_size > 0) {
size_t young_generation, old_generation;
Heap::GenerationSizesFromHeapSize(
static_cast<size_t>(FLAG_initial_heap_size) * MB, &young_generation,
&old_generation);
initial_semispace_size_ =
SemiSpaceSizeFromYoungGenerationSize(young_generation);
}
if (FLAG_min_semi_space_size > 0) {
initial_semispace_size_ =
static_cast<size_t>(FLAG_min_semi_space_size) * MB;
@ -4498,6 +4506,17 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
constraints.initial_old_generation_size_in_bytes();
old_generation_size_configured_ = true;
}
if (FLAG_initial_heap_size > 0) {
size_t initial_heap_size =
static_cast<size_t>(FLAG_initial_heap_size) * MB;
size_t young_generation_size =
YoungGenerationSizeFromSemiSpaceSize(initial_semispace_size_);
initial_old_generation_size_ =
initial_heap_size > young_generation_size
? initial_heap_size - young_generation_size
: 0;
old_generation_size_configured_ = true;
}
if (FLAG_initial_old_space_size > 0) {
initial_old_generation_size_ =
static_cast<size_t>(FLAG_initial_old_space_size) * MB;