From 616c922eb870c5365f1957b970d7042600f76787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Thu, 29 Sep 2022 15:27:03 +0200 Subject: [PATCH] [heap] Support code space sweeping on background threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since code space is now swept concurrently as well, background threads can now sweep code pages on allocation failures as well. Change-Id: I493eb9bd8b1a95f58ddb96a5ced7f87d9397da47 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3929038 Commit-Queue: Dominik Inführ Reviewed-by: Michael Lippautz Auto-Submit: Dominik Inführ Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/main@{#83489} --- src/heap/paged-spaces.cc | 51 ++++++++++++++++------------------------ src/heap/paged-spaces.h | 4 ---- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/heap/paged-spaces.cc b/src/heap/paged-spaces.cc index a6ea1cc941..6b4d143136 100644 --- a/src/heap/paged-spaces.cc +++ b/src/heap/paged-spaces.cc @@ -684,26 +684,23 @@ PagedSpaceBase::RawAllocateBackground(LocalHeap* local_heap, max_size_in_bytes, origin); if (result) return result; - if (IsSweepingAllowedOnThread(local_heap)) { - // Now contribute to sweeping from background thread and then try to - // reallocate. - int max_freed; - { - TRACE_GC_EPOCH(heap()->tracer(), - GCTracer::Scope::MC_BACKGROUND_SWEEPING, - ThreadKind::kBackground); - const int kMaxPagesToSweep = 1; - max_freed = collector->sweeper()->ParallelSweepSpace( - identity(), Sweeper::SweepingMode::kLazyOrConcurrent, - static_cast(min_size_in_bytes), kMaxPagesToSweep); - RefillFreeList(collector->sweeper()); - } + // Now contribute to sweeping from background thread and then try to + // reallocate. + int max_freed; + { + TRACE_GC_EPOCH(heap()->tracer(), GCTracer::Scope::MC_BACKGROUND_SWEEPING, + ThreadKind::kBackground); + const int kMaxPagesToSweep = 1; + max_freed = collector->sweeper()->ParallelSweepSpace( + identity(), Sweeper::SweepingMode::kLazyOrConcurrent, + static_cast(min_size_in_bytes), kMaxPagesToSweep); + RefillFreeList(collector->sweeper()); + } - if (static_cast(max_freed) >= min_size_in_bytes) { - result = TryAllocationFromFreeListBackground(min_size_in_bytes, - max_size_in_bytes, origin); - if (result) return result; - } + if (static_cast(max_freed) >= min_size_in_bytes) { + result = TryAllocationFromFreeListBackground(min_size_in_bytes, + max_size_in_bytes, origin); + if (result) return result; } } @@ -715,13 +712,11 @@ PagedSpaceBase::RawAllocateBackground(LocalHeap* local_heap, if (collector->sweeping_in_progress()) { // Complete sweeping for this space. - if (IsSweepingAllowedOnThread(local_heap)) { - TRACE_GC_EPOCH(heap()->tracer(), GCTracer::Scope::MC_BACKGROUND_SWEEPING, - ThreadKind::kBackground); - collector->DrainSweepingWorklistForSpace(identity()); + TRACE_GC_EPOCH(heap()->tracer(), GCTracer::Scope::MC_BACKGROUND_SWEEPING, + ThreadKind::kBackground); + collector->DrainSweepingWorklistForSpace(identity()); - RefillFreeList(collector->sweeper()); - } + RefillFreeList(collector->sweeper()); // Last try to acquire memory from free list. return TryAllocationFromFreeListBackground(min_size_in_bytes, @@ -777,12 +772,6 @@ PagedSpaceBase::TryAllocationFromFreeListBackground(size_t min_size_in_bytes, return std::make_pair(start, used_size_in_bytes); } -bool PagedSpaceBase::IsSweepingAllowedOnThread(LocalHeap* local_heap) const { - // Code space sweeping is only allowed on main thread. - return (local_heap && local_heap->is_main_thread()) || - identity() != CODE_SPACE; -} - #ifdef DEBUG void PagedSpaceBase::Print() {} #endif diff --git a/src/heap/paged-spaces.h b/src/heap/paged-spaces.h index bfb8d44451..fd30ce2d92 100644 --- a/src/heap/paged-spaces.h +++ b/src/heap/paged-spaces.h @@ -353,10 +353,6 @@ class V8_EXPORT_PRIVATE PagedSpaceBase bool HasPages() const { return first_page() != nullptr; } - // Returns whether sweeping of this space is safe on this thread. Code space - // sweeping is only allowed on the main thread. - bool IsSweepingAllowedOnThread(LocalHeap* local_heap) const; - // Cleans up the space, frees all pages in this space except those belonging // to the initial chunk, uncommits addresses in the initial chunk. void TearDown();