mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibJS: Split Heap into per-cell-size allocators
Instead of keeping all the HeapBlocks in one big list, we now split it into two levels: - Heap has a set of Allocators, each with a specific cell size. - Allocators have two lists of blocks, "full" and "usable". Allocating a new cell no longer has to scan the entire set of blocks, but instead just needs to find the right allocator and then pop a cell from its freelist. If all the blocks in the allocator are full, a new block will be created. Blocks are moved from the "full" to "usable" list after sweeping has determined that they are not completely empty and not completely full. There are certainly many ways we can improve on this. This patch is mostly about getting the new allocator architecture in place. :^)
This commit is contained in:
parent
d3d3b25e1c
commit
48f13b7c3f
7 changed files with 226 additions and 27 deletions
|
@ -33,6 +33,9 @@
|
|||
namespace JS {
|
||||
|
||||
class HeapBlock {
|
||||
AK_MAKE_NONCOPYABLE(HeapBlock);
|
||||
AK_MAKE_NONMOVABLE(HeapBlock);
|
||||
|
||||
public:
|
||||
static constexpr size_t block_size = 16 * KiB;
|
||||
static NonnullOwnPtr<HeapBlock> create_with_cell_size(Heap&, size_t);
|
||||
|
@ -41,6 +44,7 @@ public:
|
|||
|
||||
size_t cell_size() const { return m_cell_size; }
|
||||
size_t cell_count() const { return (block_size - sizeof(HeapBlock)) / m_cell_size; }
|
||||
bool is_full() const { return !m_freelist; }
|
||||
|
||||
ALWAYS_INLINE Cell* allocate()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue