One Final Issue: Cache Affinity

This lesson briefly explains the issue of cache affinity and how it may affect CPU performance.

One final issue arises in building a multiprocessor cache scheduler, known as cache affinity“Evaluating the Performance of Cache-Affinity Scheduling in Shared-Memory Multiprocessors” by Josep Torrellas, Andrew Tucker, Anoop Gupta. Journal of Parallel and Distributed Computing, Volume 24:2, February 1995. This is not the first paper on the topic, but it has citations to earlier work and is a more readable and practical paper than some of the earlier queuing-based analysis papers.. This notion is simple: a process, when run on a particular CPU, builds up a fair bit of state in the caches (and TLBs) of the CPU. The next time the process runs, it is often advantageous to run it on the same CPU, as it will run faster if some of its state is already present in the caches on that CPU. If instead, one runs a process on a different CPU each time, the performance of the process will be worse, as it will have to reload the state each time it runs (note it will run correctly on a different CPU thanks to the cache coherence protocols of the hardware). Thus, a multiprocessor scheduler should consider cache affinity when making its scheduling decisions, perhaps preferring to keep a process on the same CPU if at all possible.

Get hands-on with 1200+ tech skills courses.