phil-opp / blog_os

Writing an OS in Rust
http://os.phil-opp.com
Apache License 2.0
15.85k stars 1.09k forks source link

Question about PMM and VMM #1352

Closed shinobu-uwu closed 1 month ago

shinobu-uwu commented 1 month ago

I've been digging deeper into osdev, especially in osdev's wiki and discord server, and there some names that I got a little confused with after following the blog post, so I just wanted to clarify some of them.

So, the PMM, physical memory manager, is the struct called BootInfoFrameAllocator? If a process asks for some amount of memory my microkernel would use it to allocate the memory and would return the address to the process, right? Also does it always deals with absolute addresses?

And the VMM, virtual memory manager, would be OffsetPageTable, this one was not written by us, it's from the x86_64, and i think is pretty clear to me since all it does is translating addresses and managing them, correct?

tsatke commented 1 month ago

For such a discussion you have to use very precise with terminology.

Regarding the PMM, you can use the BootInfoFrameAllocator as your first Physical Memory Manager to allocate frames, however I would highly recommend you replace it with a more efficient implementation as early in the startup process as possible.

The VMM would be something that manages your virtual memory, not just the paging (as the page tables do). It does more than just translate addresses and manages them.

As an example: my VMM is responsible for allocating VMObjects. A VMObject is (for this discussion) mapped memory. When creating such a VMObject, I can either tell the VMM to map it anywhere or at a fixed address. The VMM will obtain physical frames from the PMM and do the mapping using the page tables. My VMM also allows me to obtain memory regions that are guaranteed to be unused.

You usually have one PMM per system, and one VMM per address space.

I've drawn this and I hope it helps. Feel free to ask questions.

Untitled Diagram drawio

Note that this is just to aid understanding and in an actual kernel this is going to be a lot more complex, with a lot more components involved.

shinobu-uwu commented 1 month ago

Thanks a lot @tsatke! That was very helpful

The blog post plus you guys from the issues are helping me a lot with my first kernel, which is also my graduation thesis from college!