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.
Hi people, this question might have already been debated here, but I have briefly took a look at old threads and could not see anything about it. I am currently trying to get whole idea behind memory management and I am kinda confused in two level address translation: When we are in pmode mpu does firstly segment translation by selectors values and etc... And after that does page translation stuff. But when we are in pmode our segments are there and when we call an address from kernel its base is chosen from gdt and added to offset. Doesnt this cause trouble or confusion while using paging? In memory management 1 tutorial Tim Robinson says
(When paging is enabled)
it makes sense to use segments whose base addresses are zero, although there is no reason why this should be mandatory.
Does everybody do paging in that way? I mean do people use 0 based segments? Or any other ideas? I hope I am clear enough... Thanx...
Hey, I've been trying to figure out MM to, and was wondering if I can split up the memory sapce between the user and kernel by putting it in the paging.
Hi Madmonky I am sorry but I dont think I understand you, BTW I think I am the last person to give you any advice about mm stuff in this forum, but I am very interested in debating about mm because for now I could not exactly figure it out... Anyway...
Hi Ozguxxx, I designing MM too So I need to design paging, memory alocation(malloc, etc..) and virtual memory management.
About paging I know something, but about memory alocation and virtual memory nothing...
Can anyone explain how function malloc works?
Please...
malloc() keeps track of free blocks with a linked list. If it needs more free memory, it calls morecore(). Your job is to implement morecore().
This function keeps track of the heap. If there's a request for more memory, it increments the heap pointer, allocates physical memory and maps it to virtual...
We have two allocators, a virtual and a physical allocator. Plan is: Kernel needs memory->Virtual Memory allocator asks for memory -it should be generic because it hides underlying hardware stuff- physical or low level memory allocator is called, it checks its bitmap and finds enough memory space from physical memory and maps these into address space of kernel(only kernel for now) and returns pointers to memory allocated. Virtual memory allocator gets memory it needs, returns pointer to allocated memory to kernel. Is everything OK until now?
Another question: In memory management tutorial 2 Tim Robinson's Mobius Kernel has 256 Meg of heap memory. My problem is: Does morecore function increase the 256 Meg Window or it just increases the usage inside this 256 Meg. Or maybe I should ask like: Should morecore be able to increase virtual address space (For example makes it 257 Meg) or it justs sets the end of kernel heap inside 256 Meg? But if this is the case, then kernel cannot have memory more then 256 Meg right? Or am i confused somewhere? ;D
The way I deal with this is to have two heaps: a fixed 256MB non-paged heap, and a paged heap which can go wherever it wants in kernel memory. Each heap is completely separate and uses its own morecore() routine. morecore() for the non-paged heap is a simple one which allocates from within the 256MB non-paged region. morecore() for the paged heap is based on the virtual memory manager.
You'd then use the non-paged heap anywhere where you didn't want the VMM to get called, and the paged heap everywhere else. For example, you'd put structures for the VMM, threads and processes in the non-paged heap, as well as all memory used by drivers involved in paging to disk.
I dont think I understand nonpaged heap... I am currently trying to get basic definitions... Is there anything missing in my previous understanding of memory management?(I mean 3 posts before)
Ozguxxx: the non-paged heap is the 256MB heap you mentioned earlier. The paged heap is a separate heap whose memory is allocated by the VMM. The non-paged heap occupies up to 256MB of virtual memory in a contiguous chunk. The paged heap fit in between all the gaps in kernel memory, since every time some more heap is needed, the VMM is called. The paged heap can go beyond 256MB.
You can stick with just the non-paged heap if:
- You don't mind setting an upper limit on heap size
- You don't want to be able to swap the heap to disk, or you want to swap the heap to disk but you don't mind putting in lots of checks to make sure that whatever's doing the swapping doesn't allocate any memory while it's swapping
Unexpected: a heap is where malloc() gets it memory from.
This started to make sense to me... (BTW Tim Robinson, thanx for your patience) but I have another question, and this might be some kinda silly. I think whle multitasking is done, a new PDBR is loaded (I really dont know anything about multirasking for now I just checked for understanding in mm stuff, anyway...) so this means that mpu encounters completely different mapping of memory so does that mean that same virtual addresses mean different physical addresses for different processes? So that non of memory of different processes are corrupted but if it this is correct then shouldnt mpu also load page tables? Or do the page tables always stay in memory? Thanx...
Ozguxxx wrote:so does that mean that same virtual addresses mean different physical addresses for different processes?
Yes.
So that non of memory of different processes are corrupted but if it this is correct then shouldnt mpu also load page tables? Or do the page tables always stay in memory? Thanx...
MOV CR3 invalidates the whole TLB, which means that next time any virtual address is used, the MMU reloads that page table. Each process has its own page directory and its own page tables.
OK, about VMM, I understood its necessity but now problem is that while allocating memory, it should also keep track of which virtual addresses are allocated or shown as allocated, right? But for doing as in memory management 2 tutorial, we need a linked list that can grow but this needs dynamic memory allocation. A kind of chicken egg scenario isnt it? How does VMM keep track of virtual memory? does it also use a bitmap?
That's the point of the whole non-paged heap/paged heap thing. The non-paged heap is really simple and doesn't rely on the VMM (I think I put the morecore() routine in one of the tutorials or on this board somewhere; if not, I can re-post it). The paged heap is more flexible but it does rely on the VMM.