Paging: Difference between revisions

Page Directory
[unchecked revision][unchecked revision]
(Slight Correction)
(Page Directory)
Line 6:
 
==MMU==
Paging is achieved through the use of the [[MMU]]. The MMU is a unit that wonderfully transforms virtual addresses into physical addresses based on the current pagingpage table.This section focuses on the x86 MMU.
 
===RelaxedPage Technical OverviewDirectory===
The topmost paging structure is the page directory. It is essentially an array of page directory entries that take the following form.
Think of your RAM. It is probably several hundred megabytes of continuous non-volatile memory. Now, imagine that it is actually 4 gigabytes. This is what the MMU is paid to do with a little help from the kernel.
 
'''Note: With 5mb pages, bits 21 through 12 are Reserved!'''
In a 32bit Intel x86 CPU, there are 2 types of tables. There are the:
i* Page Directory
* Page Tables
 
[[Image:Page dir.png|frame|A Page Table Entry]]
Knowing this, there are some simple rules, if you will:
* There is only one page directory in use at any one time.
* Each structure consumes 4kb of space.
* Each entry in each structure is 4bytes in size.
 
The page table address field represents the physical address of the page table that managers the four megabytes at that point. Please note that it is very important that this address be 4kb aligned. This is needed, due to the fact that the last bits of the dword are overwritten by access bits and such.
 
The next valid flag, S, or 'Page Size', stores the page size for that specific entry. If the bit is set, then pages are 4mb in size. Otherwise, they are 4kb.
If you will recall, we know that the MMU is made to map x number of megabytes to 4 gigabytes. Considering this, we can now figure out how physical memory is mapped.
 
A, or 'Accessed' is used to discover whether a page has been read or written to. If it has, then the bit is set, otherwise, it is not. Note that, this bit will not be cleared by the CPU, so that burden falls on the OS. (ie. if it needs this bit at all.)
*page directory size = 4096 bytes
*page entry = 4 bytes
*number of directory entries = 4096/4 = 1024
*number of table entries = directory entries = 1024
*mapped RAM per directory entry (aka. a table) = 4gb/1024 = 4mb
*mapped RAM per table entry (aka. a page) = 4mb/1024 = 4kb.
 
D, is the 'Cache Disable' bit. If set, the page will not be cached. Otherwise, it will be.
There you have it. Each 'page' is then 4kb.
 
W, the controls 'Write-Through' abilities of the page. If the bit is set, write-through caching is enabled. If not, then write-back is enabled instead.
 
U, the user\supervisor bit, controls access to the page based on privilege level. If the bit is set, then the page may be accessed by all; if the bit is not set, however, only the supervisor can access it.
The structure of the above in computer speak is quite simple. Each entry is the address of it's child. If it's a directory entry, the entry consists of the table's address. Moreover, if it's a table's entry we're talking about, then it's the the address of the mapped physical memory.
 
R, the read and write permissions flag, either makes the page only readable, that is, when it is not set, or makes the page both readable and writable, that is, being set.
A short note, however, just to ruin your simplicity. Each entry described above also contains several flags. As this is a relaxed overview, I'll only list the three major ones here:
*Bits 31-12: 4kb aligned address of entry
*Bit 2: User\Supervisor
*Bit 1: Read\Write
*Bit 0: Presence Flag - While set, the MMU will assume that this page is currently in memory.
 
P, or 'Presence', determines if the page is actually in physical memory at the moment. (eg. if a page only exists on the hard drive, it is not in physical memory.) If a page is called, but not present, a page fault will occur, and the OS should handle it. (See below.)
Have you made the connection? Each page is 4kb, and each entry's address must be 4kb aligned! It's just clicking, isn't it?
 
===Page Table===
Todo
 
====Example====
Anonymous user