a brief introduction to cache locality yin wei dong 14 ss
TRANSCRIPT
![Page 1: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/1.jpg)
A BRIEF INTRODUCTION TO CACHE LOCALITY
YIN WEI DONG
14 SS
![Page 2: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/2.jpg)
THINGS TO BE DISCUSSED
• Types of locality
• Algorithms to improve data locality
• History of locality reference
• Thrashing
• Applications
![Page 3: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/3.jpg)
TEMPORAL LOCALITY
• If at one point in time a particular memory location is referenced, then it is likely that the same location will be referenced again in the near future.
• To make efforts to store a copy of the referenced data in special memory storage, which can be accessed faster.
![Page 4: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/4.jpg)
SPATIAL LOCALITY
• If a particular memory location is referenced at a particular time, then it is likely that nearby memory locations will be referenced in the near future.
• To attempt to guess the size and shape of the area around the current reference for which it is worthwhile to prepare faster access.
![Page 5: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/5.jpg)
BRANCH LOCALITY
• Few amount of possible alternatives in the critical path
• Not a spatial locality since few possibilities can be located far away from each other.
![Page 6: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/6.jpg)
OVERVIEW
• The average memory reference time is
++
= average memory reference time
m=miss ratio
=the latency: the time to reference the cache when there is a hit
=various secondary effects
Important factor:LATENCYHIT RATIO
![Page 7: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/7.jpg)
EXAMPLE : LEAST RECENT USED
• Discards the least recently used items first
• expensive to always discards the least recently used item
• Implementation : keeping "age bits"
![Page 8: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/8.jpg)
EXAMPLE : MOST RECENTLY USED
• Discards the most recently used items first.
• In contrast to LRU
• Better for random access patterns and repeated scans over large datasets
![Page 9: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/9.jpg)
EXAMPLE : RANDOM REPLACEMENT(RR)
• Randomly selects a candidate item and discards it to make space when necessary
• Used in ARM processors for its simplicity
![Page 10: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/10.jpg)
OPTIMAL SOLUTION IN THEORY
• The most efficient caching algorithm would be to always discard the information that will not be needed for the longest time in the future.
• Not implementable in practice because it is impossible to predict.
• Used to compare the effectiveness of the actually chosen cache algorithm with the optimal solution after experimentation.
![Page 11: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/11.jpg)
CACHE-OBLIVIOUS ALGORITHM
• designed to take advantage of a CPU cache without having the size of the caches as a parameter.
• Good performance on multiple machines with different cache sizes without modification
• Works by a recursive divide and conquer algorithm
![Page 12: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/12.jpg)
HISTORY OF LOCALITY REFERENCE
Hints: The learning algorithm was controversial. It performed well on programs with well-defined loops and poorly on many other programs.
![Page 13: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/13.jpg)
HISTORY OF LOCALITY REFERENCE
WHY THRASHING?
![Page 14: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/14.jpg)
HISTORY OF LOCALITY REFERENCE
![Page 15: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/15.jpg)
WHY THRASHING
• memory to disk : if the working set of a program or a workload cannot be effectively held within physical memory, then constant data swapping may occur
• CPU cache to memory : main memory is accessed in a pattern that leads to multiple main memory locations competing for the same cache lines, resulting in excessive cache misses and lack of performance
![Page 16: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/16.jpg)
SOLUTIONS
• Increase the amount of RAM in the computer.
• Decrease the number of programs being run on the computer.
• Replace programs that are memory-heavy with equivalents that use less memory.
• Assign working priorities to programs, i.e. low, normal, high.
• Improve spatial locality
![Page 17: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/17.jpg)
APPLICATIONS OF CACHE LOCALITY
• In Web browsers to hold recent Web pages.
• In search engines to find the most relevant responses to queries.
• In video boards to accelerate graphics displays
• In edge servers to hold recent Web pages accessed by anyone in an organization or geographical region
• The principle of cache locality will be useful wherever there is an advantage in reducing the apparent distance from a process to the objects it accesses
![Page 18: A BRIEF INTRODUCTION TO CACHE LOCALITY YIN WEI DONG 14 SS](https://reader031.vdocuments.us/reader031/viewer/2022013004/5697bfdf1a28abf838cb26dc/html5/thumbnails/18.jpg)
END