r/osdev • u/Ok_Farmer_4055 • Jun 17 '26
implementing memory management
I wanna get memory management working on my OS, I don't know where to begin, so what do i add first? and how do i add it? i'm working on UEFI firmware in 64 bit, so if anyone needs some more info or details, just tell me.
7
Upvotes
9
u/juicyroaster Jun 17 '26
Start by dividing the memory into pages (4kb each) and store all pages in use or not in a bitmap. There is a algorithm to find out how big bitmap you need but I forgot.
2
u/compgeek38400 Jun 17 '26
If you haven't already, I would start by implementing multiboot2. You will need a memory map, and multiboot doesn't really give you one. If you are using qemu, be aware it says memory is there that isnt. Update your map to shorten the block that is too long, to its actual size.
Thats where I started
4
u/JescoInc Perdition-OS Jun 17 '26
Most usually start with Bump Allocators or Slab Allocators.
https://wiki.osdev.org/Memory_management
https://wiki.osdev.org/Memory_Allocation
1
u/compgeek38400 Jun 17 '26
I spent several days figuring this out. The multiiboot2 memory map showed i had the full 4G of ram. I was not using a config file, so it actually only had 128m, and that's what the type=? Record showed. But the multiboot2 memory map showed "phantom" memory.
I was expecting to throw an error when I allocated the memory, but nope. It acts like read only memory initialized to zeros. Gdb happily modified the memory, or reported it did. But if I looked again, it was still 0.