deps: V8: backport 2444c109f4f8

Original commit message:

    [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 <dinfuehr@chromium.org>
    Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
    Reviewed-by: Omer Katz <omerkatz@chromium.org>
    Commit-Queue: Omer Katz <omerkatz@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#110599}

Refs: https://github.com/v8/v8/commit/2444c109f4f8165024971e15b12eb4611b4cd676
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66736
This commit is contained in:
Austin BurdineandAntoine du Hamel authored and Antoine du Hamel committed 2026-11-14 17:07:24 +01:00
1 parent a4787636cb
commit f775f92e2e
6 files changed
+44 -4

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@
# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.12',
'v8_embedder_string': '-node.13',
##### V8 defaults for Node.js #####
+1
View File
@@ -80,6 +80,7 @@ Artem Kobzar <artem.kobzar@jetbrains.com>
Arthur Islamov <arthur@islamov.ai>
Asuka Shikina <shikina.asuka@gmail.com>
Aurèle Barrière <aurele.barriere@gmail.com>
Austin Burdine <austin@ghost.org>
Aviv Keller <me@aviv.sh>
Ayako Hayasaka <a.iwasaki0128@gmail.com>
Bala Avulapati <bavulapati@gmail.com>
+2
View File
@@ -692,6 +692,7 @@ class V8_EXPORT_PRIVATE GCTracer {
FRIEND_TEST(GCTracerTest, BackgroundMajorMCScope);
FRIEND_TEST(GCTracerTest, CyclePriorities);
FRIEND_TEST(GCTracerTest, EmbedderAllocationThroughput);
FRIEND_TEST(GCTracerTest, HighAllocationRateWithEmbedderAllocation);
FRIEND_TEST(GCTracerTest, MultithreadedBackgroundScope);
FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput);
FRIEND_TEST(GCTracerTest, PerGenerationAllocationThroughput);
@@ -700,6 +701,7 @@ class V8_EXPORT_PRIVATE GCTracer {
FRIEND_TEST(GCTracerTest, IncrementalMarkingDetails);
FRIEND_TEST(GCTracerTest, IncrementalScope);
FRIEND_TEST(GCTracerTest, IncrementalMarkingSpeed);
FRIEND_TEST(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation);
FRIEND_TEST(GCTracerTest, MutatorUtilization);
FRIEND_TEST(GCTracerTest, RecordMarkCompactHistograms);
FRIEND_TEST(GCTracerTest, RecordScavengerHistograms);
-2
View File
@@ -3489,9 +3489,7 @@ namespace {
double ComputeMutatorUtilizationImpl(double mutator_speed,
std::optional<double> gc_speed) {
constexpr double kMinMutatorUtilization = 0.0;
constexpr double kConservativeGcSpeedInBytesPerMillisecond = 200000;
if (mutator_speed == 0) return kMinMutatorUtilization;
if (!gc_speed) gc_speed = kConservativeGcSpeedInBytesPerMillisecond;
// Derivation:
// mutator_utilization = mutator_time / (mutator_time + gc_time)
+1 -1
View File
@@ -695,7 +695,7 @@ class Heap final {
// null.
V8_INLINE bool CanSafepoint() const { return deserialization_complete(); }
bool HasLowAllocationRate();
V8_EXPORT_PRIVATE bool HasLowAllocationRate();
bool HasHighFragmentation();
void ActivateMemoryReducerIfNeeded();
+39
View File
@@ -218,6 +218,45 @@ TEST_F(GCTracerTest, IncrementalScope) {
tracer->current_.scopes[GCTracer::Scope::MC_INCREMENTAL]);
}
TEST_F(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation) {
if (v8_flags.stress_incremental_marking) return;
Heap* heap = i_isolate()->heap();
GCTracer* tracer = heap->tracer();
tracer->ResetForTesting();
tracer->allocation_time_ = base::TimeTicks();
// Two samples 100 ms apart. Young and old generation allocate a little;
// the embedder (CppHeap) and external memory allocate nothing at all, as
// in an embedder that never uses cppgc (e.g. Node.js without node:vm).
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0,
0);
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100,
100, 0, 0);
EXPECT_DOUBLE_EQ(0.0,
tracer->EmbedderAllocationThroughputInBytesPerMillisecond());
EXPECT_TRUE(heap->HasLowAllocationRate());
}
TEST_F(GCTracerTest, HighAllocationRateWithEmbedderAllocation) {
if (v8_flags.stress_incremental_marking) return;
Heap* heap = i_isolate()->heap();
GCTracer* tracer = heap->tracer();
tracer->ResetForTesting();
tracer->allocation_time_ = base::TimeTicks();
// Same as above, but the embedder allocates heavily: 1 GB over 100 ms is
// ~10^7 B/ms, so the embedder term must still report a high allocation
// rate (mu = 200000 / (10^7 + 200000) < 0.993).
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0,
0);
tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100,
100, size_t{1} << 30, 0);
EXPECT_GT(tracer->EmbedderAllocationThroughputInBytesPerMillisecond(), 0.0);
EXPECT_FALSE(heap->HasLowAllocationRate());
}
TEST_F(GCTracerTest, IncrementalMarkingDetails) {
if (v8_flags.stress_incremental_marking) return;
GCTracer* tracer = i_isolate()->heap()->tracer();