summaryrefslogtreecommitdiff
path: root/kernel/arch
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-13 20:33:56 +0200
committerAnton Kling <anton@kling.gg>2024-04-13 20:33:56 +0200
commit008b84bf5308d2f180905130653a656bfedccf8c (patch)
tree93b138ecf6207f31818362c5539474ff6fcf889a /kernel/arch
parent6df4b041905762d7058d91b86d9a44b825c5589c (diff)
Kernel/MMU: Optimize search for free frames.
This can significantly cut down on the search space for unallocated frames. But it has not been benchmarked so I am unsure if it makes a big difference.
Diffstat (limited to 'kernel/arch')
-rw-r--r--kernel/arch/i386/mmu.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/arch/i386/mmu.c b/kernel/arch/i386/mmu.c
index 2c05fb6..b9501ff 100644
--- a/kernel/arch/i386/mmu.c
+++ b/kernel/arch/i386/mmu.c
@@ -117,8 +117,9 @@ void mmu_free_pages(void *a, u32 n) {
}
}
+u32 start_frame_search = 1;
u32 first_free_frame(void) {
- u32 i = 1;
+ u32 i = start_frame_search;
for (; i < INDEX_FROM_BIT(num_array_frames * 32); i++) {
if (tmp_small_frames[i] == 0xFFFFFFFF) {
continue;
@@ -126,6 +127,7 @@ u32 first_free_frame(void) {
for (u32 c = 0; c < 32; c++) {
if (!(tmp_small_frames[i] & ((u32)1 << c))) {
+ start_frame_search = i;
return i * 32 + c;
}
}
@@ -142,6 +144,7 @@ void write_to_frame(u32 frame_address, u8 on) {
((u32)0x1 << OFFSET_FROM_BIT(frame));
} else {
num_allocated_frames--;
+ start_frame_search = min(start_frame_search, INDEX_FROM_BIT(frame));
tmp_small_frames[INDEX_FROM_BIT(frame)] &=
~((u32)0x1 << OFFSET_FROM_BIT(frame));
}