CS5600 2/1/16 Lecture Notes - 7:00PM-8:00PM on a 64-bit machine, there is a 2^64 address space -> 1600 PB 2^64 / 2^12 ~ 2^52 ~ 4PB memory required for page tables There are huge gaps in the address space where the memory is not being used by the process. It is *sparse*. We need to store the mappings from virtual page address to physical page addresses in a more efficient manner. We use multi-level paging for this purpose. Suppose we have a virtual address 0x00410000 We split up this address into three parts 0x0 0410 000 Page directory # Page # Offset Page directory can have up to 16 rows And for each row in the page directory, there is a page table With the page directories, we might not be using several of the rows. Therefore we don’t allocate those page tables into memory. This reduces the amount of memory that we are using dramatically. If half of the page directory isn’t used, then we are saving half of the page tables from being allocated into memory. Example of converting virtual memory address to physical memory address: Suppose we have the virtual address 0x60410020. 0x6 0410 020 This might say “use the 6th page table.” Look for the virtual page entry in the page table with page 0410. This maps to a physical page address, say 1474. The physical address would be 0x1474020 The example from above illustrates only two levels. Now imagine that we have three levels, i.e. with a directory of page directories. 64-bit machines actually use multiple levels This can be generalized for several additional levels. This process of locating the physical address is called “walking through page entries” Doesn’t this become inefficient? Suppose from our CPU, the virtual address 0x400123 is generated To get the physical address, we need to walk through page tables. 2 memory reads for every access Translation Lookaside Buffer (TLB) - a special cache: Operating system when doing virtual address to physical address translation, stores translation to TLB cache. Next time, there is no need to walk through the page tables temporal locality - most recent accesses are likely to be accessed again spatial locality - addresses near recent accesses are likely to be accessed if you are generating a new address and its in TLB, this is a TLB hit if there’s a TLB miss, you have to walk through the page tables actual translations of address happen by the Memory Management Unit (MMU) there are two levels: software and hardware MMU uses TLB Might there be a hybrid MMU? Paging/Swapping Page in - take page originally written on disk and load it into RAM since we plan on accessing it Page out - take page from physical RAM and write it out onto disk The problem is that we have processes that are too big to fit in memory. How do we make it happen? Often we know that in the text segment, we don’t use the instructions from the whole program uniformly. Some pages are more active than others. Some pages are only touched once and never again. For those that won’t be accessed in the future, why not put them on disk? That is the purpose of page in and page out. The operating system keeps track of which pages are being accessed. It wants to find out what are the “hot” pages (accessed frequently), “warm” pages (accessed moderately often), and “cold” pages (not accessed in a long time) One thought is to dump cold pages to disk since we know no one is going to access them for a long time. When they need to be accessed, they can be loaded back into RAM This is one of the hardest problems for the operating system - to find the cold pages We want to find out the working set of the process - the hot pages that are necessary for this process to run efficiently Everyone is trying to reduce the working set size. This means even if your program is big, you only need a small number of pages in RAM for the program to run with the rest written to disk A page table entry may have the following: -Virtual Page Number -Physical Page Number -Permissions (Read, Write, eXecute) -Modified/Dirty: If a page has been modified and we want to do a page out, we want to write the contents to disk. Otherwise, the page hasn’t been modified since it had been read into RAM and there is no need to write it back to disk -Access: has this page been accessed? -Valid: if 0, this entry is invalid and shouldn’t be used. Eventually page table entries will be initialized with valid set to 1 -Swapped: If the page has been swapped out and written to disk, then this bit is 1 and instead of a physical memory address in RAM, there will probably be a number describing the block on disk that the page was written to. If the page was not swapped out and is currently in RAM, then this bit will be 0