writing morecore

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
hanumant
Posts: 21
Joined: Mon Jul 23, 2007 10:16 pm

writing morecore

Post by hanumant »

Hi i am working on my memory manager. I want to confirm that what I have understood is correct. So here it goes (only for kernel heap mapped to E0000000)

physical allocator

void * allocate() /*decrement stack pointer and return physical page address
void deallocate()

/*this is where i need more info. What exactly are the responsibilities of morecore.How does it work??*/

/*For now I am assuming this
1) in teh kernel page directory, find currently used entry for 0xE0000000 and beyond
2)Within the corresponding page table , if there is an entry free, call allocate of physical allocator, map the address and return virtual address
3)if no space available in the page table call allocate , insert new pagetable, then call allocate for another page(or as many times required by the argument) and perform mapping. Then return virtual address of first page .

Is this correct?????
void *morecore(nbytes)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Sounds about right. I'm not using a stack for allocation though so I'm not certain on the ins and outs of that process.
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post by deadmutex »

Yes, that's one way of doing it. Another way would be to simply add nbytes to an end-of-heap pointer and record the allocation into an allocation list. You would store the start address, memory length, the owner of the allocation, etc. Notice that you didn't actually commit any physical pages yet. When the newly allocated memory is accessed, a page fault may occur. By checking the error code, the fault address, and the owner you can decide to either commit a physical page into memory or terminate the process due to an illegal operation if a page fault occurs.

Doing it this way will generally be slower than the way you do it for large allocations. However, since this way will wait until the last moment to commit pages, it will save lots of memory when you do huge allocations but only use a couple bytes.
Post Reply