Cache effects and importance of locality

1.1k views Asked by At

I have read this blog and I am still unsure about the importance of locality. Why is locality important for cache performance? Is it because it leads to fewer cache misses? Furthermore, how is a program written in order to achieve good locality and hence good cache performance?

1

There are 1 answers

1
BeeOnRope On

Caches are smaller, and usually much smaller, than the main memories they are associated with. For example, on x86 chips, the L1 cache is typically 32 KiB, while memory sizes of 32 GiB or larger are common, which is more than a million times larger.

Without spatial locality, memory requests would be uniformly distributed in the memory of the application, and then given the very large ratios between memory size and cache size, the chance of hitting in the cache would be microscopic (about one in one million for the example above). So the cache hit rate would be microscopic and the cache would be useless.