Two-Level Page Tables(cont?d) Two-Level Page Tables Project 5: Virtual Memory

 www.phwiki.com

 

The Above Picture is Related Image of Another Journal

 

Two-Level Page Tables(cont?d) Two-Level Page Tables Project 5: Virtual Memory

California College San Diego, US has reference to this Academic Journal, Project 5: Virtual Memory Two-level page tables Page fault handler Physical page frame management?page allocation, page replacement, swap in in addition to swap out Two-Level Page Tables Directory . . . pte . . . . . . . . . pte Page tables pde A page is 4KB The size of one directory or one page table is 4KB, i.e. one page. A directory is like ?the page table in consideration of the page tables?. Two-Level Page Tables(cont?d) P PCD Each entry is an integer(4B) An entry has two fields: base addr of the physical page in addition to a set of protection bits A directory entry has similar structure base_addr Page table entry 6 12 32 US A 1 2 3 4 5 0 D RW PWT

 Cox, Jeff California College San Diego www.phwiki.com

 

Related University That Contributed for this Journal are Acknowledged in the above Image

 

Two-Level Page Tables (cont?d) First level: page directory, contains pointers so that actual page tables. The size is 4KB, each entry takes 4 bytes, so a page directory points so that 1024 page tables. Second level: page tables. Each of the 1024 entries points so that a page. A directory or page table is just a physical page.(So their addresses must be page-aligned) Protection bits Present bit(P): Set if the physical page is in memory Read/Write bit(RW): Set if this page can be read/written User/Supervisor bit(US): Set if this page can be accessed in user mode. Otherwise the page can only be accessed in supervisor mode How are page tables used? Each process has its own page directory in addition to a set of page tables. The address of page directory is in CR3(page directory register) when the process is running. CR3 is loaded alongside pcb->root_page_table at context switch done in given code

How are page tables used?(cont?d) MMU uses CR3 in addition to the first 10 bits of the virtual addr so that index into the page directory in addition to find the physical address of the page table we need. Then it uses the next 10 bits of the virtual addr so that index into the page table, find the physical address of the actual page. The lowest 12 bits are used as the offset in the page. BIOS data Kernel code/data free page frames Video memory 0x1000 0xB8000 MEM_START next_free_page MAX_PHY_MEM (0x100000) page0 page1 page2 pageN Physical Memory Layout . . . Virtual Memory (Process) Layout Kernel code/data, Kernel stacks, etc 0x0 PROCESS_LOCATION MAX_PHY_MEM (0x1000000) Process code/data Process user stack (one page, pinned in mem) MAX_VIRTUAL_MEM (0xFFFFFFFF) Kernel address space User address space

Effects of Fire Suppression on Chaparral in Southern California Look Familiar? Chaparral Biome Chaparral Plants found in California Chaparral Adaptations Fire Community Fire Community Fire Community After the Fire Baja California vs. SoCal Paradise, Cedar, in addition to Otay Fires Factors Influencing Fire Fire Suppression Impacts of Shrubland Wildfires Fire Issues References

pageN page2 BIOS data Kernel code/data free page frames Video mem page0 page1 . . . Kernel address Space only accessible in supervisor mode(except Video mem) code/data accessible in user mode user stack (one page, pinned in mem) Virtual-Physical Mapping Virtual memory Physical memory Virtual address Mapping Kernel addresses are mapped so that exactly the same physical addresses All threads share the same kernel address space Each process has its own address space. It must also map the kernel address space so that the same physical address space Why? Virtual address Mapping(cont?d) So what do we need so that do? Setup kernel page tables that are shared by all the threads. (In init_memory()) Setup process page tables when creating the process (In setup_page_table())

Kernel page tables in addition to Process page tables Kernel page dir Process page dir page tab in consideration of code/data page tab in consideration of user stack page tab in consideration of kernel Stack page First level Second level . . . Kernel code/data Some clarifications: It is OK so that setup only one page table in consideration of each of the following: kernel, process? data/code in addition to process? user-stack. The page directories in addition to page tables are themselves pages in addition to must be allocated using page_alloc() We need only one page in consideration of user-stack Setup Kernel Page Table Allocate in addition to pin two physical pages: one in consideration of kernel page directory in addition to the other in consideration of kernel page table Do we need so that allocate pages in consideration of kernel code/data? Fill in the kernel page table. What value should be filled in the base_addr field in addition to the protection bits?

Setup Kernel Page Table(cont?d) Set US bit in consideration of video memory area (SCREEN_ADDR in common.h) Why? one page is enough Don?t forget so that map kernel page table into kernel page directory Set up a Process?s Page Tables If it?s a thread, just store the address of the kernel page directory into the pcb For processes: Allocate in addition to pin four physical pages in consideration of each of the following: Page directory, page table in consideration of code/data, page table in consideration of stack, in addition to stack page Set up a Process?s Page Tables(cont?d) Map the page tables into the page directory Fill in the page table in consideration of code/data Which bits should be set? Fill in the page table in consideration of user stack What values should be filled in here? At last, don?t forget so that store the physical address of the page directory into pcb->root_page_table.

Paging Mechanism After init_memory(), the kernel enables paging mode by setting CR0[PG] so that one. Done in kernel.c In dispatch(), the kernel load CR3 register alongside current_running->root_page_table Done in scheduler.c Paging Mechanism(Cont?d) When the physical page of a virtual address is not present in memory(the P bit is not set), the MMU hardware will trigger a page fault interrupt(int 14). The exception handler saves the faulting virtual address in current_running-> fault_addr in addition to then calls page_fault_handler() done in interrupt.c Page Fault Handler That?s what you are so that implement Only code/data pages will incur page fault all other pages(page directory, page tables, stack page) are pinned in memory So assume the page table is always there in addition to go directly so that find the corresponding entry in consideration of the faulting virtual address.

Page Fault Handler(Cont?d) Allocate a physical page (Possibly swapping out another page if no free page available) Fill in the page_map structure (coming soon in the following slides) Swap in the page from disk in addition to map the virtual page so that the physical page Physical Page Management? The page_map structure Defined in memory.c An array that maintains the management information of each physical page. All physical pages are indexed by a page no. Fields in each page_map structure The pcb that owns the page Page_aligned virtual address of the page The page table entry that points so that this page Pinned or not Page Allocation Implement page_alloc() in memory.c A simple page allocation algorithm If (there is a free page) allocate it Else swap out a page in addition to allocate it

Page Allocation(Cont?d) How do we know whether there is a free page in addition to where it is? A pointer is necessary (next_free_page) If no free pages, which page so that swap out? Completely at your discretion, but be careful not so that swap out a pinned page Swap in in addition to Swap out From where in addition to so that where? The process?s image on the floppy disk. Location in addition to size are stored in pcb->swap_loc in addition to pcb->swap_size The floppy_* utilities will be useful If the dirty bit (D bit) of the page table entry is clear, do we need so that write the page back? Swap in in addition to Swap out(Cont?d) Don?t read or write too much The images on disk are sector-aligned , but not page-aligned. You should only swap in the data belonging so that this process. And be careful not so that override other process?s image when swapping out. Don?t forget so that modify the protection bits of the corresponding page table entry after swapping in or swapping out

Swap in in addition to Swap out (Cont?d) Invalidate TLB entry when swapping out a page. done in memory.c So there is no assembly in consideration of you so that do Synchronization Issue The page map array is accessed in addition to modified by multiple processes during setup_page_table() in addition to page_fault_handler(). floppy_* operations may call yield() So what should we do? Some clarifications: Only the process?s code/data pages could be swapped in or out. The following pages are allocated in consideration of once in addition to pinned in memory in consideration of ever: Page directories, page tables, user stack pages It is OK not so that reclaim the pages when a process exits

Extra Credit (Cont?d) Asynchronous I/O Find out where the kernel does busy waiting You may need so that modify some other files, such as floppy.c Please indicate how you achieve it in your README

Cox, Jeff Host

Cox, Jeff is from United States and they belong to Host and work for Ben and Matt in the Morning – KNIX-FM in the AZ state United States got related to this Particular Article.

Journal Ratings by California College San Diego

This Particular Journal got reviewed and rated by Page Allocation(Cont?d) How do we know whether there is a free page in addition to where it is? A pointer is necessary (next_free_page) If no free pages, which page so that swap out? Completely at your discretion, but be careful not so that swap out a pinned page Swap in in addition to Swap out From where in addition to so that where? The process?s image on the floppy disk. Location in addition to size are stored in pcb->swap_loc in addition to pcb->swap_size The floppy_* utilities will be useful If the dirty bit (D bit) of the page table entry is clear, do we need so that write the page back? Swap in in addition to Swap out(Cont?d) Don?t read or write too much The images on disk are sector-aligned , but not page-aligned. You should only swap in the data belonging so that this process. And be careful not so that override other process?s image when swapping out. Don?t forget so that modify the protection bits of the corresponding page table entry after swapping in or swapping out and short form of this particular Institution is US and gave this Journal an Excellent Rating.