[heap] Add API to set heap semi-space limits in KB.

This relands parts of "[heap] Allow a minimum semi-space size of 512K."
excluding the actual semi-space size change.

This partially reverts commit f341bb0f62

> Original commit message:
> Revert "[heap] Allow a minimum semi-space size of 512K."
> This reverts commit 0d2ed6c328.
> The CL introduced perf regressions: crbug.com/735649.
> We are going to reland the CL in an isolated V8 roll to ensure
> that perf regressions are attributed correctly.

> Original commit message:
> > [heap] Allow a minimum semi-space size of 512K.
> > This CL also reduces the minimum semi-space size to 512K.
> > BUG=chromium:716032
> BUG=chromium:735649

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I5ed66b72104aa877d67fcd20bdadc807ea1551c3
Reviewed-on: https://chromium-review.googlesource.com/575065
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46762}
This commit is contained in:
Ulan Degenbaev 2017-07-19 11:53:06 +02:00 committed by Commit Bot
parent 91c1a81d0e
commit bb29f9a4d6
8 changed files with 71 additions and 42 deletions

View File

@ -5986,6 +5986,8 @@ V8_INLINE Local<Boolean> False(Isolate* isolate);
*
* The arguments for set_max_semi_space_size, set_max_old_space_size,
* set_max_executable_size, set_code_range_size specify limits in MB.
*
* The argument for set_max_semi_space_size_in_kb is in KB.
*/
class V8_EXPORT ResourceConstraints {
public:
@ -6003,10 +6005,28 @@ class V8_EXPORT ResourceConstraints {
void ConfigureDefaults(uint64_t physical_memory,
uint64_t virtual_memory_limit);
int max_semi_space_size() const { return max_semi_space_size_; }
void set_max_semi_space_size(int limit_in_mb) {
max_semi_space_size_ = limit_in_mb;
// Returns the max semi-space size in MB.
V8_DEPRECATE_SOON("Use max_semi_space_size_in_kb()",
int max_semi_space_size()) {
return static_cast<int>(max_semi_space_size_in_kb_ / 1024);
}
// Sets the max semi-space size in MB.
V8_DEPRECATE_SOON("Use set_max_semi_space_size_in_kb(size_t limit_in_kb)",
void set_max_semi_space_size(int limit_in_mb)) {
max_semi_space_size_in_kb_ = limit_in_mb * 1024;
}
// Returns the max semi-space size in KB.
size_t max_semi_space_size_in_kb() const {
return max_semi_space_size_in_kb_;
}
// Sets the max semi-space size in KB.
void set_max_semi_space_size_in_kb(size_t limit_in_kb) {
max_semi_space_size_in_kb_ = limit_in_kb;
}
int max_old_space_size() const { return max_old_space_size_; }
void set_max_old_space_size(int limit_in_mb) {
max_old_space_size_ = limit_in_mb;
@ -6032,7 +6052,10 @@ class V8_EXPORT ResourceConstraints {
}
private:
int max_semi_space_size_;
// max_semi_space_size_ is in KB
size_t max_semi_space_size_in_kb_;
// The remaining limits are in MB
int max_old_space_size_;
int max_executable_size_;
uint32_t* stack_limit_;

View File

@ -878,7 +878,7 @@ Extension::Extension(const char* name,
}
ResourceConstraints::ResourceConstraints()
: max_semi_space_size_(0),
: max_semi_space_size_in_kb_(0),
max_old_space_size_(0),
stack_limit_(NULL),
code_range_size_(0),
@ -886,8 +886,8 @@ ResourceConstraints::ResourceConstraints()
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
uint64_t virtual_memory_limit) {
set_max_semi_space_size(
static_cast<int>(i::Heap::ComputeMaxSemiSpaceSize(physical_memory)));
set_max_semi_space_size_in_kb(
i::Heap::ComputeMaxSemiSpaceSize(physical_memory));
set_max_old_space_size(
static_cast<int>(i::Heap::ComputeMaxOldGenerationSize(physical_memory)));
set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize);
@ -903,7 +903,7 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
void SetResourceConstraints(i::Isolate* isolate,
const ResourceConstraints& constraints) {
int semi_space_size = constraints.max_semi_space_size();
size_t semi_space_size = constraints.max_semi_space_size_in_kb();
int old_space_size = constraints.max_old_space_size();
size_t code_range_size = constraints.code_range_size();
size_t max_pool_size = constraints.max_zone_pool_size();

View File

@ -5273,16 +5273,18 @@ void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) {
// TODO(1236194): Since the heap size is configurable on the command line
// and through the API, we should gracefully handle the case that the heap
// size is not big enough to fit all the initial objects.
bool Heap::ConfigureHeap(size_t max_semi_space_size, size_t max_old_space_size,
size_t code_range_size) {
bool Heap::ConfigureHeap(size_t max_semi_space_size_in_kb,
size_t max_old_generation_size_in_mb,
size_t code_range_size_in_mb) {
if (HasBeenSetUp()) return false;
// Overwrite default configuration.
if (max_semi_space_size != 0) {
max_semi_space_size_ = max_semi_space_size * MB;
if (max_semi_space_size_in_kb != 0) {
max_semi_space_size_ =
ROUND_UP(max_semi_space_size_in_kb * KB, Page::kPageSize);
}
if (max_old_space_size != 0) {
max_old_generation_size_ = max_old_space_size * MB;
if (max_old_generation_size_in_mb != 0) {
max_old_generation_size_ = max_old_generation_size_in_mb * MB;
}
// If max space size flags are specified overwrite the configuration.
@ -5353,7 +5355,7 @@ bool Heap::ConfigureHeap(size_t max_semi_space_size, size_t max_old_space_size,
FixedArray::SizeFor(JSArray::kInitialMaxFastElementArray) +
AllocationMemento::kSize));
code_range_size_ = code_range_size * MB;
code_range_size_ = code_range_size_in_mb * MB;
configured_ = true;
return true;

View File

@ -573,9 +573,11 @@ class Heap {
static const int kPointerMultiplier = i::kPointerSize / 4;
#endif
// The new space size has to be a power of 2. Sizes are in MB.
static const int kMinSemiSpaceSize = 1 * kPointerMultiplier;
static const int kMaxSemiSpaceSize = 8 * kPointerMultiplier;
// Semi-space size needs to be a multiple of page size.
static const int kMinSemiSpaceSizeInKB =
2 * kPointerMultiplier * ((1 << kPageSizeBits) / KB);
static const int kMaxSemiSpaceSizeInKB =
16 * kPointerMultiplier * ((1 << kPageSizeBits) / KB);
// The old space size has to be a multiple of Page::kPageSize.
// Sizes are in MB.
@ -925,10 +927,14 @@ class Heap {
// Initialization. ===========================================================
// ===========================================================================
// Configure heap size in MB before setup. Return false if the heap has been
// set up already.
bool ConfigureHeap(size_t max_semi_space_size, size_t max_old_space_size,
size_t code_range_size);
// Configure heap sizes
// max_semi_space_size_in_kb: maximum semi-space size in KB
// max_old_generation_size_in_mb: maximum old generation size in MB
// code_range_size_in_mb: code range size in MB
// Return false if the heap has been set up already.
bool ConfigureHeap(size_t max_semi_space_size_in_kb,
size_t max_old_generation_size_in_mb,
size_t code_range_size_in_mb);
bool ConfigureHeapDefault();
// Prepares the heap, setting up memory areas that are needed in the isolate
@ -1302,10 +1308,12 @@ class Heap {
uint64_t capped_physical_memory =
Max(Min(physical_memory, max_physical_memory), min_physical_memory);
// linearly scale max semi-space size: (X-A)/(B-A)*(D-C)+C
return static_cast<int>(((capped_physical_memory - min_physical_memory) *
(kMaxSemiSpaceSize - kMinSemiSpaceSize)) /
(max_physical_memory - min_physical_memory) +
kMinSemiSpaceSize);
int semi_space_size_in_kb =
static_cast<int>(((capped_physical_memory - min_physical_memory) *
(kMaxSemiSpaceSizeInKB - kMinSemiSpaceSizeInKB)) /
(max_physical_memory - min_physical_memory) +
kMinSemiSpaceSizeInKB);
return RoundUp(semi_space_size_in_kb, (1 << kPageSizeBits) / KB);
}
// Returns the capacity of the heap in bytes w/o growing. Heap grows when

View File

@ -4806,7 +4806,7 @@ HEAP_TEST(Regress538257) {
FLAG_manual_evacuation_candidates_selection = true;
v8::Isolate::CreateParams create_params;
// Set heap limits.
create_params.constraints.set_max_semi_space_size(1);
create_params.constraints.set_max_semi_space_size_in_kb(1024);
create_params.constraints.set_max_old_space_size(6);
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);

View File

@ -20325,7 +20325,7 @@ class InitDefaultIsolateThread : public v8::base::Thread {
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
switch (testCase_) {
case SetResourceConstraints: {
create_params.constraints.set_max_semi_space_size(1);
create_params.constraints.set_max_semi_space_size_in_kb(1024);
create_params.constraints.set_max_old_space_size(6);
break;
}

View File

@ -1301,7 +1301,7 @@ TEST(SliceFromSlice) {
UNINITIALIZED_TEST(OneByteArrayJoin) {
v8::Isolate::CreateParams create_params;
// Set heap limits.
create_params.constraints.set_max_semi_space_size(1);
create_params.constraints.set_max_semi_space_size_in_kb(1024);
create_params.constraints.set_max_old_space_size(7);
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);

View File

@ -63,19 +63,15 @@ TEST(Heap, MaxHeapGrowingFactor) {
}
TEST(Heap, SemiSpaceSize) {
uint64_t configurations[][2] = {
{0, 1 * i::Heap::kPointerMultiplier},
{512 * i::MB, 1 * i::Heap::kPointerMultiplier},
{1 * i::GB, 3 * i::Heap::kPointerMultiplier},
{2 * static_cast<uint64_t>(i::GB), i::Heap::kMaxSemiSpaceSize},
{4 * static_cast<uint64_t>(i::GB), i::Heap::kMaxSemiSpaceSize},
{8 * static_cast<uint64_t>(i::GB), i::Heap::kMaxSemiSpaceSize}};
for (auto configuration : configurations) {
ASSERT_EQ(configuration[1],
static_cast<uint64_t>(
i::Heap::ComputeMaxSemiSpaceSize(configuration[0])));
}
const size_t KB = static_cast<size_t>(i::KB);
const size_t MB = static_cast<size_t>(i::MB);
const size_t pm = i::Heap::kPointerMultiplier;
ASSERT_EQ(1u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(0u) * KB);
ASSERT_EQ(1u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(512u * MB) * KB);
ASSERT_EQ(7u * pm * MB / 2,
i::Heap::ComputeMaxSemiSpaceSize(1024u * MB) * KB);
ASSERT_EQ(8u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(2024u * MB) * KB);
ASSERT_EQ(8u * pm * MB, i::Heap::ComputeMaxSemiSpaceSize(4095u * MB) * KB);
}
TEST(Heap, OldGenerationSize) {