Fractal mapping

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
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Fractal mapping

Post by itisiuk »

now that i have paging working im trying to fix my virtual mem manager, and i have found that my problem is that im not
keeping track of the physical addresses for the page dir and page tables.
ive been reading that using fractal mapping can fix this problem. i just wanted to check that i had the write idea of how it works before i implement it.

when allocating a page dir, map the 1024 entry to point to the physical address of the page dir.

when allocating a page table map the 1024 entry to point to the physical address of the page table.

or have i miss understood this completely?
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

Re: Fractal mapping

Post by Adek336 »

Having the 1024th page directory entry setup with the physical address of the PGD is a good idea, then you can declare
struct PGD *pgd = (struct PGD*) 0xFFFFF000
and a PDE would be pgd.

Now setting the 1024th page table entry with the physical address of the page table would make you have the last 4kb of a 4mb space to be the page table. You may not allocate a continous space of 4 mb (or larger) linear memory - that is a drawback so I do not recommend you setting the last PTE with the PGT's physical address.

A solution I found is to reserve 4kb of linear space for being remapped to any PGT I need to access.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Fractal mapping

Post by itisiuk »

ok,
well i defanaitly wont be mapping each page table into itself, didnt see that problem. #-o
A solution I found is to reserve 4kb of linear space for being remapped to any PGT I need to access.
so by this do you mean create a page table with its pointers to the physical locations of the other page tables.

if so do i have todo this for each virtual address space i.e each processes page dir?
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

Re: Fractal mapping

Post by Adek336 »

The address spaces in which you would have a PDE setup to the PGD's physical address would be the spaces where kernelland is able to manage physical memory.

If you have a microkernel, where the memory manager is one of the services, this is what you want; only one process has to take care of the memory.

In a monolithic design you'd like to have access to the PGD within all address spaces as you would have kernel code (including physical memory management) invoked by interrupts/system calls in the address space in which the interrupt/system call occurred.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Fractal mapping

Post by itisiuk »

im compeletley confused now.
i thought i was just starting to get the hang of this but its obviousley above me at the min, unfortuantley this is the bit i need to get my new kernel working :( .
would u be able todo a little diagram if u have the time i usually find that that helps me figure thing out.

thanks
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

Re: Fractal mapping

Post by Adek336 »

Sample diagram:
diagram.png
At the top, it shows a microkernel which delegates memory management to a module and memory layouts for processes a,b,c all which have differend address spaces.
-process A is the memory management module,
-process B is another kernel module,
-process C is a user program.

The microkernel is region 2 and all three spaces have it mapped it; it provides context switching and IPC and does not provide physical memory management (or provides some management which is used solely to start the memory module).
The memory region 3 is the address space's process code and data and the memory region 1 is specific to the memory management module, it is the PGD to which only this one module needs access to. In the figure, note that it uses 0xFFFF E000 - 0xFFFF EFFF instead of 0xFFFF F000 - 0xFFFF FFFF : it's because the example microkernel doesn't map the last page and catches accesses to it as null pointer dereferences.

The example monolithic kernel here shown has user processes A and B. Region 2 is the monolithic kernel including memory management, region 1 is the PGD and region 3 is the process code and data.

Wow, that's a lot more words I though it would require in the first place :D Hope it clears things up, though. Note that a microkernel with memory management inside the kernel as opposed to having the memory management in a seperate module is also a design you could go for.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Fractal mapping

Post by suthers »

Nice drawing :wink:
Jule
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Fractal mapping

Post by itisiuk »

cheers that helped,
a microkernel with memory management inside the kernel is the way im trying to go, i think thats why ive been getting confused.
ive already started coding it i think its starting to fall into place. should find out by the end of the week hopfully.

again thanks :D
+ i too love that drawing, often the simplist ways are the best.
xWeasel
Posts: 1
Joined: Thu Jan 31, 2008 3:24 pm

Re: Fractal mapping

Post by xWeasel »

adek336 wrote:Having the 1024th page directory entry setup with the physical address of the PGD is a good idea, then you can declare
struct PGD *pgd = (struct PGD*) 0xFFFFF000
and a PDE would be pgd.

Now setting the 1024th page table entry with the physical address of the page table would make you have the last 4kb of a 4mb space to be the page table. You may not allocate a continous space of 4 mb (or larger) linear memory - that is a drawback so I do not recommend you setting the last PTE with the PGT's physical address.

A solution I found is to reserve 4kb of linear space for being remapped to any PGT I need to access.


You're missing something here - once you set the last PDE to the physical adress of the page directory itself, you already have all of the page tables mapped into the top 4MB of your virtual address space, because of the way the CPU will see the PDEs as PTEs. You should never have to set the last PTE in a page table to the physical address of the page table as this will indeed be completely useless, especially after you've implemented the recursive page directory properly. This concept can often be quite hard to grasp, so here's a tutorial I've written on implementing paging with the use of a recursive page directory: http://www.rohitab.com/discuss/index.ph ... opic=31139. I hope that helps.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Fractal mapping

Post by itisiuk »

Nice. =D> very nice.

i was using that b4 but my computer crashed and i haddnt book marked it, and i couldnt find it again. ive saved it now though.


:D

thanks
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Fractal mapping

Post by itisiuk »

ok, so i got the virtual paging fixed now, and ive started on the virtual address space manager.
when ive been looking into other ppls os's ive notice that all the address space information is malloced using the kernel heap, so thefore the v address space information/structures are all
stored on the kernel heap.
but the when the user does its malloc, the information is stored where the v address space structures point to., which is what it should do.

is it ok / normal to store the address space structures inside the kernel heap?
User avatar
samueldotj
Member
Member
Posts: 32
Joined: Mon Nov 13, 2006 12:24 am

Re: Fractal mapping

Post by samueldotj »

The reason for mapping one process's address space in kmem is because kernel might access it from other process's context.

Sam
Post Reply