OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:40 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Memory questions
PostPosted: Thu Jul 07, 2022 1:14 pm 
Offline

Joined: Sun Apr 23, 2017 4:28 am
Posts: 14
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.


Top
 Profile  
 
 Post subject: Re: Memory questions
PostPosted: Thu Jul 07, 2022 1:39 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 74 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group