CS 162 Fall 2004 Discussion 11/09/04 ==================================== TA: Yitao Duan • Processor uses TLB. How to install, update it? Look at Processor class. • A TLB miss will trap into the OS. How would you handle it? Determine if there is a page fault, if there is, bring in the page; if not, update TLB with entry from inverted page table. Status bits are transfered to other data structures when a TLB miss or a conext switch occur. TLB entries are updated whenever a page is kicked out from physical memory. • What is a core map? When and how would you use it? Inverted page table? Per process page table? IPT for address translation. per process page table for demand paging and swap. • How can you tell if a page is in memory or on disk? How can you tell where it is, in swap or in executable? And where in the file? Take advantage of the statues bits in the page table entry. Can also use the ppn field. • When allocating a page, what would you do if the free page list is empty? In proj2, deny request. proj3? need to find a page to kick out. • What if a process is trying to load a page to page ppn but other process decides to kick out that page? You pin the page. when else you need to pin a page? when you give a page to a process, you make sure it gets it, Also when you transfer data to/from virtual memory using read/writeVM. • What if all pages are pinned when you try to allocate a page? Sleep until some one unpins a page. • Lazy loading This part is similar to part II in that pages are loaded into memory on demand. The differences are (1) pages are from executable and (2) handling of stack pages. You need to have a way to indicate where the page should come from, swap or executable, in your page table. You also need to tell if a page being loaded is a stack page. See next. • Security consideration: The argument page and the stack pages are special in that the first time they are accessed (being written in load, or stack grows), they must be 0 initilized before handed to user process so it won't leak any information from other process. • Synchronization: Whenever you access shared varables ... • Nth Chance Algorithm Nth chance algorithm: don’t throw page out until hand has swept by n times OS keeps counter per page – # of sweeps On page fault, OS checks use bit: 1 => clear use and also clear counter, go on 0 => increment counter, if < N, go on else replace page How do we pick N? Why pick large N? Better approx to LRU. Why pick small N? More efficient; otherwise might have to look a long way to find free page. Dirty pages have to be written back to disk when replaced. Takes extra overhead to replace a dirty page, so give dirty pages an extra chance before replacing? Common approach: • Clean pages – use N = 1 • Dirty pages – use N = 2 (and write-back to disk when N=1)