1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibJS: Implement lazy freelist allocation for cells

HeapBlock now implements the same lazy freelist as LibC malloc() does,
where new blocks start out in a "bump allocator" mode that gets used
until we've bump-allocated all the way to the end of the block.

Then we fall back to the old freelist style as before.

This means we don't have to pre-initialize the freelist on HeapBlock
construction. This defers page faults and reduces memory usage for
blocks where all cells don't get used. :^)
This commit is contained in:
Andreas Kling 2021-05-17 19:01:08 +02:00
parent a15c7b7944
commit c2d9cd8d53
2 changed files with 8 additions and 11 deletions

View file

@ -41,15 +41,6 @@ HeapBlock::HeapBlock(Heap& heap, size_t cell_size)
, m_cell_size(cell_size)
{
VERIFY(cell_size >= sizeof(FreelistEntry));
FreelistEntry* next = nullptr;
for (ssize_t i = cell_count() - 1; i >= 0; i--) {
auto* freelist_entry = init_freelist_entry(i);
freelist_entry->set_live(false);
freelist_entry->next = next;
next = freelist_entry;
}
m_freelist = next;
}
void HeapBlock::deallocate(Cell* cell)