Cache and Virtual Memory Flashcards
Why is cache implemented?
Fetching data and instructions from memory is inefficient as the memory is further away from the CPU and is slower.
What is temporal locality?
If an item in memory is referenced, then it is likely to be referenced again soon.
What is spatial locality?
If an item in memory is referenced, then it is likely that those nearby will be referenced soon.
What are cache hits and cache misses?
∙ a cache hit — read data from cache;
∙ a cache miss — read data from memory into cache first.
What are the 3 cache designs?
Direct mapped;
fully-associative;
set-associative.
What is direct-mapped cache?
A memory address is mapped to exactly one cache address.
Search is efficient, if items are mapped in the same place, the previous item is discarded.
What is fully-associative cache?
A memory address is mapped to the least-recently-used cache address. Not used much, longer to search.
What is set-associative cache?
A memory address is mapped to exactly one cache set, each location can contain a small set of addresses. A memory address is mapped to the least recently used place in that set.
Small searches are reasonably efficient.
What is the relationship between caches?
A fully-associative cache with 𝑆 slots is an 𝑆-way associative cache — there is 1 set of size 𝑠.
A direct-mapped cache with 𝑆 slots is a 1-way set-associative cache — there are 𝑆 sets of size 1.
What are the 2 options of write hits?
∙ write back — write into cache only, memory is not updated;
∙ write through — write into both cache and memory, slower, usually used for multicore environments.
What are the 2 options of write misses?
∙ write around — write into memory only;
∙ write allocate — write into memory and read into cache.
What is virtual memory?
Extends the idea of a cache memory to disk.
Too many processes in memory rolls it out to the storage disk.
How is virtual memory divided?
Virtual memory (disk) is divided into pages, and addresses are seen as (virtual-page-number, offset) pairs.
How is RAM divided?
Physical memory (RAM) is divided into frames, and addresses are seen as (physical-frame-number, offset) pairs.
What is a page table?
A per-process page table maps virtual-page-numbers to
physical-frame-numbers or to swap-space on disk.