Lably
Skip to content

Cache pollution

Performance degration due to memory access patterns

  • 3 min read
  • 3 chapters

Related on Lably

Through Computer program, Multi-core processor and Operating system

Example

Consider the following illustration:

T[0] = T[0] + 1; for i in 0..<a rel="mw:WikiLink" href="./Sizeof" title="Sizeof" id="mwFQ">sizeof</a>(CACHE) C[i] = C[i] + 1; T[0] = T[0] + C[sizeof(CACHE)-1];

(The assumptions here are that the cache is composed of only one level, it is unlocked, the replacement policy is pseudo-LRU, all data is cacheable, the set associativity of the cache is N (where N > 1), and at most one processor register is available to contain program values).

Right before the loop starts, T[0] will be fetched from memory into cache, its value updated. However, as the loop executes, because the number of data elements the loop references requires the whole cache to be filled to its capacity, the cache block containing T[0] has to be evicted. Thus, the next time the program requests T[0] to be updated, the cache misses, and the cache controller has to request the data bus to bring the corresponding cache block from main memory again.

In this case the cache is said to be "polluted". Changing the pattern of data accesses by positioning the first update of T[0] between the loop and the second update can eliminate the inefficiency:

for i in 0..<a rel="mw:WikiLink" href="./Sizeof" title="Sizeof" id="mwHw">sizeof</a>(CACHE) C[i] = C[i] + 1; T[0] = T[0] + 1; T[0] = T[0] + C[sizeof(CACHE)-1];

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication