[heap] Support code space sweeping on background threads

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 <dinfuehr@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Auto-Submit: Dominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83489}
This commit is contained in:
Dominik Inführ 2022-09-29 15:27:03 +02:00 committed by V8 LUCI CQ
parent be3d6a3791
commit 616c922eb8
2 changed files with 20 additions and 35 deletions

View File

@ -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<int>(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<int>(min_size_in_bytes), kMaxPagesToSweep);
RefillFreeList(collector->sweeper());
}
if (static_cast<size_t>(max_freed) >= min_size_in_bytes) {
result = TryAllocationFromFreeListBackground(min_size_in_bytes,
max_size_in_bytes, origin);
if (result) return result;
}
if (static_cast<size_t>(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

View File

@ -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();