Commit cb91f9c7 authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

base/allocator: Enable periodic decommit by default.

From the finch experiment (see linked bug), this saves .7-5MB of memory per
renderer on Windows and Android, at a cost of ~0.01% of idle time main thread
CPU.

As a consequence, enabling it by default.

Metrics note: The impact it not expected to be seen in the reported metrics, see
the bug for details. This may even be reported as a slight memory regression,
which is expected.

In this CL:
- Enable periodic decommit by default
- Update the unit tests accordingly.

The feature is not removed yet, to leave the possibility to disable it on the
M77 branch.

Bug: 942512
Change-Id: Ia673c55a62e0c273645dc783bbde2f9458a72d32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1712563Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679933}
parent 8f953478
......@@ -17,8 +17,9 @@ namespace internal {
const Feature kNoPartitionAllocDecommit{"NoPartitionAllocDecommit",
FEATURE_DISABLED_BY_DEFAULT};
// TODO(crbug.com/942512): Remove the feature after the M77 branch.
const Feature kPartitionAllocPeriodicDecommit{"PartitionAllocPeriodicDecommit",
FEATURE_DISABLED_BY_DEFAULT};
FEATURE_ENABLED_BY_DEFAULT};
} // namespace internal
......@@ -43,7 +44,6 @@ void PartitionAllocMemoryReclaimer::RegisterPartition(
internal::PartitionRootBase* partition) {
AutoLock lock(lock_);
DCHECK(partition);
DCHECK(!timer_);
auto it_and_whether_inserted = partitions_.insert(partition);
DCHECK(it_and_whether_inserted.second);
}
......
......@@ -73,15 +73,20 @@ TEST_F(PartitionAllocMemoryReclaimerTest, Simple) {
EXPECT_TRUE(task_environment_.NextTaskIsDelayed());
}
TEST_F(PartitionAllocMemoryReclaimerTest, IsDisabledByDefault) {
TEST_F(PartitionAllocMemoryReclaimerTest, IsEnabledByDefault) {
StartReclaimer();
EXPECT_EQ(0u, task_environment_.GetPendingMainThreadTaskCount());
EXPECT_EQ(2u, task_environment_.GetPendingMainThreadTaskCount());
}
TEST_F(PartitionAllocMemoryReclaimerTest, FreesMemory) {
TEST_F(PartitionAllocMemoryReclaimerTest, CanBeDisabled) {
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
scoped_feature_list.InitAndDisableFeature(
internal::kPartitionAllocPeriodicDecommit);
StartReclaimer();
EXPECT_EQ(0u, task_environment_.GetPendingMainThreadTaskCount());
}
TEST_F(PartitionAllocMemoryReclaimerTest, FreesMemory) {
PartitionRootGeneric* root = allocator_->root();
size_t committed_initially = root->total_size_of_committed_pages;
......@@ -99,9 +104,6 @@ TEST_F(PartitionAllocMemoryReclaimerTest, FreesMemory) {
}
TEST_F(PartitionAllocMemoryReclaimerTest, Reclaim) {
StartReclaimer();
EXPECT_EQ(0u, task_environment_.GetPendingMainThreadTaskCount());
PartitionRootGeneric* root = allocator_->root();
size_t committed_initially = root->total_size_of_committed_pages;
......@@ -116,45 +118,13 @@ TEST_F(PartitionAllocMemoryReclaimerTest, Reclaim) {
EXPECT_LT(committed_after, committed_before);
EXPECT_LE(committed_initially, committed_after);
}
// |Reclaim()| is always enabled.
{
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
internal::kPartitionAllocPeriodicDecommit);
AllocateAndFree();
size_t committed_before = root->total_size_of_committed_pages;
EXPECT_GT(committed_before, committed_initially);
PartitionAllocMemoryReclaimer::Instance()->Reclaim();
size_t committed_after = root->total_size_of_committed_pages;
EXPECT_LT(committed_after, committed_before);
EXPECT_LE(committed_initially, committed_after);
}
}
TEST_F(PartitionAllocMemoryReclaimerTest, DeprecatedReclaim) {
StartReclaimer();
EXPECT_EQ(0u, task_environment_.GetPendingMainThreadTaskCount());
PartitionRootGeneric* root = allocator_->root();
// Deprecated reclaim is disabled by default.
{
// Deprecated reclaim enabled by default.
AllocateAndFree();
size_t committed_before = root->total_size_of_committed_pages;
PartitionAllocMemoryReclaimer::Instance()->DeprecatedReclaim();
size_t committed_after = root->total_size_of_committed_pages;
EXPECT_LT(committed_after, committed_before);
}
// Either of the features disables deprecated reclaim.
{
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
internal::kPartitionAllocPeriodicDecommit);
AllocateAndFree();
size_t committed_before = root->total_size_of_committed_pages;
PartitionAllocMemoryReclaimer::Instance()->DeprecatedReclaim();
......@@ -164,18 +134,16 @@ TEST_F(PartitionAllocMemoryReclaimerTest, DeprecatedReclaim) {
PartitionAllocMemoryReclaimer::Instance()->Reclaim();
}
// Deprecated reclaim works when periodic reclaim is disabled.
{
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
internal::kNoPartitionAllocDecommit);
scoped_feature_list.InitAndDisableFeature(
internal::kPartitionAllocPeriodicDecommit);
AllocateAndFree();
size_t committed_before = root->total_size_of_committed_pages;
PartitionAllocMemoryReclaimer::Instance()->DeprecatedReclaim();
size_t committed_after = root->total_size_of_committed_pages;
EXPECT_EQ(committed_after, committed_before);
PartitionAllocMemoryReclaimer::Instance()->Reclaim();
EXPECT_LT(committed_after, committed_before);
}
}
......@@ -185,9 +153,6 @@ TEST_F(PartitionAllocMemoryReclaimerTest, StatsRecording) {
return;
HistogramTester histogram_tester;
test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
internal::kPartitionAllocPeriodicDecommit);
StartReclaimer();
EXPECT_EQ(GetExpectedTasksCount(),
task_environment_.GetPendingMainThreadTaskCount());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment