Skip to content

Commit 2444c10

Browse files
acburdinev8-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[heap] Treat zero allocation throughput as a low allocation rate
Since https://crrev.com/c/5935313 allocation throughput is tracked with SmoothedBytesAndDuration, which has no lower bound. A sampled throughput of exactly 0 -- nothing was allocated, or the smoothed value decayed to 0 after a long idle period -- made ComputeMutatorUtilizationImpl() return a mutator utilization of 0 ("maximal allocation"). For an isolate that never allocates on the CppHeap, HasLowAllocationRate() is then never true and the MemoryReducer cannot start a GC through its low-allocation condition; only the 100s watchdog can. Node.js hits this for any process that does not use node:vm. Remove the special case. A mutator speed of 0 now yields a mutator utilization of 1, i.e. the lowest possible allocation rate. gc_speed is either the conservative default or at least 1 byte/ms, so the formula stays well defined. Bug: 570738027 Change-Id: I84cd51607df3c31c2f1e02bb2fe258e5506131ce Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8521518 Reviewed-by: Dominik Inführ <[email protected]> Commit-Queue: Dominik Inführ <[email protected]> Reviewed-by: Omer Katz <[email protected]> Commit-Queue: Omer Katz <[email protected]> Cr-Commit-Position: refs/heads/main@{#110599}
1 parent 8abc0cf commit 2444c10

5 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎AUTHORS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Artem Kobzar <[email protected]>
8181
Arthur Islamov <[email protected]>
8282
Asuka Shikina <[email protected]>
8383
Aurèle Barrière <[email protected]>
84+
Austin Burdine <[email protected]>
8485
Aviv Keller <[email protected]>
8586
Ayako Hayasaka <[email protected]>
8687
Bala Avulapati <[email protected]>

‎src/heap/gc-tracer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ class V8_EXPORT_PRIVATE GCTracer {
692692
FRIEND_TEST(GCTracerTest, BackgroundMajorMCScope);
693693
FRIEND_TEST(GCTracerTest, CyclePriorities);
694694
FRIEND_TEST(GCTracerTest, EmbedderAllocationThroughput);
695+
FRIEND_TEST(GCTracerTest, HighAllocationRateWithEmbedderAllocation);
695696
FRIEND_TEST(GCTracerTest, MultithreadedBackgroundScope);
696697
FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput);
697698
FRIEND_TEST(GCTracerTest, PerGenerationAllocationThroughput);
@@ -700,6 +701,7 @@ class V8_EXPORT_PRIVATE GCTracer {
700701
FRIEND_TEST(GCTracerTest, IncrementalMarkingDetails);
701702
FRIEND_TEST(GCTracerTest, IncrementalScope);
702703
FRIEND_TEST(GCTracerTest, IncrementalMarkingSpeed);
704+
FRIEND_TEST(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation);
703705
FRIEND_TEST(GCTracerTest, MutatorUtilization);
704706
FRIEND_TEST(GCTracerTest, RecordMarkCompactHistograms);
705707
FRIEND_TEST(GCTracerTest, RecordScavengerHistograms);

‎src/heap/heap.cc‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,9 +3487,7 @@ namespace {
34873487

34883488
double ComputeMutatorUtilizationImpl(double mutator_speed,
34893489
std::optional<double> gc_speed) {
3490-
constexpr double kMinMutatorUtilization = 0.0;
34913490
constexpr double kConservativeGcSpeedInBytesPerMillisecond = 200000;
3492-
if (mutator_speed == 0) return kMinMutatorUtilization;
34933491
if (!gc_speed) gc_speed = kConservativeGcSpeedInBytesPerMillisecond;
34943492
// Derivation:
34953493
// mutator_utilization = mutator_time / (mutator_time + gc_time)

‎src/heap/heap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ class Heap final {
698698
// null.
699699
V8_INLINE bool CanSafepoint() const { return deserialization_complete(); }
700700

701-
bool HasLowAllocationRate();
701+
V8_EXPORT_PRIVATE bool HasLowAllocationRate();
702702
bool HasHighFragmentation();
703703

704704
void ActivateMemoryReducerIfNeeded();

‎test/unittests/heap/gc-tracer-unittest.cc‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,45 @@ TEST_F(GCTracerTest, PerGenerationAllocationThroughput) {
180180
tracer->ExternalAllocationThroughputInBytesPerMillisecond()));
181181
}
182182

183+
TEST_F(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation) {
184+
if (v8_flags.stress_incremental_marking) return;
185+
Heap* heap = i_isolate()->heap();
186+
GCTracer* tracer = heap->tracer();
187+
tracer->ResetForTesting();
188+
tracer->allocation_time_ = base::TimeTicks();
189+
190+
// Two samples 100 ms apart. Young and old generation allocate a little;
191+
// the embedder (CppHeap) and external memory allocate nothing at all, as
192+
// in an embedder that never uses cppgc (e.g. Node.js without node:vm).
193+
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0,
194+
0);
195+
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100,
196+
100, 0, 0);
197+
198+
EXPECT_DOUBLE_EQ(0.0,
199+
tracer->EmbedderAllocationThroughputInBytesPerMillisecond());
200+
EXPECT_TRUE(heap->HasLowAllocationRate());
201+
}
202+
203+
TEST_F(GCTracerTest, HighAllocationRateWithEmbedderAllocation) {
204+
if (v8_flags.stress_incremental_marking) return;
205+
Heap* heap = i_isolate()->heap();
206+
GCTracer* tracer = heap->tracer();
207+
tracer->ResetForTesting();
208+
tracer->allocation_time_ = base::TimeTicks();
209+
210+
// Same as above, but the embedder allocates heavily: 1 GB over 100 ms is
211+
// ~10^7 B/ms, so the embedder term must still report a high allocation
212+
// rate (mu = 200000 / (10^7 + 200000) < 0.993).
213+
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0,
214+
0);
215+
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100,
216+
100, size_t{1} << 30, 0);
217+
218+
EXPECT_GT(tracer->EmbedderAllocationThroughputInBytesPerMillisecond(), 0.0);
219+
EXPECT_FALSE(heap->HasLowAllocationRate());
220+
}
221+
183222
TEST_F(GCTracerTest, RegularScope) {
184223
if (v8_flags.stress_incremental_marking) return;
185224
GCTracer* tracer = i_isolate()->heap()->tracer();

0 commit comments

Comments
 (0)