What is Cache

It is a components those hold commonly used memory data . The number of data words that cache can hold is called Capacity . Cache is fast.

When processor attempt to access data, it check the cache first

  • If the cache hits, data is available immediately.
  • If the cache miss, processor fetch data from memory and place in cache for future use

Note

spatial locality : when the processor accesses a piece of data, it is also likely to access data in nearby memory locations.
temporal locality : the processor is likely to access a piece of data again soon if it has accessed that data

cache use these concept to predict what data will be needed

What data is held in cache?

Ideally, cache want cache miss rate to be zero so the ideal cache would have all data needed by processor, fetch it from memory ahead of time.

But we don’t know future, so cache will try to guess which data we need based on past pattern of memory access

we use concept of spatial locality and temporal locality

  • When processor load or store data that is not in the cache, the data is copied into cache.
  • When cache fetch one word from memory, it may also fetch other adjacent words we called this group of words a cache block or cache line

How is Data found?

  • A cache organize into Set, each one hold one or more blocks of data.
  • Relationship between address of data in main memory and location of that data in cache call mappings

Note

Cache Block : Groups of words fetch from memory Sets : A place where cache hold one or more cache blocks of data Mappings : Relation between address of memory and location of that data in cache

Category of cache

Cache is categorized based on number of blocks in set.

Direct mapped cache

Each set contains exactly one block. Cache has

  • a particular main memory address maps into a unique block in cache
N-ways set associative cache

Each set contains blocks. Cache has

  • Address still maps to a unique set
  • Data from that address can go to any of the blocks in that set
Fully associative cache

Cache only has , Data can go in any of the block in sets.