Memory allocator = done, memory management = ?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
leledumbo
Posts:2
Joined:Thu Nov 27, 2008 5:26 am
Memory allocator = done, memory management = ?

Post by leledumbo » Thu Nov 27, 2008 5:34 am

I've implemented memory allocators both physical and virtual as in tutorial 17 & 18 (with a "little" modification, of course). The question is, how do I manage them? I mean, if I have a function like:

Code: Select all

function GetMem(Size: LongWord): Pointer;
how do I connect it with AllocPage (corresponds to your vmmngr_alloc_page)? Plus, if I allocate more than one page, AFAIK they have to be contiguous. How can I ensure that?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Thu Nov 27, 2008 5:42 pm

The whole idea of splitting physical and virtual memory is that you can allocate non-contiguous physical pages and map them to contiguous virtual addresses.

As for managing memory inside a process:

You need to implement functions like 'malloc' or 'new' that will internally use the memory management functions that you have. The job of malloc and new is to keep a record of how much memory you have to access, keep a record of which memory is currently allocated to the process, and to ask the virtual memory manager for more memory if it needs.

There is no easy way to do this and there are many different algorithms for doing so.

Sorry this isn't very helpful

~Andrew
Image

leledumbo
Posts:2
Joined:Thu Nov 27, 2008 5:26 am

Post by leledumbo » Tue Dec 02, 2008 4:05 am

Some questions:
  • Should it be calling virtual or physical allocator?
  • When should I create the heap? Before or after enabling paging?
  • Any small and easy to understand existing code?

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Tue Dec 02, 2008 1:09 pm

Good questions:

malloc should use the virtual memory manager if it needs more space. the virtual memory manager should in tern use the physical memory manager when needing another page or for swapping pages to and from main memory.

It makes much more sense to create the heap after after enabling paging because that allows you to maintain a contiguous heap in virtual memory, even if the physical pages of memory used are not contiguous.

As for code, I am sorry but I haven't got this far with my kernel (too much work :( ).

Hope this helps,

~Andrew
Image

Post Reply