From bb195749c89cb8996b14dca9849d52f21572ce63 Mon Sep 17 00:00:00 2001 From: Troels Bjerre Lund Date: Thu, 28 Sep 2023 16:05:26 +0200 Subject: [PATCH] [K/N] Re-enable mutator assist Also remove disabling of GC scheduling during GC --- kotlin-native/runtime/src/alloc/custom/cpp/Heap.cpp | 6 ++++++ .../src/gcScheduler/adaptive/cpp/GCSchedulerImpl.hpp | 1 - .../src/gcScheduler/common/cpp/GCSchedulerConfig.hpp | 2 +- .../src/gcScheduler/common/cpp/HeapGrowthController.hpp | 4 ---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kotlin-native/runtime/src/alloc/custom/cpp/Heap.cpp b/kotlin-native/runtime/src/alloc/custom/cpp/Heap.cpp index 9fc1695fd56..01548cc5d8f 100644 --- a/kotlin-native/runtime/src/alloc/custom/cpp/Heap.cpp +++ b/kotlin-native/runtime/src/alloc/custom/cpp/Heap.cpp @@ -116,6 +116,12 @@ std::vector Heap::GetAllocatedObjects() noexcept { return unfinalized; } +// This overhead is calculated under the assumption that each thread holds on +// to one almost empty page of each page type currently in use. Thus, the +// per-thread-overhead is the sum of the page sizes of the page types that the +// Heap has currently allocated, i.e., whose PageStores are not empty. This +// estimate has two-sided error, and there are still pathological allocation +// patterns that would lead to constant GC triggering. size_t Heap::EstimateOverheadPerThread() noexcept { size_t overHeadPerThread = 0; if (!nextFitPages_.isEmpty()) overHeadPerThread += NEXT_FIT_PAGE_SIZE; diff --git a/kotlin-native/runtime/src/gcScheduler/adaptive/cpp/GCSchedulerImpl.hpp b/kotlin-native/runtime/src/gcScheduler/adaptive/cpp/GCSchedulerImpl.hpp index a42173841a1..0d8940e45de 100644 --- a/kotlin-native/runtime/src/gcScheduler/adaptive/cpp/GCSchedulerImpl.hpp +++ b/kotlin-native/runtime/src/gcScheduler/adaptive/cpp/GCSchedulerImpl.hpp @@ -64,7 +64,6 @@ public: void onGCStart() noexcept { regularIntervalPacer_.OnPerformFullGC(); - heapGrowthController_.unsetBoundaries(); timer_.restart(config_.regularGcInterval()); } diff --git a/kotlin-native/runtime/src/gcScheduler/common/cpp/GCSchedulerConfig.hpp b/kotlin-native/runtime/src/gcScheduler/common/cpp/GCSchedulerConfig.hpp index 6d236210ba4..798f2c566f6 100644 --- a/kotlin-native/runtime/src/gcScheduler/common/cpp/GCSchedulerConfig.hpp +++ b/kotlin-native/runtime/src/gcScheduler/common/cpp/GCSchedulerConfig.hpp @@ -40,7 +40,7 @@ struct GCSchedulerConfig { std::atomic heapTriggerCoefficient = 0.9; // See `mutatorAssists()`. std::atomic> mutatorAssistsImpl = - static_cast>(MutatorAssists::kDisable); + static_cast>(MutatorAssists::kDefault); std::chrono::microseconds regularGcInterval() const { return std::chrono::microseconds(regularGcIntervalMicroseconds.load()); } diff --git a/kotlin-native/runtime/src/gcScheduler/common/cpp/HeapGrowthController.hpp b/kotlin-native/runtime/src/gcScheduler/common/cpp/HeapGrowthController.hpp index ea19ca01d2c..1d7f30e731c 100644 --- a/kotlin-native/runtime/src/gcScheduler/common/cpp/HeapGrowthController.hpp +++ b/kotlin-native/runtime/src/gcScheduler/common/cpp/HeapGrowthController.hpp @@ -31,10 +31,6 @@ public: triggerHeapBytes_ = targetHeapBytes_ * config_.heapTriggerCoefficient.load(std::memory_order_relaxed); } - void unsetBoundaries() noexcept { - targetHeapBytes_ = triggerHeapBytes_ = std::numeric_limits::max(); - } - // Can be called by any thread. MemoryBoundary boundaryForHeapSize(size_t totalAllocatedBytes) noexcept { if (totalAllocatedBytes >= targetHeapBytes_) {