An Intro to Kernel Development - MMU - Part 8
10 mins
Let's see think about how we can implement a low level page allocator..
In the previous blog we have debugged some issues related to linker script to get the location for array map.
In this part, I have implemented a low level page allocator/deallocator that is gonna keep track of the physical pages using a bitmap.
Initially, i had an idea of keeping track of the pages based on an index like
Struct {
map,
index,
bit
};
and keep incrementing the index to find the next free page, A page is set as used by setting it to 1, but this wont work if we have to free page, as we cant go back the index and find the freed page.
Second approach is to go through the map linearly and find the next free bit inside an index.
Struct {
map
}
we used bit shit operations to set/unset the bit inside an index.
Index: 0, Bit: 0
Index: 0, Bit: 1
Index: 0, Bit: 2
Index: 0, Bit: 3
Index: 0, Bit: 4
Index: 0, Bit: 5
Index: 0, Bit: 6
Index: 0, Bit: 7
Index: 1, Bit: 0
Index: 1, Bit: 1
Index: 1, Bit: 2
Index: 1, Bit: 3
Index: 1, Bit: 4
Index: 1, Bit: 5
single index could store 8 pages.
I have steamed the entire implemenation session on youtube.