From 61308f2aca3048ff39d7e00637b7845237542b57 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 3 Sep 2026 03:07:31 +0000 Subject: [PATCH] Revert "WarmUpBlockProvider: start the helper thread after 64 block requests" (#553) Deferring the helper thread start to the 64th MarkedBlock request means WTF::Thread::create now runs from tryAllocateAlignedMemory on the mutator while user code is executing. On Windows that hangs @datadog/pprof (JSC SamplingProfiler via the v8::CpuProfiler shim): test/integration/datadog-pprof times out at 120 s on windows-x64 in every Bun CI run pinned past #553 (builds 109483, 109496, 109557) and passes with the same Bun tree pinned to #552 without #553 (build 109518). Revert until the thread start is moved off the allocation path and verified against that test on Windows. --- .../heap/FastMallocAlignedMemoryAllocator.cpp | 19 +------------------ Source/JavaScriptCore/runtime/OptionsList.h | 1 - 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp b/Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp index d433a5d196656..833f607583c2c 100644 --- a/Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp +++ b/Source/JavaScriptCore/heap/FastMallocAlignedMemoryAllocator.cpp @@ -81,23 +81,6 @@ class WarmUpBlockProvider { return Options::useWarmUpMarkedBlocks() && Options::warmUpMarkedBlockCount() && !VM::isInMiniMode(); } - // Bringing up a VM takes a few dozen blocks, and a short program never asks for many more; for - // it the helper thread is only a thread to create, fault a supply on and tear down again at exit. - // So the provider stays dormant until the process has requested this many blocks. A heap that - // is ramping passes the threshold within its first milliseconds of allocation, and the helper - // then fills the supply to its full depth as it would have from the first request. - static bool isPastStartThreshold() - { - static std::atomic past { false }; - static std::atomic requests { 0 }; - if (past.load(std::memory_order_relaxed)) [[likely]] - return true; - if (requests.fetch_add(1, std::memory_order_relaxed) + 1 < Options::warmUpMarkedBlockStartAfterBlocks()) - return false; - past.store(true, std::memory_order_relaxed); - return true; - } - static WarmUpBlockProvider& singleton() { static LazyNeverDestroyed provider; @@ -278,7 +261,7 @@ void* FastMallocAlignedMemoryAllocator::tryAllocateAlignedMemory(size_t alignmen #else // MarkedBlock::tryCreate is the only caller today and always asks for a block-shaped region. // The guard keeps a future caller of some other size from being handed a block. - if (alignment == MarkedBlock::blockSize && size == MarkedBlock::blockSize && WarmUpBlockProvider::isEnabled() && WarmUpBlockProvider::isPastStartThreshold()) { + if (alignment == MarkedBlock::blockSize && size == MarkedBlock::blockSize && WarmUpBlockProvider::isEnabled()) { if (void* block = WarmUpBlockProvider::singleton().tryTake()) return block; } diff --git a/Source/JavaScriptCore/runtime/OptionsList.h b/Source/JavaScriptCore/runtime/OptionsList.h index dd559c4ba163d..00b28122ead71 100644 --- a/Source/JavaScriptCore/runtime/OptionsList.h +++ b/Source/JavaScriptCore/runtime/OptionsList.h @@ -273,7 +273,6 @@ bool hasCapacityToUseLargeGigacage(); v(Double, gcIncrementScale, 0, Normal, nullptr) \ v(Bool, useWarmUpMarkedBlocks, true, Normal, "hand MarkedBlock allocation pages that a helper thread already made resident"_s) \ v(Unsigned, warmUpMarkedBlockCount, 32, Normal, "how many MarkedBlocks the helper thread keeps ready with their pages already resident; 0 turns it off"_s) \ - v(Unsigned, warmUpMarkedBlockStartAfterBlocks, 64, Normal, "how many MarkedBlocks the process allocates before the helper thread starts; a program that stops before that never creates it"_s) \ v(Double, warmUpMarkedBlockIdleTimeout, 10, Normal, "seconds without a MarkedBlock request before the helper thread releases what it is holding and shuts down"_s) \ v(Bool, scribbleFreeCells, false, Normal, nullptr) \ v(Bool, decommitUnusedMarkedBlockPages, true, Normal, "after sweeping a MarkedBlock, return its interior OS pages that hold no live cell to the OS (only where OS pages are smaller than a MarkedBlock)") \