Skip to content

Commit 8aa848c

Browse files
authored
cobalt: Tune CC GPU memory settings to reduce footprint (#7527)
This change tunes two GPU memory settings in the compositor to reduce its overall memory footprint, particularly on Android devices. The primary change reduces the amount of memory allocated for offscreen content prepainting. On most Android devices, this was previously set to use up to 67% of the compositor's memory budget for prepainting textures outside the visible viewport. This is lowered to 25%. Experimental results on an android-qa build on Sabrina show this change significantly reduces the memory usage of the compositor (the 'cc' component). When navigating quickly through video content, memory usage dropped from ~70-80 MB to a more stable ~40-50 MB. Further local testing showed that reducing this to 0% (disabling prepainting) could lower usage to 30-40 MB with a minimal impact on user experience. We are proceeding with 25% for now, but could consider further reductions in the future. Additionally, the GPU memory allocation priority was changed from CUTOFF_ALLOW_NICE_TO_HAVE to CUTOFF_ALLOW_REQUIRED_ONLY. While this did not show a significant memory reduction in testing, it is a logical change for our use case, as scrolling is not a primary interaction on most target devices, making "nice-to-have" allocations for scrolling less critical. It's worth noting that while the compositor's component memory decreased, the peak RSS numbers reported by memory-infra did not show a clear reduction. However, this metric is known to fluctuate. The impact of these changes on overall system memory should be verified in production. Bug: 424591313
1 parent 66a3b56 commit 8aa848c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

third_party/blink/renderer/platform/widget/compositing/layer_tree_settings.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
9191
cc::ManagedMemoryPolicy actual = default_policy;
9292
actual.bytes_limit_when_visible = 0;
9393
actual.priority_cutoff_when_visible =
94+
#if BUILDFLAG(IS_COBALT)
95+
gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY;
96+
#else
9497
gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
98+
#endif
9599

96100
// If the value was overridden on the command line, use the specified value.
97101
static bool client_hard_limit_bytes_overridden =
@@ -407,7 +411,11 @@ cc::LayerTreeSettings GenerateLayerTreeSettings(
407411
// On low-end we want to be very careful about killing other
408412
// apps. So initially we use 50% more memory to avoid flickering
409413
// or raster-on-demand.
414+
#if BUILDFLAG(IS_COBALT)
415+
settings.max_memory_for_prepaint_percentage = 0;
416+
#else
410417
settings.max_memory_for_prepaint_percentage = 67;
418+
#endif
411419
} else {
412420
// On other devices we have increased memory excessively to avoid
413421
// raster-on-demand already, so now we reserve 50% _only_ to avoid

third_party/blink/renderer/platform/widget/compositing/layer_tree_settings_unittest.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,33 @@ TEST(LayerTreeSettings, IgnoreGivenMemoryPolicy) {
1515
auto policy =
1616
GetGpuMemoryPolicy(cc::ManagedMemoryPolicy(256), gfx::Size(), 1.f);
1717
EXPECT_EQ(512u * 1024u * 1024u, policy.bytes_limit_when_visible);
18+
#if BUILDFLAG(IS_COBALT)
19+
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
20+
#else
1821
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
22+
#endif
1923
policy.priority_cutoff_when_visible);
2024
}
2125

2226
TEST(LayerTreeSettings, LargeScreensUseMoreMemory) {
2327
auto policy = GetGpuMemoryPolicy(cc::ManagedMemoryPolicy(256),
2428
gfx::Size(4096, 2160), 1.f);
2529
EXPECT_EQ(2u * 512u * 1024u * 1024u, policy.bytes_limit_when_visible);
30+
#if BUILDFLAG(IS_COBALT)
31+
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
32+
#else
2633
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
34+
#endif
2735
policy.priority_cutoff_when_visible);
2836

2937
policy = GetGpuMemoryPolicy(cc::ManagedMemoryPolicy(256),
3038
gfx::Size(2048, 1080), 2.f);
3139
EXPECT_EQ(2u * 512u * 1024u * 1024u, policy.bytes_limit_when_visible);
40+
#if BUILDFLAG(IS_COBALT)
41+
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
42+
#else
3243
EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
44+
#endif
3345
policy.priority_cutoff_when_visible);
3446
}
3547
#endif

0 commit comments

Comments
 (0)