


Count the misses that will occur in both designs.Īssume simple mapping that uses (x modulo 8) to calculate the cache block to assign memory block x to.ĭirect mapped will have 3 misses due to conflicts, since 0 and 8 occupy the same block in the cache.

In set associative caches, you can choose which memory block to evict, which can help avoid misses & evictions when the access pattern causes conflict evictions in the direct mapped case.Įxample: Memory block access pattern is 0, 8, 0, 8. In a direct mapped cache, if two memory blocks map to the same cache block, you have to evict the block and store another one. You are right in saying that their capacity will be the same, but you should think about the access pattern and how many evictions and misses will occur in the different designs with respect to the access pattern. But in the case of a direct mapped cache, once you fill a cache block with a single memory block, cache trashing becomes possible). In such a scenario, wouldn't both cases result in 2 memory blocks being mapped to a single cache block? How are they different in this sense? (The only thing I can think of is in a 2-way set associative cache, for each set, you can fit in 2 memory blocks before cache trashing becomes possible. In this case, there would be 4 memory blocks mapped to each cache set. This would mean that for each cache block, there will be 2 blocks of memory that can be mapped to it.įor a 2-way set associative cache (of the same size), there would be 4 sets, each set containing 2 cache blocks. Here's my question: If a Direct Mapped Cache has the same number of cache blocks (lines) as an N-way Set Associative Cache, wouldn't their performance be the same?įor example, say there are 16 blocks of memory and 8 cache blocks in a direct mapped cache.
