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

Kernel: Wrap around to region start if necessary in take_free_page

This commit is contained in:
Conrad Pankoff 2019-06-12 23:31:14 +10:00 committed by Andreas Kling
parent aee9317d86
commit b29a83d554

View file

@ -43,6 +43,7 @@ RetainPtr<PhysicalPage> PhysicalRegion::take_free_page(bool supervisor)
if (m_used == m_pages)
return nullptr;
// search from the last page we allocated
for (unsigned page = m_last; page < m_pages; page++) {
if (!m_bitmap.get(page)) {
m_bitmap.set(page, true);
@ -52,6 +53,16 @@ RetainPtr<PhysicalPage> PhysicalRegion::take_free_page(bool supervisor)
}
}
// wrap back around to the start in case we missed something
for (unsigned page = 0; page < m_last; page++) {
if (!m_bitmap.get(page)) {
m_bitmap.set(page, true);
m_used++;
m_last = page + 1;
return PhysicalPage::create(m_lower.offset(page * PAGE_SIZE), supervisor);
}
}
ASSERT_NOT_REACHED();
return nullptr;