Ex.1 +------------+ +------------+ 0xf0f02ffc | 0xf00f3007 | 0xff005ffc | 0xbebeebee | +------------+ +------------+ | ... | | ... | +------------+ +------------+ 0xf0f02800 | 0xff005007 | 0xff005800 | 0xf00f8000 | +------------+ +------------+ | ... | | ... | +------------+ +------------+ 0xf0f02000 | 0xffff5007 | 0xff005000 | 0xc5201000 | +------------+ +------------+ +------------+ +------------+ 0xffff1ffc | 0xd5202007 | 0xffff5ffc | 0xdeadbeef | +------------+ +------------+ | ... | | ... | +------------+ +------------+ 0xffff1800 | 0xff005007 | 0xffff5800 | 0xff005000 | +------------+ +------------+ | ... | | ... | +------------+ +------------+ 0xffff1000 | 0xf0f02007 | 0xffff5000 | 0xc5202000 | +------------+ +------------+ The content of %cr3 (the pointer to the page directory) is 0xffff1000. Output of this is: int *ptr1 = (int *) 0x0; int *ptr2 = (int *) 0x200ffc; printf("%x\n", *ptr1); printf("%x\n", *ptr2); Ex.2 - TLB / page faults Assuming 0x200000 and 0x300000 are stored on disk [context switch - tlb is flushed (x86)] 0x500 movl 0x200000, %eax # move data in 0x200000 to register %eax 0x504 incl %eax, 1 # add one to %eax 0x508 movl %eax, 0x300000 # move %eax to memory location 0x300000 0x512 push %ecx # push %ecx onto the stack How many tlb misses? How many page faults? MemOS: - Kernel virtual address Kernel is setup to use an identity mapping [0, MEMSIZE_PHYSICAL) -> [0, MEMSIZE_PHYSICAL) - Physical pages' meta data is recorded in page_info array, whose elements contains refcount, owner owner can be kernel, reserved, free, or pid - Process control block: * Your usual process registers, process state * Process page table - a pointer (?) to a page directory * Page directory's first entry points to a page table Our job mainly consists of manipulating the page tables, and page info array - Useful functions to implement for said manipulations: * find a PO_FREE physical page and assign it to a process (Ex2, 3, 4, 5) * allocate empty page dir + page table for a process (Ex2, 4) * make a copy of existing page table and assign it to a process (Ex2, 5) * implement your own helper functions as you see fit Tip: Zero the allocated page before using it!! (memset) - Some useful functions/macros: PTE_ADDR : PTE_ENTRY -> Physical address PAGENUMBER : a phyiscal address -> corresponding index into page info array PAGEADDR : PAGENUMBER^{-1} virtual_memory_lookup(pagetable, va)