Cache and Virtual Memory Replacement Algorithms

Slides:



Advertisements
Similar presentations
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Advertisements

Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
SE-292 High Performance Computing
Chapter 4 Memory Management Basic memory management Swapping
Multilevel Page Tables
1 Overview Assignment 4: hints Memory management Assignment 3: solution.
9.4 Page Replacement What if there is no free frame?
CS 241 Spring 2007 System Programming 1 Memory Replacement Policies Lecture 32 Klara Nahrstedt.
Page Replacement Algorithms
Page Replacement Algorithms
Online Algorithm Huaping Wang Apr.21
Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution -
361 Computer Architecture Lecture 15: Cache Memory
Chapter 3.3 : OS Policies for Virtual Memory
Virtual Memory 3 Fred Kuhns
Module 10: Virtual Memory
Chapter 3 Memory Management
Chapter 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory II Chapter 8.
Memory Management.
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a cache for secondary (disk) storage – Managed jointly.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
25 seconds left…...
SE-292 High Performance Computing
SE-292 High Performance Computing Memory Hierarchy R. Govindarajan
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Oct. 23, 2002 Topic: Memory Hierarchy Design (HP3 Ch. 5) (Caches, Main Memory and.
T-SPaCS – A Two-Level Single-Pass Cache Simulation Methodology + Also Affiliated with NSF Center for High- Performance Reconfigurable Computing Wei Zang.
1 Lecture 13: Cache and Virtual Memroy Review Cache optimization approaches, cache miss classification, Adapted from UCB CS252 S01.
Prof. Sin-Min Lee Department of Computer Science
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
1 Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
1 Virtual Memory Sample Questions Project 3 – Build Pthread Lib Extra Office Hour: Wed 4pm-5pm HILL 367 Recitation 6.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
1  2004 Morgan Kaufmann Publishers Chapter Seven.
1 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4 to 6 transistors) DRAM: –value is stored as a charge.
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
COEN 180 Main Memory Cache Architectures. Basics Speed difference between cache and memory is small. Therefore:  Cache algorithms need to be implemented.
Lecture 33: Chapter 5 Today’s topic –Cache Replacement Algorithms –Multi-level Caches –Virtual Memories 1.
Maninder Kaur CACHE MEMORY 24-Nov
Maninder Kaur VIRTUAL MEMORY 24-Nov
Virtual Memory.
Memory Systems Architecture and Hierarchical Memory Systems
Chapter Twelve Memory Organization
10/18: Lecture topics Memory Hierarchy –Why it works: Locality –Levels in the hierarchy Cache access –Mapping strategies Cache performance Replacement.
L/O/G/O Cache Memory Chapter 3 (b) CS.216 Computer Architecture and Organization.
By Andrew Yee. Virtual Memory Memory Management What is Page Replacement?
1 Virtual Memory Main memory can act as a cache for the secondary storage (disk) Advantages: –illusion of having more physical memory –program relocation.
11 Intro to cache memory Kosarev Nikolay MIPT Nov, 2009.
1 Chapter Seven CACHE MEMORY AND VIRTUAL MEMORY. 2 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4.
1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are ns at cost of $100 to $250 per Mbyte. DRAM access times are ns.
1  2004 Morgan Kaufmann Publishers Locality A principle that makes having a memory hierarchy a good idea If an item is referenced, temporal locality:
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Ramya Kandasamy CS 147 Section 3
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
Chap. 12 Memory Organization
Overview Problem Solution CPU vs Memory performance imbalance
Presentation transcript:

Cache and Virtual Memory Replacement Algorithms 1 Cache and Virtual Memory Replacement Algorithms Presented by Michael Smaili CS 147 Spring 2008

2 Overview

Central Idea of a Memory Hierarchy 3 Central Idea of a Memory Hierarchy Provide memories of various speed and size at different points in the system. Use a memory management scheme which will move data between levels. Those items most often used should be stored in faster levels. Those items seldom used should be stored in lower levels.

4 Terminology Cache: a small, fast “buffer” that lies between the CPU and the Main Memory which holds the most recently accessed data. Virtual Memory: Program and data are assigned addresses independent of the amount of physical main memory storage actually available and the location from which the program will actually be executed. Hit ratio: Probability that next memory access is found in the cache. Miss rate: (1.0 – Hit rate)

Importance of Hit Ratio 5 Importance of Hit Ratio Given: h = Hit ratio Ta = Average effective memory access time by CPU Tc = Cache access time Tm = Main memory access time Effective memory time is: Ta = hTc + (1 – h)Tm Speedup due to the cache is: Sc = Tm / Ta Example: Assume main memory access time of 100ns and cache access time of 10ns and there is a hit ratio of .9. Ta = .9(10ns) + (1 - .9)(100ns) = 19ns Sc = 100ns / 19ns = 5.26 Same as above only hit ratio is now .95 instead: Ta = .95(10ns) + (1 - .95)(100ns) = 14.5ns Sc = 100ns / 14.5ns = 6.9

Cache vs Virtual Memory 6 Cache vs Virtual Memory Primary goal of Cache: increase Speed. Primary goal of Virtual Memory: increase Space.

Cache Mapping Schemes 1) Fully Associative (1 extreme) 7 Cache Mapping Schemes 1) Fully Associative (1 extreme) 2) Direct Mapping (1 extreme) 3) Set Associative (compromise)

Fully Associative Mapping 8 Fully Associative Mapping A main memory block can map into any block in cache. Main Memory Cache Memory Block 1 000 Prog A Block 2 001 Prog B Block 3 010 Prog C Block 4 011 Prog D Block 5 100 Data A Block 6 101 Data B Block 7 110 Data C Block 8 111 Data D Block 1 100 Data A Block 2 010 Prog C Italics: Stored in Memory

Fully Associative Mapping 9 Fully Associative Mapping Advantages: No Contention Easy to implement Disadvantages: Very expensive Very wasteful of cache storage since you must store full primary memory address

Direct Mapping 10 Main Memory Cache Memory Store higher order tag bits along with data in cache. Main Memory Cache Memory Block 1 000 Prog A Block 2 001 Prog B Block 3 010 Prog C Block 4 011 Prog D Block 5 100 Data A Block 6 101 Data B Block 7 110 Data C Block 8 111 Data D Block 1 00 Prog A Block 2 01 Block 3 10 1 Data C Block 4 11 Prog D Italics: Stored in Memory Index bits Tag bits

Direct Mapping Advantages: Disadvantages: 11 Low cost; doesn’t require an associative memory in hardware Uses less cache space Disadvantages: Contention with main memory data with same index bits.

Set Associative Mapping 12 Set Associative Mapping Puts a fully associative cache within a direct-mapped cache. Main Memory Cache Memory Block 1 000 Prog A Block 2 001 Prog B Block 3 010 Prog C Block 4 011 Prog D Block 5 100 Data A Block 6 101 Data B Block 7 110 Data C Block 8 111 Data D Set 1 00 Prog A 10 Data A Set 2 1 11 Data D Data B Italics: Stored in Memory Index bits Tag bits

Set Associative Mapping 13 Set Associative Mapping Intermediate compromise solution between Fully Associative and Direct Mapping Not as expensive and complex as a fully associative approach. Not as much contention as in a direct mapping approach.

Set Associative Mapping 14 Set Associative Mapping Cost Degree Associativity Miss Rate Delta $ 1-way 6.6% $$ 2-way 5.4% 1.2 $$$$ 4-way 4.9% .5 $$$$$$$$ 8-way 4.8% .1 Performs close to theoretical optimum of a fully associative approach – notice it tops off. Cost is only slightly more than a direct mapped approach. Thus, Set-Associative cache offers best compromise between speed and performance.

Cache Replacement Algorithms 15 Cache Replacement Algorithms Replacement algorithm determines which block in cache is removed to make room. 2 main policies used today Least Recently Used (LRU) The block replaced is the one unused for the longest time. Random The block replaced is completely random – a counter-intuitive approach.

16 LRU vs Random Below is a sample table comparing miss rates for both LRU and Random. Cache Size Miss Rate: LRU Random 16KB 4.4% 5.0% 64KB 1.4% 1.5% 256KB 1.1% As the cache size increases there are more blocks to choose from, therefore the choice is less critical  probability of replacing the block that’s needed next is relatively low.

Virtual Memory Replacement Algorithms 17 Virtual Memory Replacement Algorithms 1) Optimal 2) First In First Out (FIFO) 3) Least Recently Used (LRU)

18 Optimal Replace the page which will not be used for the longest (future) period of time. Faults are shown in boxes; hits are not shown. 1 2 3 4 1 2 5 1 2 5 3 4 5 7 page faults occur

19 Optimal A theoretically “best” page replacement algorithm for a given fixed size of VM. Produces the lowest possible page fault rate. Impossible to implement since it requires future knowledge of reference string. Just used to gauge the performance of real algorithms against best theoretical.

FIFO 20 Faults are shown in boxes; hits are not shown. When a page fault occurs, replace the one that was brought in first. Faults are shown in boxes; hits are not shown. 1 2 3 4 1 2 5 1 2 5 3 4 5 9 page faults occur

FIFO Simplest page replacement algorithm. 21 FIFO Simplest page replacement algorithm. Problem: can exhibit inconsistent behavior known as Belady’s anomaly. Number of faults can increase if job is given more physical memory i.e., not predictable

Example of FIFO Inconsistency 22 Example of FIFO Inconsistency Same reference string as before only with 4 frames instead of 3. Faults are shown in boxes; hits are not shown. 1 2 3 4 1 2 5 1 2 5 3 4 5 10 page faults occur

23 LRU Replace the page which has not been used for the longest period of time. Faults are shown in boxes; hits only rearrange stack 1 2 3 4 1 2 5 1 2 5 3 4 5 1 2 5 5 1 2 2 5 1 9 page faults occur

LRU More expensive to implement than FIFO, but it is more consistent. 24 LRU More expensive to implement than FIFO, but it is more consistent. Does not exhibit Belady’s anomaly More overhead needed since stack must be updated on each access.

Example of LRU Consistency 25 Example of LRU Consistency Same reference string as before only with 4 frames instead of 3. Faults are shown in boxes; hits only rearrange stack 1 2 3 4 1 2 5 1 2 5 3 4 5 1 2 1 2 5 4 1 5 1 2 3 4 2 5 1 2 3 4 4 4 7 page faults occur

26 Questions?