4.2 Cachememory
4.2 Cachememory
2D Organization
- Memory cells are organized in the form of 2D array.
- Each raw refers to a word line.
- Each column refers to a bit of word (data lines).
- Decoders are used to select rows and columns.
Example: 32K words memory uses 15X215 decoder for row selection.
Word Bit line
Word line
Data lines
Memory Array Organization
3D Organization
- n-bit address of rows is divided into two parts x and y.
- Each x and y contains equal or nearly equal bits
Example: In 32K words memory x and y decoders have 7 or 8 bits.
Data lines
Memory Array Organization
2.5D Organization
- Column decoder is segmented
Example: 512X512 words memory uses 9 bits for row decoder and 9 bits for column decoder.
no
Access main memory for word(block) containing address
generated by CPU
Argument register
Address Data
01000 3450
02777 6710
22235 1234
MEMORY AND CACHE MAPPING - DIRECT MAPPING -
- Each memory block has only one place to load in Cache
- n-bit memory address consists of 2 parts; k bits of Index field and n-k bits of Tag field
-n-bit addresses are used to access main memory and k-bit Index is used to access the Cache
-Each word in cache consists of tag-data pair
-When CPU generates a memory request, the index field is used to access the cache
00 000 32K x 12
000
512 x 12
Main memory Cache memory
Address = 15 bits Address = 9 bits
Data = 12 bits Data = 12 bits
77 777 777
01777 4560
02000 5670
777 02 6710
02777 6710
DIRECT MAPPING
Operation
- CPU generates a memory request with (TAG;INDEX)
- Access Cache using INDEX ; (tag; data)
Compare TAG and tag
- If matches -> Hit
Provide Cache[INDEX](data) to CPU
- If not match -> Miss
M[tag;INDEX] <- Cache[INDEX](data)
Cache[INDEX] <- (TAG;M[TAG; INDEX])
CPU <- Cache[INDEX](data)
Disadvantage
- hit ratio drops considerably if two or more words with same index but of different tags are
accessed repeatedly
Each word of cache can store two or more words of memory with same index address.
In this example word length =2(6+12) i.e. 36bits and the size of cache memory =512X36.
Operation
- CPU generates a memory address(TAG; INDEX)
- Access Cache with INDEX, (Cache word = (tag 0, data 0); (tag 1, data 1))
- Compare TAG and tag 0 and then tag 1
- If tag i = TAG -> Hit, CPU <- data i
- If tag i TAG -> Miss,
Replace either (tag 0, data 0) or (tag 1, data 1),
Assume (tag 0, data 0) is selected for replacement,
M[tag 0, INDEX] <- Cache[INDEX](data 0)
Cache[INDEX](tag 0, data 0) <- (TAG, M[TAG,INDEX]),
CPU <- Cache[INDEX](data 0)
CACHE WRITE
Write Through
When writing into memory
If Hit, both Cache and memory is written in parallel
If Miss, Memory is written
For a read miss, missing block may be overloaded onto a cache block
Memory is always updated
Slow, due to the memory access time
Write-Back (Copy-Back)
When writing into memory
If Hit, only Cache is written
If Miss, missing block is brought to Cache and write into Cache
For a read miss, candidate block must be written back to the memory
Memory is not up-to-date, i.e., the same item in Cache and memory may have different value
Cache Initialization
The cache is initialized when power is applied or when main memory is loaded from auxiliary memory.
After initialization cache is considered to be empty.
Each word in cache include valid bit to indicate whether or not word contains valid data.
The cache is initialized by clearing all the valid bits to 0.
When the word is loaded from main memory, the valid bit of cache memory is set to 1.
Problem-Cache Memory
12.15 A two-way set associative cache memory uses blocks of 4 words. The cache can accommodate a total
of 2048 words from main memory. The main memory size is 128KX32.
(a) Formulate all pertinent information required to construct the cache memory.
(b) What is the size of cache memory?
Solution :
Tag(7) Index(10)
(a) 128K means 17 bits address. The set size is 2 (given)
Hence words in cache = 2048/2 i.e. 1024 it means index size is of 10 bits. So tag size = 17-10 i.e. 7 bits
(b) The size of cache memory = 1024 * 2*(7+32)
Tag1(7) Data1(32) Tag2(7) Data2(32)
12.16 The access time of a cache memory is 100 ns and that of main memory 1000 ns. It is estimated that 80%
of memory requests are for read and the remaining 20% for write. The hit ratio for read accesses only is
0.9. A write-through procedure is used.
(a) What is the average access time of the system considering only memory read cycles?
(b) What is the average access time of the system for both read and write requests?
(c) What is the hit ratio taking into consideration the write cycles?
Solution :
(a) Access time = 0.9*100 +0.1*(1000+100) = 90 + 110 =200 ns
(b) Access time = 0.2*1000 + 0.8*200 = 200 + 160 =360 ns
(c) Hit ratio = 0.8*0.9 = 0.72
Problem-Cache Memory
12.17 A four-way set-associative cache memory has 4 words in each set. A replacement procedure based on the
least recently used (LRU) algorithm is implemented by means of 2-bit counters associated with each word
in the set. A value in the range 0 to 3 is thus recorded for each word. When a hit occurs, the counter
associated with the referenced word is set to 0, those counters with values originally lower than the
referenced one are incremented by 1, and all other remains unchanged. If a miss occurs, the word with
counter value 3 is removed, the new word is put in its place, and its counter is set to 0. The other three
counters are incremented by 1. show that this procedure works for the following sequence of word
reference : A, B, C, D, B, E, D, A, C, E, C, E. (Start with A, B, C, D as the initial four words, with word A being
the least recently used.)
Solution : 3 2 1 0
A B C D
B is hit A C D B
E is miss C D B E
D is hit C B E D
and so on
12.18 A digital computer has a memory unit of 64KX16 and a cache memory of 1K words. The cache uses direct
mapping with a block size of 4 words.
(a) How many bits are there in the tag, index, block and word fields of the address format?
(b) How many bits are there in each word of cache and how are they divided into functions? Include a valid bit.
(c) How many blocks can the cache accommodate?
Solution :
(a) 64K means address is of 16 bits.
cache memory size 1K means index size is of 10 bits. Tag Block Word
4 words in a block means word size is of 2 bits. 6 8 2
since index = block + word hence block size is of 10 -2 i.e. 8 bits.
since tag = address – index hence tag size is of 16-10 i.e. 6 bits.
(b) Since word length is 16 hence 16 bits are there in each word i.e. data size is of 16 bits.
1 valid bit (given) V Tag Data
6 bits for tag 1 6 16
(c) Since block size is 8 bits hence total blocks = 28 i.e. 256