Cache Knowledge Base
Cache Knowledge Base
Cache Knowledge Base
CACHE
• To speed up accesses by storing recently used data closer to
CPU instead of main memory
• Accessed by content Content Addressable Memory
HIT / MISS
• Cache Hit - When requested data is found in cache
• Cache Miss – When requested data is not found in the cache
REPLACEMENT POLICY
How do we choose victim cache line?
• FIFO (First In First Out)
• LRU (Least Recently Used)
• Random
Length of address in Main Memory
DEFINITIONS
• TAG – distinguished one cache memory block with another
• INDEX – identifies the cache block
• OFFSET – points to desired data in cache block
PRO / CONS
Direct mapping is simple and inexpensive to implement, but if a program accesses 2 blocks that map to the same line
repeatedly, the cache begins to thrash back and forth reloading the line over and over again leads to high miss rate.
Length of address in Main Memory
DEFINITIONS
• TAG – distinguished one cache memory block with another
• OFFSET – points to desired data in cache block
INSTRUCTION BREAKDOWN
Length of load instruction : log2(M) bits
Each of the address of load instruction is broken OFFSET :z bits
into three parts: tag and offset. TAG : log2(M) – log2(C) bits
Main memory size = M , cache size = C and offset CACHE BLOCKS : log2(C) blocks
bits = Z results in the following (right figure).
HOW IT WORKS
• The requested address is broken down into tag and offset.
• Requested tag will be searched through cache with valid bit
• If there is tag matched with one of the index in the
cache table, cache hit is obtained
• Else, cache miss is obtained
• When cache hit is obtained, data from cache table will be
returned. Else, data will be retrieved from main memory.
PRO / CONS
Fully Associative is the most efficient utilisation of cache blocks, yet it is expensive to transverse through the cache to
find each requested tag. Since there is no specified slot for each instruction, an algorithm of replacement policy must
be designed along with implementation of fully associative cache.
Length of address in Main Memory
INSTRUCTION BREAKDOWN
Length of load instruction : log2(M) bits
Each of the address of load instruction is broken OFFSET :z bits
into three parts: tag, index and offset. INDEX : log2(C) – z – log2(N) bits
N-way set associative, Main memory size = M , TAG : log2(M) – log2(C) + log2(N)bits
cache size = C and offset bits = Z results in the CACHE BLOCKS : log2(C) blocks
following (right figure).
HOW IT WORKS
• The requested address is broken down into tag, index and
offset.
• Cache table with corresponding index will be examined. N-
ways of cache blocks will be transversed.
• If one of the way has the requested index, a cache hit
will be obtained
• Else cache miss is obtained
• When cache hit is obtained, data from cache table will be
returned. Else, data will be retrieved from main memory.
PRO / CONS
Combining direct mapped and fully associative principle is seen as the most balanced way to obtain high hit rate
meanwhile maintaining the resources cost. However, N-Way associative could be hard for initial implementation as
various concepts is involved.
• Different cache types has varied resource utilisation. This section will
explain NAND gates used in each type of cache.
• Decision made by each cache type when an instruction is loaded:
• Direct Mapped : 1 * valid_bit + valid_bit_1* tag_comparison.
• Fully Associative : cache_size * valid_bit + valid_bit_1 * tag_comparison
• N-way set associative : N* valid_bit + valid_bit_1 *tag_comparison
• Valid_bit_1 is a variable to calculate the number of (validbit==1) in
respective situation, meanwhile valid_bit and tag_comparison are the
NAND needed for each action.
Valid_Bit Tag_Comparison_per_bit
(2 NAND GATES) (4 NAND GATES)
• Tag_comparison = cache_bit * tag_comparison_per_bit.
• Hence, the costs of each cache can be summarised as:
PAGE TABLE
• Data structure that maintain information concerning the
location of each page, whether on disk or in memory.
Length of Virtual Address
DEFINITIONS
• Page Frames – virtual memory partitions of
main memory.
• OFFSET – points to desired data in page
frame
• Physical address – actual memory address
of physical memory
• Virtual address – addresses where physical
address mapped into