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

Kernel: Remove PhysicalRegion::finalize_capacity()

There's no reason to delay calculating the capacity (total page count)
of each PhysicalRegion. Just do it in the constructor.
This commit is contained in:
Andreas Kling 2021-07-13 18:46:09 +02:00
parent 5171249540
commit 959ceb4424
3 changed files with 5 additions and 19 deletions

View file

@ -282,10 +282,10 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map()
.release_nonnull()); .release_nonnull());
for (auto& region : m_super_physical_regions) for (auto& region : m_super_physical_regions)
m_system_memory_info.super_physical_pages += region.finalize_capacity(); m_system_memory_info.super_physical_pages += region.size();
for (auto& region : m_user_physical_regions) for (auto& region : m_user_physical_regions)
m_system_memory_info.user_physical_pages += region.finalize_capacity(); m_system_memory_info.user_physical_pages += region.size();
register_reserved_ranges(); register_reserved_ranges();
for (auto& range : m_reserved_memory_ranges) { for (auto& range : m_reserved_memory_ranges) {

View file

@ -34,6 +34,7 @@ PhysicalRegion::PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper)
: m_lower(lower) : m_lower(lower)
, m_upper(upper) , m_upper(upper)
{ {
m_pages = (m_upper.get() - m_lower.get()) / PAGE_SIZE;
} }
void PhysicalRegion::initialize_zones() void PhysicalRegion::initialize_zones()
@ -54,13 +55,6 @@ void PhysicalRegion::initialize_zones()
make_zones(256); make_zones(256);
} }
unsigned PhysicalRegion::finalize_capacity()
{
VERIFY(!m_pages);
m_pages = (m_upper.get() - m_lower.get()) / PAGE_SIZE;
return size();
}
OwnPtr<PhysicalRegion> PhysicalRegion::try_take_pages_from_beginning(unsigned page_count) OwnPtr<PhysicalRegion> PhysicalRegion::try_take_pages_from_beginning(unsigned page_count)
{ {
VERIFY(page_count > 0); VERIFY(page_count > 0);
@ -68,16 +62,9 @@ OwnPtr<PhysicalRegion> PhysicalRegion::try_take_pages_from_beginning(unsigned pa
auto taken_lower = m_lower; auto taken_lower = m_lower;
auto taken_upper = taken_lower.offset((PhysicalPtr)page_count * PAGE_SIZE); auto taken_upper = taken_lower.offset((PhysicalPtr)page_count * PAGE_SIZE);
m_lower = m_lower.offset((PhysicalPtr)page_count * PAGE_SIZE); m_lower = m_lower.offset((PhysicalPtr)page_count * PAGE_SIZE);
m_pages = (m_upper.get() - m_lower.get()) / PAGE_SIZE;
// TODO: find a more elegant way to re-init the existing region return try_create(taken_lower, taken_upper);
m_pages = 0;
finalize_capacity();
auto taken_region = try_create(taken_lower, taken_upper);
if (!taken_region)
return {};
taken_region->finalize_capacity();
return taken_region;
} }
NonnullRefPtrVector<PhysicalPage> PhysicalRegion::take_contiguous_free_pages(size_t count) NonnullRefPtrVector<PhysicalPage> PhysicalRegion::take_contiguous_free_pages(size_t count)

View file

@ -25,7 +25,6 @@ public:
~PhysicalRegion(); ~PhysicalRegion();
unsigned finalize_capacity();
void initialize_zones(); void initialize_zones();
PhysicalAddress lower() const { return m_lower; } PhysicalAddress lower() const { return m_lower; }