Skip to content

Commit bfccd51

Browse files
mi-acCommit bot
authored andcommitted
Revert of [heap] Add more tasks for parallel compaction (patchset v8#11 id:200001 of https://codereview.chromium.org/1354383002/ )
Reason for revert: [Sheriff] May have caused this new flake: http://build.chromium.org/p/client.v8/builders/V8%20Linux/builds/5412 Original issue's description: > [heap] Add more tasks for parallel compaction > > - We now compute the number of parallel compaction tasks, depending on the > evacuation candidate list, the number of cores, and some hard limit. > - Free memory is moved over to compaction tasks (up to some limit) > - Moving over memory is done by dividing the free list of a given space up among > other free lists. Since this is potentially slow we limit the maximum amount > of moved memory. > > BUG=chromium:524425 > LOG=N > > Committed: https://crrev.com/0e842418835eea85886a06cf37052895bc8a17db > Cr-Commit-Position: refs/heads/master@{#30886} [email protected],[email protected] NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=chromium:524425 Review URL: https://codereview.chromium.org/1356363005 Cr-Commit-Position: refs/heads/master@{#30888}
1 parent afa60ff commit bfccd51

File tree

5 files changed

+44
-145
lines changed

5 files changed

+44
-145
lines changed

src/heap/mark-compact.cc

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "src/base/atomicops.h"
88
#include "src/base/bits.h"
9-
#include "src/base/sys-info.h"
109
#include "src/code-stubs.h"
1110
#include "src/compilation-cache.h"
1211
#include "src/cpu-profiler.h"
@@ -3371,39 +3370,26 @@ bool MarkCompactCollector::EvacuateLiveObjectsFromPage(
33713370
}
33723371

33733372

3374-
int MarkCompactCollector::NumberOfParallelCompactionTasks() {
3375-
if (!FLAG_parallel_compaction) return 1;
3376-
// We cap the number of parallel compaction tasks by
3377-
// - (#cores - 1)
3378-
// - a value depending on the list of evacuation candidates
3379-
// - a hard limit
3380-
const int kPagesPerCompactionTask = 4;
3381-
const int kMaxCompactionTasks = 8;
3382-
return Min(kMaxCompactionTasks,
3383-
Min(1 + evacuation_candidates_.length() / kPagesPerCompactionTask,
3384-
Max(1, base::SysInfo::NumberOfProcessors() - 1)));
3385-
}
3386-
3387-
33883373
void MarkCompactCollector::EvacuatePagesInParallel() {
33893374
if (evacuation_candidates_.length() == 0) return;
33903375

3391-
const int num_tasks = NumberOfParallelCompactionTasks();
3376+
int num_tasks = 1;
3377+
if (FLAG_parallel_compaction) {
3378+
num_tasks = NumberOfParallelCompactionTasks();
3379+
}
33923380

33933381
// Set up compaction spaces.
33943382
CompactionSpaceCollection** compaction_spaces_for_tasks =
33953383
new CompactionSpaceCollection*[num_tasks];
3396-
FreeList** free_lists = new FreeList*[2 * num_tasks];
33973384
for (int i = 0; i < num_tasks; i++) {
33983385
compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap());
3399-
free_lists[i] = compaction_spaces_for_tasks[i]->Get(OLD_SPACE)->free_list();
3400-
free_lists[i + num_tasks] =
3401-
compaction_spaces_for_tasks[i]->Get(CODE_SPACE)->free_list();
34023386
}
3403-
heap()->old_space()->DivideFreeLists(free_lists, num_tasks, 1 * MB);
3404-
heap()->code_space()->DivideFreeLists(&free_lists[num_tasks], num_tasks,
3405-
1 * MB);
3406-
delete[] free_lists;
3387+
3388+
compaction_spaces_for_tasks[0]->Get(OLD_SPACE)->MoveOverFreeMemory(
3389+
heap()->old_space());
3390+
compaction_spaces_for_tasks[0]
3391+
->Get(CODE_SPACE)
3392+
->MoveOverFreeMemory(heap()->code_space());
34073393

34083394
compaction_in_progress_ = true;
34093395
// Kick off parallel tasks.
@@ -3414,8 +3400,10 @@ void MarkCompactCollector::EvacuatePagesInParallel() {
34143400
v8::Platform::kShortRunningTask);
34153401
}
34163402

3417-
// Perform compaction on the main thread.
3403+
// Contribute in main thread. Counter and signal are in principal not needed.
3404+
concurrent_compaction_tasks_active_++;
34183405
EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_);
3406+
pending_compaction_tasks_semaphore_.Signal();
34193407

34203408
WaitUntilCompactionCompleted();
34213409

src/heap/mark-compact.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,11 @@ class MarkCompactCollector {
709709

710710
void EvacuatePagesInParallel();
711711

712-
// The number of parallel compaction tasks, including the main thread.
713-
int NumberOfParallelCompactionTasks();
712+
int NumberOfParallelCompactionTasks() {
713+
// TODO(hpayer, mlippautz): Figure out some logic to determine the number
714+
// of compaction tasks.
715+
return 1;
716+
}
714717

715718
void WaitUntilCompactionCompleted();
716719

src/heap/spaces.cc

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,40 +2218,6 @@ intptr_t FreeList::Concatenate(FreeList* free_list) {
22182218
}
22192219

22202220

2221-
FreeSpace* PagedSpace::TryRemoveMemory() {
2222-
FreeSpace* space = nullptr;
2223-
int node_size = 0;
2224-
space = free_list()->FindNodeIn(FreeList::kHuge, &node_size);
2225-
if (space == nullptr)
2226-
space = free_list()->FindNodeIn(FreeList::kLarge, &node_size);
2227-
if (space == nullptr)
2228-
space = free_list()->FindNodeIn(FreeList::kMedium, &node_size);
2229-
if (space == nullptr)
2230-
space = free_list()->FindNodeIn(FreeList::kSmall, &node_size);
2231-
if (space != nullptr) {
2232-
accounting_stats_.DecreaseCapacity(node_size);
2233-
}
2234-
return space;
2235-
}
2236-
2237-
2238-
void PagedSpace::DivideFreeLists(FreeList** free_lists, int num,
2239-
intptr_t limit) {
2240-
CHECK(num > 0);
2241-
CHECK(free_lists != nullptr);
2242-
if (limit == 0) {
2243-
limit = std::numeric_limits<intptr_t>::max();
2244-
}
2245-
int index = 0;
2246-
FreeSpace* space = nullptr;
2247-
while (((space = TryRemoveMemory()) != nullptr) &&
2248-
(free_lists[index]->available() < limit)) {
2249-
free_lists[index]->owner()->AddMemory(space->address(), space->size());
2250-
index = (index + 1) % num;
2251-
}
2252-
}
2253-
2254-
22552221
void FreeList::Reset() {
22562222
small_list_.Reset();
22572223
medium_list_.Reset();
@@ -2295,62 +2261,39 @@ int FreeList::Free(Address start, int size_in_bytes) {
22952261
}
22962262

22972263

2298-
void FreeList::UpdateFragmentationStats(FreeListCategoryType category,
2299-
Address address, int size) {
2300-
Page* page = Page::FromAddress(address);
2301-
switch (category) {
2302-
case kSmall:
2303-
page->add_available_in_small_free_list(size);
2304-
break;
2305-
case kMedium:
2306-
page->add_available_in_medium_free_list(size);
2307-
break;
2308-
case kLarge:
2309-
page->add_available_in_large_free_list(size);
2310-
break;
2311-
case kHuge:
2312-
page->add_available_in_huge_free_list(size);
2313-
break;
2314-
default:
2315-
UNREACHABLE();
2316-
}
2317-
}
2318-
2319-
2320-
FreeSpace* FreeList::FindNodeIn(FreeListCategoryType category, int* node_size) {
2321-
FreeSpace* node = GetFreeListCategory(category)->PickNodeFromList(node_size);
2322-
if (node != nullptr) {
2323-
UpdateFragmentationStats(category, node->address(), -(*node_size));
2324-
DCHECK(IsVeryLong() || available() == SumFreeLists());
2325-
}
2326-
return node;
2327-
}
2328-
2329-
23302264
FreeSpace* FreeList::FindNodeFor(int size_in_bytes, int* node_size) {
23312265
FreeSpace* node = NULL;
23322266
Page* page = NULL;
23332267

23342268
if (size_in_bytes <= kSmallAllocationMax) {
2335-
node = FindNodeIn(kSmall, node_size);
2336-
if (node != nullptr) {
2337-
DCHECK(size_in_bytes <= node->size());
2269+
node = small_list_.PickNodeFromList(node_size);
2270+
if (node != NULL) {
2271+
DCHECK(size_in_bytes <= *node_size);
2272+
page = Page::FromAddress(node->address());
2273+
page->add_available_in_small_free_list(-(*node_size));
2274+
DCHECK(IsVeryLong() || available() == SumFreeLists());
23382275
return node;
23392276
}
23402277
}
23412278

23422279
if (size_in_bytes <= kMediumAllocationMax) {
2343-
node = FindNodeIn(kMedium, node_size);
2344-
if (node != nullptr) {
2345-
DCHECK(size_in_bytes <= node->size());
2280+
node = medium_list_.PickNodeFromList(node_size);
2281+
if (node != NULL) {
2282+
DCHECK(size_in_bytes <= *node_size);
2283+
page = Page::FromAddress(node->address());
2284+
page->add_available_in_medium_free_list(-(*node_size));
2285+
DCHECK(IsVeryLong() || available() == SumFreeLists());
23462286
return node;
23472287
}
23482288
}
23492289

23502290
if (size_in_bytes <= kLargeAllocationMax) {
2351-
node = FindNodeIn(kLarge, node_size);
2352-
if (node != nullptr) {
2353-
DCHECK(size_in_bytes <= node->size());
2291+
node = large_list_.PickNodeFromList(node_size);
2292+
if (node != NULL) {
2293+
DCHECK(size_in_bytes <= *node_size);
2294+
page = Page::FromAddress(node->address());
2295+
page->add_available_in_large_free_list(-(*node_size));
2296+
DCHECK(IsVeryLong() || available() == SumFreeLists());
23542297
return node;
23552298
}
23562299
}

src/heap/spaces.h

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,8 +1682,6 @@ class FreeList {
16821682
PagedSpace* owner() { return owner_; }
16831683

16841684
private:
1685-
enum FreeListCategoryType { kSmall, kMedium, kLarge, kHuge };
1686-
16871685
// The size range of blocks, in bytes.
16881686
static const int kMinBlockSize = 3 * kPointerSize;
16891687
static const int kMaxBlockSize = Page::kMaxRegularHeapObjectSize;
@@ -1697,27 +1695,6 @@ class FreeList {
16971695
static const int kLargeAllocationMax = kMediumListMax;
16981696

16991697
FreeSpace* FindNodeFor(int size_in_bytes, int* node_size);
1700-
FreeSpace* FindNodeIn(FreeListCategoryType category, int* node_size);
1701-
1702-
FreeListCategory* GetFreeListCategory(FreeListCategoryType category) {
1703-
switch (category) {
1704-
case kSmall:
1705-
return &small_list_;
1706-
case kMedium:
1707-
return &medium_list_;
1708-
case kLarge:
1709-
return &large_list_;
1710-
case kHuge:
1711-
return &huge_list_;
1712-
default:
1713-
UNREACHABLE();
1714-
}
1715-
UNREACHABLE();
1716-
return nullptr;
1717-
}
1718-
1719-
void UpdateFragmentationStats(FreeListCategoryType category, Address address,
1720-
int size);
17211698

17221699
PagedSpace* owner_;
17231700
Heap* heap_;
@@ -1726,8 +1703,6 @@ class FreeList {
17261703
FreeListCategory large_list_;
17271704
FreeListCategory huge_list_;
17281705

1729-
friend class PagedSpace;
1730-
17311706
DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList);
17321707
};
17331708

@@ -2010,22 +1985,6 @@ class PagedSpace : public Space {
20101985

20111986
virtual bool is_local() { return false; }
20121987

2013-
// Divide {this} free lists up among {other_free_lists} up to some certain
2014-
// {limit} of bytes. Note that this operation eventually needs to iterate
2015-
// over nodes one-by-one, making it a potentially slow operation.
2016-
void DivideFreeLists(FreeList** other_free_lists, int num, intptr_t limit);
2017-
2018-
// Adds memory starting at {start} of {size_in_bytes} to the space.
2019-
void AddMemory(Address start, int size_in_bytes) {
2020-
IncreaseCapacity(size_in_bytes);
2021-
Free(start, size_in_bytes);
2022-
}
2023-
2024-
// Tries to remove some memory from {this} free lists. We try to remove
2025-
// as much memory as possible, i.e., we check the free lists from huge
2026-
// to small.
2027-
FreeSpace* TryRemoveMemory();
2028-
20291988
protected:
20301989
// PagedSpaces that should be included in snapshots have different, i.e.,
20311990
// smaller, initial pages.
@@ -2773,6 +2732,12 @@ class CompactionSpace : public PagedSpace {
27732732
CompactionSpace(Heap* heap, AllocationSpace id, Executability executable)
27742733
: PagedSpace(heap, id, executable) {}
27752734

2735+
// Adds external memory starting at {start} of {size_in_bytes} to the space.
2736+
void AddExternalMemory(Address start, int size_in_bytes) {
2737+
IncreaseCapacity(size_in_bytes);
2738+
Free(start, size_in_bytes);
2739+
}
2740+
27762741
virtual bool is_local() { return true; }
27772742

27782743
protected:

test/cctest/test-spaces.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ TEST(CompactionSpaceUsingExternalMemory) {
507507
CHECK_EQ(compaction_space->CountTotalPages(), 0);
508508
CHECK_EQ(compaction_space->Capacity(), 0);
509509
// Make the rest of memory available for compaction.
510-
compaction_space->AddMemory(HeapObject::cast(chunk)->address(),
511-
static_cast<int>(rest));
510+
compaction_space->AddExternalMemory(HeapObject::cast(chunk)->address(),
511+
static_cast<int>(rest));
512512
CHECK_EQ(compaction_space->CountTotalPages(), 0);
513513
CHECK_EQ(compaction_space->Capacity(), rest);
514514
while (num_rest_objects-- > 0) {

0 commit comments

Comments
 (0)