lecture 12 Flashcards
Cache Memory, Mapping Algorithms, and the Principle of Locality
cache memory (real definition)
small fast SRAM-based memory
- managed in automatically in the hardware (NOT SOFTWARE)
- located on CPU
- hold frequently accessed memory blocks in RAM (main memory)
cache (online definition)
fast storage buffer that is located in the CPU (central processing unit) of a computer
*also called cache memory
where is cache located?
CPU (central processing unit) in your computer
what are blocks?
blocks –> equal-sized chunks of main memory that are held in the cache
are blocks physical partitions?
no, block is a contiguous range of physical address locations
controller
————
0
1
2
…
N - 1
—————–
how many blocks is RAM partitioned into?
RAM = N-1 blocks in total
what is the process for a Block Read Operation for a block that is not in the cache?
- CPU sends Block Read operation
to RAM controller- operation –> CPU sends the start
address of the block in RAM
- operation –> CPU sends the start
- RAM controller goes to that address in main memory
- makes a copy of the block (aka
data) - puts the copy of the block onto
the BUS
- makes a copy of the block (aka
- CPU controller reads the copy of the block from the BUS
- puts it in cache memory in the
CPU
what is the process for a Block Write Operation for a block that is in the cache that needs to be in main memory?
- CPU controller goes into cache
- puts a copy of block onto the BUS
with a specific address in the
main memory
- puts a copy of block onto the BUS
- RAM controller reads from the BUS
- goes to that specific address in
main memory - replaces current block with the
copy of the block from the BUS
from the cache in the CPU
- goes to that specific address in
block size in main memory = ? bytes
4 bytes
0000 —- start of block 0
0001
0010
0011 —- end of block 0
0100 —- start of block 1
0101
0110
0111 —- end of block 1
what are these binary numbers an example of?
block address bits
0000 —- start of block 0
0001
0010
0011 —- end of block 0
0100 —- start of block 1
0101
0110
0111 —- end of block 1
what is ‘10’, ‘11’, ‘01’, ‘10’ an example of?
block offset bits
what are block offset bits?
the last two binary digits in the block address bits –> references specific byte within the block
ex) byte at offset 11
- references one byte within
block with unique block offset
bits
block size =
2^b
b = bytes
total number of blocks =
2^m/ 2^b
m = physical address bits (4)
b = bytes
3 types of cache mapping algorithms
- Fully Associative
- Direct Mapping
- Set Associative
which type doesn’t have line bits?
FA–> the block could be anywhere in the cache
which type does have line bits?
DM–> line bits determine exactly where the block is located in the cache
which type has the block replacement algorithm?
FA
what is the block replacement algorithm?
cache = full, line must be evicted to make space for new line of data
3 methods to determine which block to replace for FA
- LRU (least recently used)
- FIFO (first in first out)
- Random (no favoritism)
**DM
0 1 1 0
what is the tag bit?
0 –> msb
**DM
0 1 1 0
what is the line bit?
1 –> next bit to left of msb
**DM
0 1 1 0
what are the block offset bits?
1 0 –> last two bits after tag and line
- 0 is technically lsb
what are the two different policies for writing operations for cache?
- write-through: CPU writes are cached while also written to main memory
- stalls the CPU until write is done - write-back: CPU writes are cached, but not immediately written to main memory
- main memory contents become
“stale”
- value = evicted or modified
(“dirty”) –> then written to main
memory
how big is a block in physical memory?
one word
principle of locality
programs tend to use data and instructions in memory that have addresses near or equal to those they have used recently
temporal locality
recently referenced blocks are likely to be referenced again in the near future
spatial locality
blocks with nearby addresses tend to be referenced close together in time