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.
If I wanted to use the whole 4GB of address space. I would need to map 4MB of memory for the page directory/tables.
4kb/page * 1024 pages = 4096kb = 4MB of address space to map.
Now in reality, I only want to use one page directory and one table as temporary to setup paging. So I would only need to allocate 8092 bytes (8KB), 4096 bytes for size of page directory and 4096 bytes for size of page table.
4kb/page * 1 pages = 4096 bytes = 4kb for page directory
4096 bytes (4kb) for 1 page table.
a neat trick i leaned about setting up paging is if you map an entry in the page directory to itself (pretending the page dir is a page table) it will give you access to the page directory and all mapped pages at fixed locations.
personally, i like to set the last entry of the page directory to map the page directory...so the very last page of virtual memory is the virtual address of page directory.
and mapped pages are accessible starting at: 0xffc00000. at the cost of 4 megs of virtual memory you have a world of convinience
i'm not 100% certain i got BeyondSociety's point correctly, but indeed, as Proxy said, recursive mapping of the page table leads to very convenient and yet efficient scheme.
You can naturally access PG_DIR_ENTRY(vaddr) or PG_TBL_ENTRY(vaddr) at any moment, while having a single page that map one of the tables may require an important amount of TLB flushes just for page maintainance. It would also make it harder to copy/compare entries from distinct entries ...
Btw, the term "demand paging" usually signifies "allocating frames for pages as invalid accesses are made from the user process" ...
Btw, the term "demand paging" usually signifies "allocating frames for pages as invalid accesses are made from the user process" ...
Im was thinking along the lines of partial mapping where I only need to map enough memory for the necessary page directory and page table for setting up paging.
I guess I need to read the intel manuals again. Also a design of it on paper might help me to explain it better to you. Goes off to read his manual. ;D
srg wrote:
This trick of mapping the page directory into it's self, I still don't understand what the benefites of this are.
What are the real benefits of this idea, I just doesn't make sense to me at the moment.
srg
you save 4k, you get a very simple way of addressing the page tables, you can use way simpler page mapping algorithms, because the mapping is so simple you also save pages (since you auto-map the page tables, you don't have to spend extra page tables on mapping the page tables). On a 4-level system (amd64) the savings are of course higher.
Anyway, since I'm kind of depressed and don't write in a nice tone (sorry bout that) when I'm like that, I'm not going to post here for some days/weeks/months/something until it's passed. Cya.
Ive been toying with paging for quite a while and I have noticed something wrong with my design.
My paging design:
I allocate one page directory at 0x124000 and map the page directory onto itself and then mark all entries to not present except for one page table. I then allocate the one page table at 0x125000 and map 2MB of memory (512 entries in the page table) and set the rest to not present.
[glow=red,2,300]Update:[/glow]In my original design I was using two variables: one for the index into the page directory and one for the mapping. Thus when my code ran, it would page fault because the variable for the page directory index was at a different location than the other variable for the mapping.
So instead of mapping two seperate areas, I just used one variable for both solving my problem.