95249bca1f
Do a step before selecting the limit for the next step. However, as seen on crbug.com/795323, while this fix makes us more precise in our accounting, we do ending up seeing steps more frequently. This ends up invoking the idle scavenger more frequently. To compensate, we adjust the idle scavenger step size. Bug: Change-Id: I7bc2b1785a564dee27aa3ce6a5a196efe9eb6283 Reviewed-on: https://chromium-review.googlesource.com/838440 Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#50816}
115 lines
4.3 KiB
C++
115 lines
4.3 KiB
C++
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <limits>
|
|
|
|
#include "src/globals.h"
|
|
#include "src/heap/scavenge-job.h"
|
|
#include "src/utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
const size_t kScavengeSpeedInBytesPerMs = 500 * KB;
|
|
const size_t kNewSpaceCapacity = 8 * MB;
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitEmptyNewSpace) {
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
kScavengeSpeedInBytesPerMs, 0, kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitFullNewSpace) {
|
|
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
kScavengeSpeedInBytesPerMs, kNewSpaceCapacity, kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitUnknownScavengeSpeed) {
|
|
size_t expected_size = ScavengeJob::kInitialScavengeSpeedInBytesPerMs *
|
|
ScavengeJob::kAverageIdleTimeMs -
|
|
ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
|
|
expected_size = Max(expected_size, ScavengeJob::kMinAllocationLimit);
|
|
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(0, expected_size - 1,
|
|
kNewSpaceCapacity));
|
|
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(0, expected_size,
|
|
kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitLowScavengeSpeed) {
|
|
size_t scavenge_speed = 1 * KB;
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
scavenge_speed, ScavengeJob::kMinAllocationLimit - 1, kNewSpaceCapacity));
|
|
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
scavenge_speed, ScavengeJob::kMinAllocationLimit, kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitAverageScavengeSpeed) {
|
|
size_t expected_size =
|
|
kScavengeSpeedInBytesPerMs * ScavengeJob::kAverageIdleTimeMs -
|
|
ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
kScavengeSpeedInBytesPerMs, ScavengeJob::kMinAllocationLimit,
|
|
kNewSpaceCapacity));
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
kScavengeSpeedInBytesPerMs, expected_size - 1, kNewSpaceCapacity));
|
|
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
kScavengeSpeedInBytesPerMs, expected_size, kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, AllocationLimitHighScavengeSpeed) {
|
|
size_t scavenge_speed = kNewSpaceCapacity;
|
|
size_t expected_size =
|
|
static_cast<size_t>(
|
|
kNewSpaceCapacity *
|
|
ScavengeJob::kMaxAllocationLimitAsFractionOfNewSpace) -
|
|
ScavengeJob::kBytesAllocatedBeforeNextIdleTask;
|
|
EXPECT_FALSE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
scavenge_speed, expected_size - 1, kNewSpaceCapacity));
|
|
EXPECT_TRUE(ScavengeJob::ReachedIdleAllocationLimit(
|
|
scavenge_speed, expected_size + 1, kNewSpaceCapacity));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, EnoughIdleTimeForScavengeUnknownScavengeSpeed) {
|
|
size_t scavenge_speed = ScavengeJob::kInitialScavengeSpeedInBytesPerMs;
|
|
size_t new_space_size = 1 * MB;
|
|
size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
|
|
EXPECT_TRUE(
|
|
ScavengeJob::EnoughIdleTimeForScavenge(expected_time, 0, new_space_size));
|
|
EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(expected_time - 1, 0,
|
|
new_space_size));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, EnoughIdleTimeForScavengeLowScavengeSpeed) {
|
|
size_t scavenge_speed = 1 * KB;
|
|
size_t new_space_size = 1 * MB;
|
|
size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
|
|
EXPECT_TRUE(ScavengeJob::EnoughIdleTimeForScavenge(
|
|
expected_time, scavenge_speed, new_space_size));
|
|
EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(
|
|
expected_time - 1, scavenge_speed, new_space_size));
|
|
}
|
|
|
|
|
|
TEST(ScavengeJob, EnoughIdleTimeForScavengeHighScavengeSpeed) {
|
|
size_t scavenge_speed = kNewSpaceCapacity;
|
|
size_t new_space_size = 1 * MB;
|
|
size_t expected_time = (new_space_size + scavenge_speed - 1) / scavenge_speed;
|
|
EXPECT_TRUE(ScavengeJob::EnoughIdleTimeForScavenge(
|
|
expected_time, scavenge_speed, new_space_size));
|
|
EXPECT_FALSE(ScavengeJob::EnoughIdleTimeForScavenge(
|
|
expected_time - 1, scavenge_speed, new_space_size));
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|