Docsity

Advanced Caching Techniques: Reducing Miss Rates and Increasing Locality - Prof. Steven Ja, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Advanced Caching Techniques: Reducing Miss Rates and Increasing Locality - Prof. Steven Ja and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Advance Caching

Today

“quiz 5” recap

quiz 6 recap

advanced caching

Hand a bunch of stuff back.

Know Thy Enemy

Misses happen for different reasons

The three C’s (types of cache misses)

Compulsory: The program has never requested this data before. A miss is mostly unavoidable.

Conflict: The program has seen this data, but it was evicted by another piece of data that mapped to the same “set” (or cache line in a direct mapped cache)

Capacity: The program is actively using more data than the cache can hold.

Different techniques target different C’s

Compulsory Misses

Compulsory misses are difficult to avoid

Caches are effectively a guess about what data the processor will need.

One technique: Prefetching (240A to learn more)

In this case, the processor could identify the pattern and proactively “prefetch” data program will ask for.

Current machines do this alot...

Keep track of delta= thisAddress - lastAddress, it’s consistent, start fetching thisAddress + delta. for(i = 0;i < 100; i++) { sum += data[i]; }

Reducing Compulsory Misses

HW Prefetching

In this case, the processor could identify the pattern and proactively “prefetch” data program will ask for.

Current machines do this alot...

Keep track of delta= thisAddress - lastAddress, it’s consistent, start fetching thisAddress + delta. for(i = 0;i < 1000000; i++) { sum += data[i]; }

Reducing Compulsory Misses

  • Software prefetching
  • Use register $zero! for(i = 0;i < 1000000; i++) { sum += data[i]; “load data[i+16] into $zero” } For exactly this reason, loads to $zero never fail (i.e., you can load from any address into $zero without fear)

Reducing Conflict Misses

Conflict misses occur because too much data maps to the same “set”

Increase the number of sets (i.e., cache capacity)

Increase the size of the sets (i.e., the associativity)

The compiler and OS can help here too

Colliding Threads and Data

  • The stack and the heap tend to be aligned to large chunks of memory (maybe 128MB).

Threads often run the same code in the same way

This means that thread stacks will end up occupying the same parts of the cache.

Randomize the base of each threads stack.

Large data structures (e.g., arrays) are also often aligned. Randomizing malloc() can help here. 

Stack Thread 0 0x Stack Thread 1 0x Stack Thread 2 0x Stack Thread 3 0x Stack Thread 0 0x Stack Thread 1 0x Stack Thread 2 0x Stack Thread 3 0x

Reducing Capacity Misses

Increase capacity!

More associativity or more associative “sets”

Costs area and makes the cache slower.

Cache hierarchies do this implicitly already:

if the working set “falls out” of the L1, you start using the L2.

Poof! you have a bigger, slower cache.

In practice, you make the L1 as big as you can within your cycle time and the L2 and/or L3 as big as you can while keeping it on chip.

Reducing Capacity Misses: The compiler
  • The key to capacity misses is the working set
  • How a program performs operations has a large impact on its working set.

Increasing Locality in the Compiler or Application

  • Live Demo... The Return!

Capacity Misses in Action

Live Demo... The return! Part Deux!

A Simple Example

Consider a direct mapped cache with 16 blocks, a block size of 16 bytes, and the application repeat the following memory access sequence:

0x80000000, 0x80000008, 0x80000010, 0x80000018, 0x

A Simple Example

a direct mapped cache with 16 blocks, a block size of 16 bytes

16 = 2^4 : 4 bits are used for the index

16 = 2^4 : 4 bits are used for the byte offset

The tag is 32 - (4 + 4) = 24 bits

For example: 0x 80000010 tag index offset