CS161 – Design and Architecture of Computer

Slides:



Advertisements
Similar presentations
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a cache for secondary (disk) storage – Managed jointly.
Advertisements

Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
Morgan Kaufmann Publishers Large and Fast: Exploiting Memory Hierarchy
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
The Memory Hierarchy (Lectures #24) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer Organization.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley and Rabi Mahapatra & Hank Walker.
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 16 Instructor: L.N. Bhuyan
Translation Buffers (TLB’s)
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy (Part II)
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
Lecture 19: Virtual Memory
Lecture 15: Virtual Memory EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
IT253: Computer Organization
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Virtual Memory Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
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”
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
3/1/2002CSE Virtual Memory Virtual Memory CPU On-chip cache Off-chip cache DRAM memory Disk memory Note: Some of the material in this lecture are.
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.
CS161 – Design and Architecture of Computer
Lecture 11 Virtual Memory
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS352H: Computer Systems Architecture
Lecture 12 Virtual Memory.
Virtual Memory User memory model so far:
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.
Memory Hierarchy Virtual Memory, Address Translation
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers Large and Fast: Exploiting Memory Hierarchy
COSC121: Computer Systems. Managing Memory
Chapter 4 Large and Fast: Exploiting Memory Hierarchy Part 2 Virtual Memory 박능수.
Virtual Memory 3 Hakim Weatherspoon CS 3410, Spring 2011
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
ECE 445 – Computer Organization
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Virtual Memory Prof. Eric Rotenberg
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
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.
CS161 – Design and Architecture of Computer
Virtual Memory.
Sarah Diesburg Operating Systems CS 3430
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory 1 1.
Presentation transcript:

CS161 – Design and Architecture of Computer Virtual Memory

Why Virtual memory? Allows applications to be bigger than main memory size Helps with multiple process management Each process gets its own chunk of memory Protection of processes against each other Mapping of multiple processes to memory Relocation Application and CPU run in virtual space Mapping of virtual to physical space is invisible to the application Management between main memory and disk Miss in main memory is a page fault or address fault Block is a page

Mapping Virtual to Physical Memory Virtual Memory Divide memory into equal sized “chunks” or pages (typically 4KB each) Any chunk of Virtual Memory can be assigned to any chunk of Physical Memory ¥ Stack Physical Memory Single Process 64 MB Heap Static Code

Paged Virtual Memory Virtual address space divided into pages Physical address space divided into pageframes Page missing in Main Memory = page fault Pages not in Main Memory are on disk: swap-in/swap-out Or have never been allocated New page may be placed anywhere in MM (fully associative map) Dynamic address translation Effective address is virtual Must be translated to physical for every access Virtual to physical translation through page table in Main Memory

Cache vs VM Cache Virtual Memory Block or Line Page Miss Page Fault Block Size: 32-64B Page Size: 4K-16KB Placement: Direct Mapped, Fully Associative N-way Set Associative Replacement: LRU or Random LRU approximation Write Thru or Back Write Back How Managed: Hardware Hardware + Software (Operating System)

Handling Page Faults A page fault is like a cache miss Must find page in lower level of hierarchy If valid bit is zero, the Physical Page Number points to a page on disk When OS starts new process, it creates space on disk for all the pages of the process, sets all valid bits in page table to zero, and all Physical Page Numbers to point to disk called Demand Paging - pages of the process are loaded from disk only as needed Create “swap” space for all virtual pages on disk

Performing Address Translation VM divides memory into equal sized pages Address translation relocates entire pages offsets within the pages do not change if page size is a power of two, the virtual address separates into two fields: (like cache index, offset fields) Virtual Page Number Page Offset virtual address

Mapping Virtual to Physical Address

Address Translation Want fully associative page placement How to locate the physical page? Search impractical (too many pages) A page table is a data structure which contains the mapping of virtual pages to physical pages There are several different ways, all up to the operating system, to keep this data around Each process running in the system has its own page table

Page Table and Address Translation

Page Table Page table translates address

Mapping Pages to Storage

Replacement and Writes To reduce page fault rate, prefer least-recently used (LRU) replacement Reference bit (aka use bit) in PTE set to 1 on access to page Periodically cleared to 0 by OS A page with reference bit = 0 has not been used recently Disk writes take millions of cycles Block at once, not individual locations Write through is impractical Use write-back Dirty bit in PTE set when page is written

Optimizing VM Page Table too big! Virtual Memory too slow! 4GB Virtual address space / 4 KB page 220 page table entries. Assume 4B per entry. 4MB just for Page Table of single process With 100 process, 400MB of memory is required! Virtual Memory too slow! Requires two memory accesses. One to access page table to get the memory address Another to get the real data

Fast Address Translation Problem: Virtual Memory requires two memory accesses! one to translate Virtual Address into Physical Address (page table lookup) one to transfer the actual data (hit) But Page Table is in physical memory! => 2 main memory accesses! Observation: since there is locality in pages of data, must be locality in virtual addresses of those pages! Why not create a cache of virtual to physical address translations to make translation fast? (smaller is faster) For historical reasons, such a “page table cache” is called a Translation Lookaside Buffer, or TLB

Fast Translation Using a TLB

TLB Translation Virtual-to-physical address translation by a TLB and how the resulting physical address is used to access the cache memory.

TLB Misses If page is in memory If page is not in memory (page fault) Load the PTE from memory and retry Could be handled in hardware Can get complex for more complicated page table structures Or in software Raise a special exception, with optimized handler If page is not in memory (page fault) OS handles fetching the page and updating the page table Then restart the faulting instruction

TLB Miss Handler TLB miss indicates Page present, but PTE not in TLB Page not preset Must recognize TLB miss before destination register overwritten Raise exception Handler copies PTE from memory to TLB Then restarts instruction If page not present, page fault will occur

Page Fault Handler Use faulting virtual address to find PTE Locate page on disk Choose page to replace If dirty, write to disk first Read page into memory and update page table Make process runnable again Restart from faulting instruction

TLB and Cache Interaction Morgan Kaufmann Publishers 26 May, 2018 TLB and Cache Interaction If cache tag uses physical address Need to translate before cache lookup Physically Indexed, Physically Tagged Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

TLB and Cache Addressing Cache review Set or block field indexes are used to get tags 2 steps to determine hit: Index (lookup) to find tags (using block or set bits) Compare tags to determine hit Sequential connection between indexing and tag comparison Rather than waiting for address translation and then performing this two step hit process, can we overlap the translation and portions of the hit sequence? Yes!

Cache Index/Tag Options Physically indexed, physically tagged (PIPT) Wait for full address translation Then use physical address for both indexing and tag comparison Virtually indexed, physically tagged (VIPT) Use portion of the virtual address for indexing then wait for address translation and use physical address for tag comparisons Virtually indexed, virtually tagged (VIVT) Use virtual address for both indexing and tagging…No TLB access unless cache miss Requires invalidation of cache lines on context switch or use of process ID as part of tags

Virtually Index Physically Tagged

Cache & Virtual memory

Summary Virtual Memory overcomes main memory size limitations VM supported through Page Tables TLB enables fast address translation