Virtual Memory Lecture notes from MKP and S. Yalamanchili.

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

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
Virtual Memory Hardware Support
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.
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
Translation Buffers (TLB’s)
©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)
Lecture 33: Chapter 5 Today’s topic –Cache Replacement Algorithms –Multi-level Caches –Virtual Memories 1.
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
Lecture 15: Virtual Memory EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5B:Virtual Memory Adapted from Slides by Prof. Mary Jane Irwin, Penn State University Read Section 5.4,
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
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.
CS2100 Computer Organisation Cache II (AY2010/2011) Semester 2.
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.
CS203 – Advanced Computer Architecture Virtual Memory.
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
CS161 – Design and Architecture of Computer
CS352H: Computer Systems Architecture
Lecture 12 Virtual Memory.
Section 9: Virtual Memory (VM)
From Address Translation to Demand Paging
From Address Translation to Demand Paging
Module: Virtual Memory
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
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers Large and Fast: Exploiting Memory Hierarchy
CSE 153 Design of Operating Systems Winter 2018
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
ECE 445 – Computer Organization
Lecture 12 Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
CSE 153 Design of Operating Systems Winter 2019
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.
Virtual Memory.
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

Virtual Memory Lecture notes from MKP and S. Yalamanchili

Reading OS online text - Sections 4.1-4.3 and Chapter 3

Goal Introduce the process as the abstraction of a running program Understand virtualization of memory as a resource Each process operates as if its entire address space is in physical memory

What makes sharing memory effective?  Locality! The Memory Hierarchy What makes sharing memory effective?  Locality! Memory registers Cache Memory ALU Memory Managed by the compiler Memory Managed by the hardware Managed by the operating system Managed by the operating system Faster Cheaper

Recall The Executable Format Object file ready to be linked and loaded header text static data reloc symbol table debug Linker Store Executable An executable for a Process Load creates an executable instance or process  allocate memory, copy data and code initialize registers and stack, and jumps to the entry point Static Libraries Standard storage formats include ELF, CoFF, etc.

Process A process is a running program with state Code Static data Heap Stack DLL’s A process is a running program with state Stack, memory, open files PC, registers Each process has its own address space. The operating system keeps tracks of the state of all processors E.g., for scheduling processes OS Code

Process Creation (more later) Address Space Core $$ Interconnect DRAM Break it up into contiguous sequence of memory addresses (e.g., pages). disk Load and initialize a process

Morgan Kaufmann Publishers 24 May, 2019 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 Each gets a private virtual address space holding its frequently used code and data Protected from other programs CPU and OS translate virtual addresses to physical addresses VM “block” is called a page VM translation “miss” is called a page fault Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Virtual to Physical Mapping Virtual Address Space Exploit program locality at page granularity Program can be larger than memory At any point in time, the program is in memory+disk Physical Address Space physical virtual physical pages

Morgan Kaufmann Publishers 24 May, 2019 Address Translation Fixed-size pages (e.g., 4K) Examples of translation Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Address Translation: Concepts virtual memory pages (located on disk) Physical memory pages base address VPN offset pages PPN offset offset Move page and translate address Address Translation Data Structure PPN VPN Offsets within the virtual page and corresponding physical page are the same We only need to translate the virtual page number (VPN) to the corresponding physical page number (PPN) also called page frame  effectively a base address

Morgan Kaufmann Publishers 24 May, 2019 Page Tables Stores placement information Array of page table entries, indexed by virtual page number Page table register in CPU points to page table in physical memory (part of the process state) If page is present in memory Page table entry (PTE) stores the physical page number Plus other status bits (referenced, dirty, …) If page is not present PTE can refer to location in swap space on disk Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Translation Using a Page Table Morgan Kaufmann Publishers 24 May, 2019 Translation Using a Page Table Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Morgan Kaufmann Publishers 24 May, 2019 Page Fault Penalty On page fault, the page must be fetched from disk Takes millions of clock cycles Handled by OS code Try to minimize page fault rate Fully associative placement Smart replacement algorithms Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Mapping Pages to Storage Morgan Kaufmann Publishers 24 May, 2019 Mapping Pages to Storage Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Replacement and Writes Morgan Kaufmann Publishers 24 May, 2019 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 Write through is impractical Use write-back Dirty bit in PTE set when page is written Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Caching PTEs: The Translation Lookaside Buffer (TLB) A four entry TLB VPN PPN V state VPN PPN V state VPN PPN V state VPN PPN V state Keep a cache of most recently used PTEs Each PTE corresponds to a “relatively” large part of memory For example, a 16Kbyte page may have 4K instructions A small set of PTEs can cover a large code segment For example, 8 PTEs and 16 Kbyte pages corresponds to a program size of 32K instructions The TLB access time is comparable or better than cache access time Typically operates as a fully associative cache, but can be implemented as a set associative cache

Fast Translation Using a TLB Morgan Kaufmann Publishers 24 May, 2019 Fast Translation Using a TLB Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

TLB Operation TLB size typically a function of the target domain Memory registers virtual address physical address TLB Cache Memory ALU Memory miss Memory Translate & Update TLB TLB size typically a function of the target domain High end machines will have fully associative large TLBs PTE entries are replaced on a demand driven basis The TLB is in the critical path

Morgan Kaufmann Publishers 24 May, 2019 TLB Misses If page is in memory 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 IF ID MEM WB EX Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Morgan Kaufmann Publishers 24 May, 2019 TLB Miss Handler TLB miss indicates one of Page present, but PTE not in TLB Page not present 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 Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Morgan Kaufmann Publishers 24 May, 2019 Page Fault Handler Use faulting virtual address to find PTE Locate page on disk Choose page to replace If dirty, write to disk first What about copies in the cache? Read page into memory and update page table Interaction with the operating system: make process runnable again Restart from faulting instruction Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

TLB and Cache Interaction Morgan Kaufmann Publishers 24 May, 2019 TLB and Cache Interaction If cache tag uses physical address Need to translate before cache lookup Alternative: use virtual address tag Complications due to aliasing Different virtual addresses for shared physical address Example problems Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

2-Level TLB Organization Morgan Kaufmann Publishers 24 May, 2019 2-Level TLB Organization Intel Nehalem AMD Opteron X4 Virtual addr 48 bits Physical addr 44 bits Page size 4KB, 2/4MB L1 TLB (per core) L1 I-TLB: 128 entries for small pages, 7 per thread (2×) for large pages L1 D-TLB: 64 entries for small pages, 32 for large pages Both 4-way, LRU replacement L1 I-TLB: 48 entries L1 D-TLB: 48 entries Both fully associative, LRU replacement L2 TLB (per core) Single L2 TLB: 512 entries 4-way, LRU replacement L2 I-TLB: 512 entries L2 D-TLB: 512 entries Both 4-way, round-robin LRU TLB misses Handled in hardware Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Morgan Kaufmann Publishers 24 May, 2019 Memory Protection Different tasks can share parts of their virtual address spaces But need to protect against errant access Requires OS assistance Hardware support for OS protection Privileged supervisor mode (aka kernel mode) Privileged instructions Page tables and other state information only accessible in supervisor mode System call exception (e.g., syscall in MIPS) Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Sharing Shared physical pages through mappings shared page B’s Page table A’s Page table Process A Main Memory Process B Shared physical pages through mappings This raises issues with the cache Synonym problem: we will not address that here

Morgan Kaufmann Publishers 24 May, 2019 The Memory Hierarchy The BIG Picture Common principles apply at all levels of the memory hierarchy Based on notions of caching At each level in the hierarchy Block placement Finding a block Replacement on a miss Write policy Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Morgan Kaufmann Publishers 24 May, 2019 Concluding Remarks Fast memories are small, large memories are slow We really want fast, large memories  Caching gives this illusion  Principle of locality Programs use a small part of their memory space frequently Memory hierarchy L1 cache  L2 cache  …  DRAM memory  disk Memory system design is critical for multiprocessors Chapter 5 — Large and Fast: Exploiting Memory Hierarchy

Study Guide Be able to trace through the page table and cache data structures on a memory reference (see sample problems) Understand how to allocate virtual pages to page frames to minimize conflicts in the cache Relationships between address translation, page size, and cache size. For example, given a memory system design (page sizes, virtual and physical address spaces, cache parameters) understand the address breakdowns at different levels of the memory hierarchy Be able to map lines in a page to sets in the cache (identify the set from the address)

Study Guide Given a cache design and virtual address space and page size, define the pages (by their addresses) that may conflict in the cache Distinguish between a TLB miss, a data cache miss, and a page fault

Glossary Page Table Page Table Entry (PTE) Page fault Physical address Physical page Physically tagged cache Synonym problem Translation lookaside buffer (TLB) Virtual address Virtual page Virtually tagged cache