The agnostic explanation of Virtual Memory with Basic and Multi-level Page Tables
What is trying to solve any virtual memory implementation ? * Not enough RAM * Holes in our address space (memory fragmentation) * Programs (or any similar entity with context) writing over each other How is a modern virtual memory implementation working? * Stores sundry indirection levels for getting fast page translation.
The Hypothetical 32 bit address space for a program An Operative system or any other software artifact with a virtual memory implementation migth give each program its own 32 bits address space. Programs would access any byte within the range of 32 bits (4Gb) What if we did not have 4Gb of memory ?
How do programs share the memory space?
Memory Fragmentation (Holes in memory) A program would need All its required memory In a row Now I could not run Program 3. Even I 've got enough Space in memory
How do we keep programs secure ? * Each programs could access any 32 bit address :( * They would corrupt or crash each other (where is then security and reliability?)
What is a virtual memory implementation ? ButlerLampson once said, "all problems in Computer Science can be solved by another level of indirection"http://c2.com/cgi/wiki?ButlerLampson Virtual memory is a layer of indirection. That maps program address and map them to the physical memory.
Mapping the memory with flexibility * To try to load something beyond 1Gb will turn out in moving out some old pages to the disk memory and an updating of the map (a.k.a Page out).Then the earlier data will be load inside the new available spaces. *When we need it (this need is also know as page-fault), we bring it into memory. (a.k.a Page in).
Each program is mapped in the physical memory (without a need of contiguos memory)
Security and reliability problem is solved In spite of isolation. This approach allows to shared data among programs when It is needed.
Map == Page Table
Pages instead of Words
The trade-off
From page Virtual to Physical
The offset A virtual address is compound of 2 parts * Page table address and offset
Address Translation for system with just 256MB of RAM
Which Page ?
Just a brief question to ensure everything is clear
An example of translation with more details for 4kb pages
An example of translation with more details for 64kb pages
Multi-level Page Tables * Each Program need a Page table that will consume 4MB RAM Why 4MB ? * If we`ve got 100 programs running , we require 400MB just for page tables.
Multi-level Page Tables * Each Program need a Page table that will consume 4MB RAM Why 4MB ? * If we`ve got 100 programs running , we require 400MB just for page tables.
How can we fix this ? I think we would add other indirection level for Saving memory.
Now We can have page tables in disk or memory Multi level page table introduces a bit of hierarchy to reduce the amount of information needed at any one time.
1st Level page table is always in memory * We always need 1st level page table in memory to find the second one levels * First level page table is only a helper to find the other page tables
An example of multilevel page table translation
Not used then Not Allocated Regions which are not actually used do not require allocated memory (These will be mark in the outer page table). The multi-level scheme reduces the memory by requiring Page Tables only for those virtual memory regions actually used by a process.