Elements of Cache Design
Elements of Cache Design
by CPU in reference to a
program. corresponding logical addresses.
User can view the logical address User can never view physical
Visibility of a program. address of program.
Editable Logical address can be change. Physical address will not change.
2. Cache size
The size of the cache should be small enough so that the overall average
cost per bit is close to that of main memory alone and large enough so that
the overall average access time is close to that of the cache alone.
3. Mapping function
As there are fewer cache lines than main memory blocks, an algorithm is
needed for mapping main memory blocks into cache lines. Further, a
means is needed for determining which main memory block currently
occupies a cache line. The choice of the mapping function dictates how the
cache is organized. Three techniques can be used: direct, associative, and
set associative.
DIRECT MAPPING: The simplest technique, known as direct mapping,
maps each block of main memory into only one possible cache line.
The direct mapping technique is simple and inexpensive to
implement.
ASSOCIATIVE MAPPING: Associative mapping overcomes the
disadvantage of direct mapping by permitting each main memory
block to be loaded into any line of the cache
SET-ASSOCIATIVE MAPPING: Set-associative mapping is a
compromise that exhibits the strengths of both the direct and
associative approaches. With set-associative mapping, block can be
mapped into any of the lines of set j.
4. Replacement algorithm
Once the cache has been filled, when a new block is brought into the
cache, one of the existing blocks must be replaced. For direct mapping,
there is only one possible line for any particular block, and no choice is
possible. For the associative and set associative techniques, a replacement
algorithm is needed. To achieve high speed, such an algorithm must be
implemented in hardware. Least Recently Used (LRU), Least Frequently
Used(LFU), First In First Out (FIFO) are some replacement algorithms.\
- FIFO (first-in-first-out) is also used as a cache replacement algorithm
and behaves exactly as you would expect. Objects are added to the
queue and are evicted with the same order. Even though it provides a
simple and low-cost method to manage the cache but even the most
used objects are eventually evicted when they're old enough.
- The least recently used (LRU) algorithm is one of the most famous
cache replacement algorithms and for good reason! As the name
suggests, LRU keeps the least recently used objects at the top and
evicts objects that haven't been used in a while if the list reaches the
maximum capacity.So it's simply an ordered list where objects are
moved to the top every time they're accessed; pushing other objects
down. LRU is simple and providers a nice cache-hit rate for lots of
use-cases.
5. Write policy
when a block that is resident in the cache is to be replaced, there are
two cases to consider. If the old block in the cache has not been
altered, then it may be overwritten with a new block without first
writing out the old block. If at least one write operation has been
performed on a word in that line of the cache, then main memory
must be updated by writing the line of cache out to the block of
memory before bringing in the new block.
Write through- Ghi thẳng
Simplest technique
All write operations are made to main memory as well as to the
cache
The main disadvantage of this technique is that it generates substantial
(heavy) memory traffic and may create a bottleneck.
6. Line size
Basically, as the block size increases, more useful data are brought into
the cache. The hit ratio will begin to decrease, however, as the block
becomes even bigger and the probability of using the newly fetched
information becomes less than the probability of reusing the information
that has to be replaced.
Larger line size More data Cache hit increases, but expensive and
more data in cache but not used (Normal: 64-128 bytes)
7. Number of cache
When caches were originally introduced, the typical system had a single cache.
More recently, the use of multiple caches has become an important aspect.
There are two design issues surrounding number of caches.