Virtual Memory Slides adapted from Dr. Valeriu Bieu, (Washington State University, EE 334, Spring 2005) (originally adapted from Dr. David Patterson, UC.

Slides:



Advertisements
Similar presentations
CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
Advertisements

Virtual Memory Hardware Support
Cs 325 virtualmemory.1 Accessing Caches in Virtual Memory Environment.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley and Rabi Mahapatra & Hank Walker.
Translation Look-Aside Buffers TLBs usually small, typically entries Like any other cache, the TLB can be fully associative, set associative,
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
Recap. The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management 2010.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
Chapter 3.2 : Virtual Memory
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
Vm Computer Architecture Lecture 16: Virtual Memory.
CPE 442 vm.1 Introduction To Computer Architecture CpE 442 Virtual Memory.
CSE431 L22 TLBs.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 22. Virtual Memory Hardware Support Mary Jane Irwin (
Lecture 19: Virtual Memory
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
IT253: Computer Organization
CpE 442 Virtual Memory Start: X:40.
Chapter 4 Memory Management Virtual Memory.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Vm.1 EEL-4713 Computer Architecture Virtual Memory.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
CS203 – Advanced Computer Architecture Virtual Memory.
Memory Management memory hierarchy programs exhibit locality of reference - non-uniform reference patterns temporal locality - a program that references.
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
Lecture 12 Virtual Memory.
Virtual Memory Provides illusion of very large memory
From Address Translation to Demand Paging
CS703 - Advanced Operating Systems
From Address Translation to Demand Paging
CS 704 Advanced Computer Architecture
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Morgan Kaufmann Publishers
Virtual Memory Chapter 8.
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
EECE.4810/EECE.5730 Operating Systems
CS399 New Beginnings Jonathan Walpole.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CS703 - Advanced Operating Systems
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Translation Buffers (TLBs)
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Operating Systems: Internals and Design Principles, 6/E
Virtual Memory.
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory 1 1.
Presentation transcript:

Virtual Memory Slides adapted from Dr. Valeriu Bieu, (Washington State University, EE 334, Spring 2005) (originally adapted from Dr. David Patterson, UC Berkeley)

Outline Virtual Memory Introduction Page Tables and TLB Memory Protection

Virtual Memory Provides illusion of very large memory – Sum of the memory of many jobs greater than physical memory – Address space of each job larger than physical memory Allows available (fast and expensive) physical memory to be very well utilized Simplifies memory management (main reason today) Exploits memory hierarchy to keep average access time low Involves at least two storage levels: main and secondary (disk)

Definitions Virtual Address -- address used by the programmer Virtual Address Space -- collection of such addresses Memory Address -- address of word in physical memory also known as “physical address” or “real address”

Basic Issues in VM System Design Size of information blocks that are transferred from secondary to main storage (M) -- page size Block of information brought into M, and if M is full, then some region of M must be released to make room for the new block --> replacement policy reg cache mem disk pages frame

Basic Issues in VM System Design Which region of M is to hold the new block --> placement policy Missing item fetched from secondary memory only on the occurrence of a fault --> demand load policy Virtual and physical address space partitioned into blocks of equal size Virtual  pages Physical  page frames

Address Mapping V = {0, 1,..., n - 1} virtual address space n > m M = {0, 1,..., m - 1} physical address space MAP: V --> M U {0} address mapping function: MAP(a) = a' if data at virtual address a is present in physical address a' and a' in M = 0 if data at virtual address a is not present in M Processor Name Space V Addr Trans Mechanism Fault handler Main Memory Secondary Memory a a a' 0 physical address OS performs this transfer missing item fault

Paging Organization

Address Mapping Algorithm If valid bit set, then page is in main memory at frame address stored in table; else address located page in secondary memory Access Rights – R = Read-only, R/W = read/write, X = execute only If kind of access requested is not compatible with specified access rights, then protection fault occurred If valid bit not set then page fault occurred

Faults Protection Fault: access rights violation; causes trap to hardware, microcode, or software fault handler Page Fault: page not resident in physical memory, also causes a trap; usually accompanied by a context switch: current process suspended while page is fetched from secondary storage

Fragmentation and Relocation Fragmentation is when areas of memory space become unavailable because the available contiguous memory spaces become too small Relocation: move program or data to a new region of the address space. Need compaction to make larger contiguous address space

Fragmentation and Relocation External Fragmentation: – Space left between blocks Internal Fragmentation: – Program is not an integral # of pages, part of the last page frame is "wasted" (obviously less of an issue as physical memories get larger)

Optimal Page Size Choose page size that minimizes fragmentation – Large page size => internal fragmentation more severe – BUT decreases the number of pages => smaller page tables In general, the trend is towards larger page sizes because – memories get larger as the price of RAM drops – gap between processor speed and disk speed grow wider – programmers demand larger virtual address spaces (larger programs) – smaller page table to maintain increasing virtual address size Most machines at 4K-8K byte pages today, with page sizes likely to increase

More Fragmentation Page Table Fragmentation occurs when page tables become very large because of large virtual address spaces; linearly mapped page tables could take up BIG chunk of memory EX: VAX Architecture (late 1970s): – NOTE: this implies that page table could require up to 2 21 entries, each on the order of 4 bytes long (8 M Bytes!)

More Fragmentation Alternatives to linear page table: – (1) Hardware associative mapping: requires one entry per page frame = O(M) rather than per virtual page = O(V) – (2) "software" approach based on a hash table (inverted page table)

2-Level Page Table

Page Replacement Algorithms (1) Just like cache block replacement! Least Recently Used: – selects the least recently used page for replacement – requires knowledge about past references, more difficult to implement (thread thru page table entries from most recently referenced to least recently referenced; when a page is referenced it is placed at the head of the list; the end of the list is the page to replace) – good performance, recognizes principle of locality

Page Replacement Algorithms (2) Not Recently Used: – Associated with each page is a reference flag such that ref flag = 1 if the page has been referenced in recent past = 0 otherwise – If replacement is necessary, choose any page frame such that its reference bit is 0. This is a page that has not been referenced in the recent past

An implementation of NRU:

Demand Paging and Prefetching Pages Fetch Policy – When is the page brought into memory? – If pages are loaded solely in response to page faults, then the policy is demand paging An alternative is prefetching: – Anticipate future references and load such pages before their actual use (spatial locality) – Reduces page transfer overhead – Removes pages already in page frames, which could adversely affect the page fault rate – Predicting future references usually difficult Most systems implement demand paging without prefetching – One way to obtain effect of prefetching behavior is increasing the page size

Virtual Address and Cache It takes an extra memory access to translate VA to PA This makes cache access very expensive, and this is the "innermost loop" that you want to go as fast as possible! But why access cache with PA at all? VA caches have a problem!

Virtual Address and Cache synonym / alias problem: two different virtual addresses map to same physical address => two different cache entries holding data for the same physical address! for update: must update all cache entries with same physical address or memory becomes inconsistent determining this requires significant hardware, essentially an associative lookup on the physical address tags to see if you have multiple hits

Translation Lookaside Buffer (TLB) A way to speed up translation is to use a special cache of recently used page table entries -- this has many names, but the most frequently used is Translation Lookaside Buffer or TLB TLB access time comparable to cache access time (much less than main memory access time)

Translation Lookaside Buffer Just like any other cache, the TLB can be organized as fully associative, set associative, or direct mapped TLBs are usually small, typically not more than entries even on high end machines. This permits fully associative lookup on these machines. Most mid-range machines use small n-way set associative organizations.

Reducing Translation Time Machines with TLBs go one step further to reduce # cycles/cache access They overlap the cache access with the TLB access Works because high order bits of the VA are used to look in the TLB while low order bits are used as index into cache

Overlapped Cache and TLB Access IF cache hit AND (cache tag = PA) then deliver data to CPU ELSE IF [cache miss OR (cache tag = PA)] and TLB hit THEN access memory with the PA from the TLB ELSE do standard VA translation

Problems with Overlapped Cache/TLB Access Overlapped access only works as long as the address bits used to index into the cache do not change as the result of VA translation This usually limits things to small caches, large page sizes, or high n-way set associative caches if you want a large cache

Problems with Overlapped Cache/TLB Access Example: suppose everything the same except that the cache is increased to 8 K bytes instead of 4 K:

More on Selecting a Page Size Reasons for larger page size – Page table size is inversely proportional to the page size; therefore memory is saved – Fast cache hit time easy when cache <= page size; bigger page makes it feasible to build bigger cache without alias problem – Transferring larger pages to or from secondary storage, possibly over a network, is more efficient (cost per bit decreased) – Number of TLB entries are restricted by clock cycle time, so a larger page size maps more memory thereby reducing TLB misses Reasons for a smaller page size – Don’t waste storage; data must be contiguous within page – Quicker process start for small processes? Hybrid solution: multiple page sizes – Alpha, UltraSPARC: 8KB, 64KB, 512 KB, 4 MB pages

Summary Virtual Memory invented as another level of the hierarchy Original purpose: run programs bigger than physical memory, by swapping pieces to disk DRAM growth reduced that need Today VM allows many processes to share single memory without having to swap all processes to disk, so protection is more important (Multi-level) page tables to map virtual address to physical address TLBs are important for fast translation TLB misses are significant in performance

Segmentation (see x86) Alternative to paging (often combined with paging) Segments allocated for each program module; may be different sizes; segment is unit of transfer between physical memory and disk Faults: – missing segment (Present = 0) – over-/under-flow (Displacement exceeds segment length) – protection violation (access incompatible with segment protection) Segment-based addressing sometimes used to implement capabilities, i.e., hardware support for sophisticated protection mechanisms

Segment Based Addressing Three Serious Drawbacks: – (1) storage allocation with variable sized blocks (best fit vs. fit fit vs. buddy system) – (2) external fragmentation: physical memory allocated in such a fashion that all remaining pieces are too small to be allocated to any segment. Solved by expensive run-time memory compaction. – (3) complex addressing: segment & offset need be manipulated separately The best of both worlds: paged segmentation schemes used by IBM: 4K byte pages, 16 x 1 Mbyte or 64 x 64 Kbyte segments

Alpha VM Mapping “64-bit” address divided into 3 segments – seg0 (bit 63=0) user code/heap – seg1 (bit 63 = 1, 62 = 1) user stack – kseg (bit 63 = 1, 62 = 0) kernel segment for OS 3 level page table, each one page – Alpha only 43 unique bits of VA – (future min page size up to 64KB => 55 bits of VA) PTE bits; valid, kernel & user read & write enable (No reference, use, or dirty bit)

Conclusion #1 Virtual Memory invented as another level of the hierarchy Controversial at the time: can SW automatically manage 64KB across many programs? DRAM growth removed the controversy Today VM allows many processes to share single memory without having to swap all processes to disk, protection more important (Multi-level) page tables to map virtual address to physical address TLBs are important for fast translation TLB misses are significant in performance

Conclusion #2 Theory of Algorithms & Compilers based on number of operations Compiler remove operations and “simplify” ops: Integer adds << Integer multiplies << FP adds << FP multiplies – Advanced pipelines => these operations take similar time With higher clock rates and longer pipelines, instructions take less time but DRAMs only slightly faster (although much larger) Today time is a function of (ops, cache misses) Given importance of caches, what does this mean to: Compilers? Data structures?Algorithms?