[heap] Finish sweeping only for particular space

Instead of completely finishing sweeping in the slow path of allocation,
just sweep all pages for the current PagedSpace. This will help
in making main thread allocation concurrent, since there is no need
anymore to lock the allocation mutexes of other PagedSpaces.

Bug: v8:10315
Change-Id: I1cf76d94fa7a22e726fc71f49c2d5669e4a0598c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2292306
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68822}
This commit is contained in:
Dominik Inführ 2020-07-13 15:37:56 +02:00 committed by Commit Bot
parent e87484c6d5
commit 5a779ecd8b
5 changed files with 17 additions and 3 deletions

View File

@ -622,6 +622,12 @@ void MarkCompactCollector::EnsureSweepingCompleted() {
#endif
}
void MarkCompactCollector::DrainSweepingWorklistForSpace(
AllocationSpace space) {
if (!sweeper()->sweeping_in_progress()) return;
sweeper()->DrainSweepingWorklistForSpace(space);
}
void MarkCompactCollector::ComputeEvacuationHeuristics(
size_t area_size, int* target_fragmentation_percent,
size_t* max_evacuated_bytes) {

View File

@ -516,6 +516,7 @@ class MarkCompactCollector final : public MarkCompactCollectorBase {
//
// Note: Can only be called safely from main thread.
V8_EXPORT_PRIVATE void EnsureSweepingCompleted();
void DrainSweepingWorklistForSpace(AllocationSpace space);
// Checks if sweeping is in progress right now on any space.
bool sweeping_in_progress() const { return sweeper_->sweeping_in_progress(); }

View File

@ -858,8 +858,9 @@ bool PagedSpace::EnsureSweptAndRetryAllocation(int size_in_bytes,
DCHECK(!is_local_space());
MarkCompactCollector* collector = heap()->mark_compact_collector();
if (collector->sweeping_in_progress()) {
// Wait for the sweeper threads here and complete the sweeping phase.
collector->EnsureSweepingCompleted();
// Complete sweeping for this space.
collector->DrainSweepingWorklistForSpace(identity());
RefillFreeList();
// After waiting for the sweeper threads, there may be new free-list
// entries.
@ -920,7 +921,7 @@ bool PagedSpace::RawSlowRefillLinearAllocationArea(int size_in_bytes,
if (collector->sweeping_in_progress()) {
if (FLAG_concurrent_sweeping && !is_compaction_space() &&
!collector->sweeper()->AreSweeperTasksRunning()) {
collector->EnsureSweepingCompleted();
collector->DrainSweepingWorklistForSpace(identity());
}
// First try to refill the free-list, concurrent sweeper threads

View File

@ -247,6 +247,11 @@ void Sweeper::EnsureCompleted() {
sweeping_in_progress_ = false;
}
void Sweeper::DrainSweepingWorklistForSpace(AllocationSpace space) {
if (!sweeping_in_progress_) return;
ParallelSweepSpace(space, 0);
}
void Sweeper::SupportConcurrentSweeping() {
ForAllSweepingSpaces([this](AllocationSpace space) {
const int kMaxPagesToSweepPerSpace = 1;

View File

@ -106,6 +106,7 @@ class Sweeper {
void StartSweeping();
V8_EXPORT_PRIVATE void StartSweeperTasks();
void EnsureCompleted();
void DrainSweepingWorklistForSpace(AllocationSpace space);
bool AreSweeperTasksRunning();
// Support concurrent sweepers from main thread