Week 1 - Memory and Cache Flashcards
What is the primary purpose of memory and cache in a computer system?
To store data and instructions temporarily, allowing faster access by the CPU, improving processor performance.
What are the key performance metrics for cache memory?
Hit rate: Percentage of memory accesses found in the cache.
Miss rate: Percentage of memory accesses not found in the cache.
Average Memory Access Time (AMAT): A measure of the average time required to access memory.
How do you calculate Average Memory Access Time (AMAT)?
AMAT = Hit time + (Miss rate × Miss penalty)
What is a cache hit and a cache miss?
Cache hit: When the data requested by the CPU is found in the cache.
Cache miss: When the data requested is not in the cache, and it must be fetched from main memory.
What is the hit rate formula for cache memory?
Hit rate = (Number of cache hits) / (Total number of data requests)
What is the miss penalty in cache memory?
The additional time required to fetch data from main memory when a cache miss occurs, usually measured in clock cycles.
What are temporal locality and spatial locality in the context of caching?
Temporal locality: Recently accessed data is likely to be accessed again soon.
Spatial locality: Data located near recently accessed data is likely to be accessed soon.
How does direct mapping work in cache memory?
Each memory location is mapped to exactly one cache location using modulo division based on the cache size.
What is the formula for determining the cache index using direct mapping?
Cache index = Memory address mod Cache size (2^k)
What is the role of the valid bit in cache memory?
The valid bit indicates whether the data stored in a cache block is valid (1) or invalid (0).
What happens during a cache miss?
The data is fetched from the main memory.
The data and corresponding tag are copied into the cache.
The valid bit for the cache block is set to 1.
How does the CPU find data in the cache?
The memory address is divided into tag, index, and offset bits.
The index is used to locate a specific cache block.
The tag is compared with the stored tag in the cache.
If the tag matches and the valid bit is set, the data is retrieved from the cache.
What is a cache tag?
A cache tag is a part of the memory address that helps identify whether the data stored in a cache block corresponds to the requested memory address.
What is the difference between direct-mapped cache and fully associative cache?
Direct-mapped cache: Each memory block maps to exactly one cache location.
Fully associative cache: Any memory block can be placed in any cache block.
How does set-associative cache work?
A set-associative cache is a compromise between direct-mapped and fully associative caches. Memory is divided into sets, and each block can be placed in any location within a specific set.