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)
writing morecore
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.
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.