Ch7d- 2 EE/CS/CPE Computer Organization Seattle Pacific University Individual Space Every process wants its own space Ideally, it would like the entire computer to itself Sharing the computer’s memory creates problems Sometimes a program will be at location 4000, sometimes at location , etc. 7.4 Use Virtual Memory to fool each process to thinking that it starts at location 0 CPU uses virtual addresses - Start the program at virtual page 0, even if it’s not physical page 0 Each process must have an individual page table to make this work Every virtual page 0 must point to a different physical page, and so on
Ch7d- 3 EE/CS/CPE Computer Organization Seattle Pacific University Example VPNValidPPN/ (index)BitDisk address sector sector 4323… sector Page Table for process A: VPNValidPPN/ (index)BitDisk address sector sector sector Page Table for process B: 7.4 Virtual page (process A) points to physical page Virtual page (process B) points to physical page The processes both can start at location , but have different data. Note: Physical page 1100 is shared.
Ch7d- 4 EE/CS/CPE Computer Organization Seattle Pacific University Protection Using Virtual Memory 7.4 We want to protect different processes from each other Can’t read or write to any other process’s memory, unless specifically allowed Providing separate page tables fixes this problem Each process can only access pages through its page table As long as the page table doesn’t point to pages belonging to other processes, no problem Since only the OS can write the page tables, the system is safe
Ch7d- 5 EE/CS/CPE Computer Organization Seattle Pacific University Protection Example VPNValidPPN/ (index)BitDisk address sector sector 4323… sector Page Table for process A: VPNValidPPN/ (index)BitDisk address sector sector sector Page Table for process B: 7.4 How can process A access process B’s V.P ? Note: Since physical page 1100 is shared, protection is violated. None of process A’s V.P. point to Physical page Impossible to to access it!
Ch7d- 6 EE/CS/CPE Computer Organization Seattle Pacific University Shooting Ourselves in the Foot 7.4 Virtual Memory Access Look up page number in page table Access memory Each memory access becomes two accesses Even for addresses stored in the cache Solution: Cache the page table entries in a special cache The Translation Lookaside Buffer (TLB) is just a cache that holds recently accessed page table entries A TLB hit means that we don’t have to actually look in the page table
Ch7d- 7 EE/CS/CPE Computer Organization Seattle Pacific University TLB Design 7.4 We want the TLB to have a high hit rate Fortunately, pages are huge, providing super-high locality TLB usually only has a small number of entries (i.e. 64) and is fully-associative Typical hit rates are 98.0 to 99.9% The TLB should store anything needed from the page table Physical page number Valid bit, Dirty bit Warning: TLB can violate protection after a process switch Flush the TLB on each process switch
Ch7d- 8 EE/CS/CPE Computer Organization Seattle Pacific University Virtual Memory Benefits 7.4 Virtual Memory frees the programmer from many issues Large programs can run in smaller systems It doesn’t matter what else is running on the system, all programs start at a virtual address of zero and can access the entire address space Virtual memory protects different processes from each other
Ch7d- 9 EE/CS/CPE Computer Organization Seattle Pacific University Evidence of Virtual Memory at Work 7.4 Thrashing If a program is just too big, it will constantly page fault to read in new pages (and throw out ones it needs) Paging Out If a program has been sitting idle for a long time, it is likely that it will be completely paged out to disk When you return to the program, it will start out slow as it pages all of the memory back in Loading Bringing in a new program may require writing pages for an old one out to disk