Memory Manager (Really Stuck)

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
pskyboy

Memory Manager (Really Stuck)

Post by pskyboy »

Hey Guys

Im really stuck when it comes to writing my memory allocator im not quite sure where to start in implementing it. I understand what i need to do but am not sure how.

For instance how does virtuall memory get handled do i need to write the virtual address and physical adress somewhere. Or do i just give a program an address and then decode this into a physical page when it tries to access it. In which case this will be very slow as it will be done in software. SO my biggest question is how do i use the MMU to do thsi.

Also what interface do i need to expose from the memory manager ie a function to allocate memory etc.

Peter
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Memory Manager (Really Stuck)

Post by Pype.Clicker »

once paging has been activated by you kernel, every memory access that will be made will be a *linear address* which the paging unit of the MMU will translate into a physcial address using page tables.

So what your memory manager will have to do is
1) provide a way to allocate addresses (virtual memory) within a process.
2) provide a way to allocate physical page frames, so that you're sure you won't use the same physical page @ 2 distinct virtual addresses.
3) h00k p4g3 f4ults, look up the table manually to figure out what was wrong and performs the corresponding actions... (might be a page to be fetched from the disk, to be allocated on demand, to be copied so that the process can safely modify it, wh4t3v3r ...
Whatever5k

Re:Memory Manager (Really Stuck)

Post by Whatever5k »

Pype, you said that after enabling paging, every address is translated into a physical one.
Is that only the case for addresses within the user address space, or is it the same with the kernel?
Also, I don't exactly understand what you want to say with point 2 (the physical allocator). Why do we have a Physical Allocator? And why are we able to have one if all addresses are translated into virtual ones, is it possible?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Memory Manager (Really Stuck)

Post by Pype.Clicker »

abless wrote: Pype, you said that after enabling paging, every address is translated into a physical one.
Is that only the case for addresses within the user address space, or is it the same with the kernel?
This do happen for both user and kernel. But the kernel can c0ntr0l this process through the use of page tables.

What i suggest you is to have an entry in your page table that will map yourwhole kernel (let's say the very first one or the very last one. First one seems easier to me because if you assume the system will have at least 4Mb, you can safely switch the "paging bit" within your C kernel and have it running properly. If you opt for the last (kernel at top), then the OS loader will have to enable paging itself, or the kernel will need dynamic relocations :( )

Also, I don't exactly understand what you want to say with point 2 (the physical allocator). Why do we have a Physical Allocator?
And why are we able to have one if all addresses are translated into virtual ones, is it possible?
The logical --> physical translation result in writing the address of page frames in some Page Table Entries.
So for instance you'll say that addresses 0x801000 o 0x801fff will actually be stored in memory from [0x12000] to [0x12fff] ... But as your kernel must fill page tables with page frames numbers (here, we used page frame #12), it must have some allocation scheme that prevents it to give the same page frame to 2 virtual addresses (or your process's memory will act w31rdly ...

What i did is to have a bitmap for the whole physical memory (1bit --> 4Kb) and mark which page is used...
Whatever5k

Re:Memory Manager (Really Stuck)

Post by Whatever5k »

That clears things up a bit...
I'll use a bitmap, too. That's quite easy to realize.
But the Page Allocator doesn't allocator anything, does it? It just makes sure that nobody is using one page frame with two virtual addresses?!
pskyboy

Re:Memory Manager (Really Stuck)

Post by pskyboy »

I read somewhere about having to use a bitmap if you plan to use paging does anyone know what this is about or is this rubbish.

Peter
pskyboy

Re:Memory Manager (Really Stuck)

Post by pskyboy »

Okay this is starting to make sense

So does the whole virtual memory managment come in on the page faults.

Ie i load a program and tell it it is in 0-1Gb and then when it generates a page fault trying to access that page i write the page table for the address into the TLB.

Also how much do you reckon i should use for looking after memory 8mb seems about the maximum to me whihc will give a 32Gb address region.

Peter
Post Reply