Memory questions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
viruss33
Posts: 14
Joined: Sun Apr 23, 2017 4:28 am
Libera.chat IRC: Viruss

Memory questions

Post by viruss33 »

So I'm working on malloc function now, I implemented PMM and VMM and I want to clarify if I understand it all correctly. So the way I see it is PMM manages physical memory, so it has some structure to manage free blocks of memory. Then we have VMM, it manages virtual adresses, so also holds a structure to check which virtual addresses are free. VMM is responsible for mapping virtual to physical memory, so when someone asks for new page, it asks PMM for new blocks of memory, then it gets next free virtual address and maps them. Then we have heap which manages bytes within pages and with the malloc function it allocates bytes per demand. At initialization time it requests some pages from VMM to work with and when it runs out of memory it asks VMM for more. So heap also has to hold some structure for determining which regions of memory are free. And malloc does not prevent the user of the api to use more memory than allocated - the user must take care to use only the allocated memory. It all seems reasonable for me, except I don't see how virtual memory solves the fragmentation problem. Lets say I allocate 10 pages, then free page 2, 4 and 6. Now we have fragmented memory. I don't have userspace in my os yet, so I'm thinking in terms of kernel memory only.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Memory questions

Post by Octocontrabass »

viruss33 wrote:I don't see how virtual memory solves the fragmentation problem.
Paging solves physical memory fragmentation, not virtual memory fragmentation. When your VMM needs to map a contiguous block of virtual memory, it can satisfy that request with any physical pages - they don't have to be in a single contiguous block.
Post Reply