Commit 031b753a authored by Darius Mercadier's avatar Darius Mercadier Committed by Commit Bot

[heap] Add length_ field to FreeListCategory

Having O(1) access to the length of the free lists on a given Page
will be useful to compute fragmentation and to implement efficient
heuristics to select evacuation candidates.

Bug: v8:9329
Change-Id: I92c7fcc38c89dcb18fef4ce7cc9ebf0b83d03dc5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1664065Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Darius Mercadier <dmercadier@google.com>
Cr-Commit-Position: refs/heads/master@{#62251}
parent a5fa211f
......@@ -2926,6 +2926,7 @@ void FreeListCategory::Reset() {
set_prev(nullptr);
set_next(nullptr);
available_ = 0;
length_ = 0;
}
FreeSpace FreeListCategory::PickNodeFromList(size_t minimum_size,
......@@ -2940,6 +2941,7 @@ FreeSpace FreeListCategory::PickNodeFromList(size_t minimum_size,
set_top(node.next());
*node_size = node.Size();
available_ -= *node_size;
length_--;
return node;
}
......@@ -2953,6 +2955,7 @@ FreeSpace FreeListCategory::SearchForNodeInList(size_t minimum_size,
if (size >= minimum_size) {
DCHECK_GE(available_, size);
available_ -= size;
length_--;
if (cur_node == top()) {
set_top(cur_node.next());
}
......@@ -2978,6 +2981,7 @@ void FreeListCategory::Free(Address start, size_t size_in_bytes,
free_space.set_next(top());
set_top(free_space);
available_ += size_in_bytes;
length_++;
if ((mode == kLinkCategory) && (prev() == nullptr) && (next() == nullptr)) {
owner()->AddCategory(this);
}
......@@ -3191,6 +3195,16 @@ void FreeList::PrintCategories(FreeListCategoryType type) {
PrintF("null\n");
}
int MemoryChunk::FreeListsLength() {
int length = 0;
for (int cat = kFirstCategory; cat <= kLastCategory; cat++) {
if (categories_[cat] != nullptr) {
length += categories_[cat]->FreeListLength();
}
}
return length;
}
size_t FreeListCategory::SumFreeList() {
size_t sum = 0;
FreeSpace cur = top();
......@@ -3205,17 +3219,6 @@ size_t FreeListCategory::SumFreeList() {
return sum;
}
int FreeListCategory::FreeListLength() {
int length = 0;
FreeSpace cur = top();
while (!cur.is_null()) {
length++;
cur = cur.next();
if (length == kVeryLongFreeList) return length;
}
return length;
}
#ifdef DEBUG
bool FreeList::IsVeryLong() {
int len = 0;
......
......@@ -151,12 +151,14 @@ class FreeListCategory {
page_(page),
type_(kInvalidCategory),
available_(0),
length_(0),
prev_(nullptr),
next_(nullptr) {}
void Initialize(FreeListCategoryType type) {
type_ = type;
available_ = 0;
length_ = 0;
prev_ = nullptr;
next_ = nullptr;
}
......@@ -189,7 +191,7 @@ class FreeListCategory {
void set_free_list(FreeList* free_list) { free_list_ = free_list; }
size_t SumFreeList();
int FreeListLength();
int FreeListLength() { return length_; }
private:
// For debug builds we accurately compute free lists lengths up until
......@@ -216,6 +218,9 @@ class FreeListCategory {
// category.
size_t available_;
// |length_|: Total blocks in this free list category.
int length_;
// |top_|: Points to the top FreeSpace in the free list category.
FreeSpace top_;
......@@ -562,6 +567,8 @@ class MemoryChunk {
Address area_end() { return area_end_; }
size_t area_size() { return static_cast<size_t>(area_end() - area_start()); }
int FreeListsLength();
// Approximate amount of physical memory committed for this chunk.
V8_EXPORT_PRIVATE size_t CommittedPhysicalMemory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment