mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
Kernel: Implement zone-based buddy allocator for physical memory
The previous allocator was very naive and kept the state of all pages in one big bitmap. When allocating, we had to scan through the bitmap until we found an unset bit. This patch introduces a new binary buddy allocator that manages the physical memory pages. Each PhysicalRegion is divided into zones (PhysicalZone) of 16MB each. Any extra pages at the end of physical RAM that don't fit into a 16MB zone are turned into 15 or fewer 1MB zones. Each zone starts out with one full-sized block, which is then recursively subdivided into halves upon allocation, until a block of the request size can be returned. There are more opportunities for improvement here: the way zone objects are allocated and stored is non-optimal. Same goes for the allocation of buddy block state bitmaps.
This commit is contained in:
parent
be83b3aff4
commit
ba87571366
9 changed files with 411 additions and 145 deletions
|
@ -13,7 +13,7 @@ namespace Kernel {
|
|||
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool may_return_to_freelist)
|
||||
{
|
||||
auto& physical_page_entry = MM.get_physical_page_entry(paddr);
|
||||
return adopt_ref(*new (&physical_page_entry.physical_page) PhysicalPage(may_return_to_freelist));
|
||||
return adopt_ref(*new (&physical_page_entry.allocated.physical_page) PhysicalPage(may_return_to_freelist));
|
||||
}
|
||||
|
||||
PhysicalPage::PhysicalPage(bool may_return_to_freelist)
|
||||
|
@ -28,9 +28,12 @@ PhysicalAddress PhysicalPage::paddr() const
|
|||
|
||||
void PhysicalPage::free_this()
|
||||
{
|
||||
auto paddr = MM.get_physical_address(*this);
|
||||
if (m_may_return_to_freelist) {
|
||||
auto paddr = MM.get_physical_address(*this);
|
||||
auto& this_as_freelist_entry = MM.get_physical_page_entry(paddr).freelist;
|
||||
this->~PhysicalPage(); // delete in place
|
||||
this_as_freelist_entry.next_index = -1;
|
||||
this_as_freelist_entry.prev_index = -1;
|
||||
MM.deallocate_physical_page(paddr);
|
||||
} else {
|
||||
this->~PhysicalPage(); // delete in place
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue