1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

Kernel: Move PhysicalPage classes out of the heap into an array

By moving the PhysicalPage classes out of the kernel heap into a static
array, one for each physical page, we can avoid the added overhead and
easily find them by indexing into an array.

This also wraps the PhysicalPage into a PhysicalPageEntry, which allows
us to re-use each slot with information where to find the next free
page.
This commit is contained in:
Tom 2021-07-07 19:50:05 -06:00 committed by Andreas Kling
parent ad5d9d648b
commit 87dc4c3d2c
11 changed files with 285 additions and 43 deletions

View file

@ -52,12 +52,14 @@ enum class UsedMemoryRangeType {
LowMemory = 0,
Kernel,
BootModule,
PhysicalPages,
};
static constexpr StringView UserMemoryRangeTypeNames[] {
"Low memory",
"Kernel",
"Boot module",
"Physical Pages"
};
struct UsedMemoryRange {
@ -195,10 +197,14 @@ public:
const Vector<UsedMemoryRange>& used_memory_ranges() { return m_used_memory_ranges; }
bool is_allowed_to_mmap_to_userspace(PhysicalAddress, const Range&) const;
PhysicalPageEntry& get_physical_page_entry(PhysicalAddress);
PhysicalAddress get_physical_address(PhysicalPage const&);
private:
MemoryManager();
~MemoryManager();
void initialize_physical_pages();
void register_reserved_ranges();
void register_vmobject(VMObject&);
@ -216,7 +222,12 @@ private:
static Region* find_region_from_vaddr(VirtualAddress);
RefPtr<PhysicalPage> find_free_user_physical_page(bool);
u8* quickmap_page(PhysicalPage&);
ALWAYS_INLINE u8* quickmap_page(PhysicalPage& page)
{
return quickmap_page(page.paddr());
}
u8* quickmap_page(PhysicalAddress const&);
void unquickmap_page();
PageDirectoryEntry* quickmap_pd(PageDirectory&, size_t pdpt_index);
@ -235,6 +246,10 @@ private:
NonnullRefPtrVector<PhysicalRegion> m_user_physical_regions;
NonnullRefPtrVector<PhysicalRegion> m_super_physical_regions;
RefPtr<PhysicalRegion> m_physical_pages_region;
PhysicalPageEntry* m_physical_page_entries { nullptr };
size_t m_physical_page_entries_free { 0 };
size_t m_physical_page_entries_count { 0 };
Region::List m_user_regions;
Region::List m_kernel_regions;