paging optimization

This commit is contained in:
2026-01-28 21:37:05 +11:00
parent 1326696724
commit 68df6c7ebb
5 changed files with 45 additions and 38 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -52,23 +52,6 @@ void PageFrameAllocator::InitBitmap(size_t bitmapSize, void* bufferAddress){
} }
} }
void PageFrameAllocator::FreePage(void* address) {
uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
usedMemory -= 4096;
}
}
void PageFrameAllocator::FreePages(void* address, uint64_t pageCount) {
for (int t = 0; t < pageCount; t++) {
FreePage((void*)((uint64_t)address + (t * 4096)));
}
}
void PageFrameAllocator::LockPage(void* address) { void PageFrameAllocator::LockPage(void* address) {
uint64_t index = (uint64_t)address / 4096; uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == true) return; // page is already locked if (PageBitmap[index] == true) return; // page is already locked
@@ -86,23 +69,6 @@ void PageFrameAllocator::LockPages(void* address, uint64_t pageCount) {
} }
} }
void PageFrameAllocator::UnreservePage(void* address) {
uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
reservedMemory -= 4096;
}
}
void PageFrameAllocator::UnreservePages(void* address, uint64_t pageCount) {
for (int t = 0; t < pageCount; t++) {
UnreservePage((void*)((uint64_t)address + (t * 4096)));
}
}
void PageFrameAllocator::ReservePage(void* address) { void PageFrameAllocator::ReservePage(void* address) {
uint64_t index = (uint64_t)address / 4096; uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == true) return; // page is already locked if (PageBitmap[index] == true) return; // page is already locked
@@ -120,17 +86,58 @@ void PageFrameAllocator::ReservePages(void* address, uint64_t pageCount) {
} }
} }
uint64_t pageBitmapIndex = 0;
void* PageFrameAllocator::RequestPage() { void* PageFrameAllocator::RequestPage() {
for (uint64_t index = 0; index < PageBitmap.Size * 8; index++) { for (; pageBitmapIndex < PageBitmap.Size * 8; pageBitmapIndex++) {
if (PageBitmap[index] == true) continue; if (PageBitmap[pageBitmapIndex] == true) continue;
LockPage((void*)(index * 4096)); LockPage((void*)(pageBitmapIndex * 4096));
return (void*)(index * 4096); return (void*)(pageBitmapIndex * 4096);
} }
return NULL; // page frame swap to file return NULL; // page frame swap to file
} }
void PageFrameAllocator::FreePage(void* address) {
uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
usedMemory -= 4096;
if (pageBitmapIndex > index) pageBitmapIndex = index;
}
}
void PageFrameAllocator::FreePages(void* address, uint64_t pageCount) {
for (int t = 0; t < pageCount; t++) {
FreePage((void*)((uint64_t)address + (t * 4096)));
}
}
void PageFrameAllocator::UnreservePage(void* address) {
uint64_t index = (uint64_t)address / 4096;
if (PageBitmap[index] == false) return; // page is already free
// free page in bitmap
if (PageBitmap.Set(index, false)) {
freeMemory += 4096;
reservedMemory -= 4096;
if (pageBitmapIndex > index) pageBitmapIndex = index;
}
}
void PageFrameAllocator::UnreservePages(void* address, uint64_t pageCount) {
for (int t = 0; t < pageCount; t++) {
UnreservePage((void*)((uint64_t)address + (t * 4096)));
}
}
uint64_t PageFrameAllocator::GetFreeRAM() { uint64_t PageFrameAllocator::GetFreeRAM() {
return freeMemory; return freeMemory;
} }