34-Cache Memory Block Identification in Direct Mapping, Associate Mapping and Set Associate-06-03-2
34-Cache Memory Block Identification in Direct Mapping, Associate Mapping and Set Associate-06-03-2
Organization
• Course Code: BCSE205L
• Course Type: Theory (ETH)
• Slot: A2+TA2
• Timings:
Monday 14:00-14:50
Wednesday 15:00-15:50
Friday 16:00-16:50
Fully Associative
Tag
Offset
FCFS
Random
Write Through
Write back
Update Policies
Write around
Write allocate
Cache Memory Management Techniques
Index
Offset
How to manage the cache and main memory collectively
(together).
• Paging is the management of the hard drive and main memory together.
• A page can fit into one frame when MM memory is broken up into units
known as frames. (Note: Pages are used to organise secondary memory.)
• In same way, the cache is divided into what are referred to as lines in order to
manage the main memory and cache. Here The main memory is organised
into units referred to as blocks.
• Now, each block size will be determined so that it is equal to the line size.
Note:
➢ It is possible to divide MM into blocks and frames.
➢ While talking about the HDD and Main memory we are taking about the page movement.
➢ While talking about the MM and cache we talk about blocks
Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore
How to manage the cache and main memory collectively
(Example).
Word: Smallest addressable unit in the memory.
Block: Collection of one or more words
Assume, the word size is 1Byte. That is 1word=1Byte. Which means this system is byte addressable.
Consider that the MM is 64 words. Assume that there are 16 words in the cache.
There are four words in each block.
1 Block=4 words.
How many blocks are there in the MM if one block is four words?
Blocks in MM = 64 words / 4 = 16 blocks.
Cache number line: 16/4 = 4 Lines
There are 64 words. Address lines or physical addresses are 6 bits since 2^(6)=64.
How to manage the cache and main memory collectively
(Example).
• Consider that the MM is 64 words.
Assume that there are 16 words in the
cache.
• There are four words in each block.
• 1 Block=4 words.
• How many blocks are there in the
MM if one block is four words?
• Blocks in MM = 64 words / 4 = 16
blocks.
• Cache number line: 16/4 = 4 Lines
• There are 64 words. Address lines or
physical addresses are 6 bits since
2^(6)=64.
000101➔ 0 0 0 1 01
How to manage the cache and main memory collectively
(Example).
Block number Block offset
000101➔ 0 0 0 1 01
The two least significant bits will give you a value known as
Block offset. Block offset refers to the term that is contained
within the block.
The four bits with the most significance will give you a block
number. Block number refers the block where the CPU-required
word is present.
Look into block number 1 because of 0001 and then block Here 01 means 1.
Words in the block start from 0. So 1 means the second word, that is 5.
How to manage the cache and main memory collectively
(Example).
Another example, 001010
0010 10
We are aware that MM has a larger capacity (higher number of blocks) than
cache memory. Naturally, it is not possible to put all the words from MM in a
cache.
Cache: Mappings (Cache Memory Management Techniques)
Mapping: Is a cache memory management techniques. Each memory block in the main
memory is mapped to a line in the cache is known as mapping.
• Mapping will answer the following things:
• What (which block) and how can then be stored in cache memory? This idea is known
as mapping.
• Where are the MM-blocks going to be maintained if you have to place them in the
cache?
• This means, which line of the cache does one block of MM holds?
Set Associative
Fully Associative
Cache line number = ( Main Memory Block Address ) Modulo (Number of lines in Cache)
If we consider
block 4 bits then
we have the
following binary
pattern.
Therefore, from 6 bits CPU address line, the first two least significant bits indicate the block offset (i.e.,
word location in block) and the Next four bits indicate the block address. In the block number field, the
first two least significant bits indicate the line number of the cache and the remaining two bits indicates
Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore
the tag directory.
Cache: Mappings (Cache Memory Management Techniques)
Direct mapping TAG field in Block Identification
From 6 bits CPU address line,
• The first two least significant bits indicate the block offset (i.e., word location in
block) and the
• Next four bits indicate the block address.
• In the block number field, the first two least significant bits indicate the line
number of the cache and
• The remaining two bits indicates the tag directory.
• Block address can be used to determine the block number in this case, and block offset is
used to determine where the word is located inside the block in MM.
• The first two LSB of the block number represent the line number of the cache, which
identifies the line number on which that word can be found there.
• What use does the TAG field, which is created from the remaining bits of the block
number, then serve?
Index
Offset
Cache: Mappings (Cache Memory Management Techniques) : Direct mapping
Q: Given MM size=128KB and cache size=16KB, block size=256B then find tag bits and Tag directory size.
Tag bits in physical address. Here memory is byte addressable
Here memory is byte addressable, which means Every address should able to produce all the bytes present in that memory size.
From given 128KB, there are 128K Bytes are present.
Then we convert the 128K in 2^? to get the number of bits. 128K=27*210=217➔17bits
The physical address (PA) for 28KB MM size is =17bits According to the cache, this
PA will be represented as
Q: Given MM size=128KB and cache size=16KB, block size=256B then find tag bits and Tag directory size.
Tag bits in physical address. Here memory is byte addressable
Block size is 256B, Block offset Number of lines or Line numbers= Total cache Totally bits are 17, except Line
to represent the block size of size/Block size or Line size = number 6 bits and Block offset 8bits
256B=2^8➔ 8bits 16KB/256B=24*210/28=26 remaining (17-(6+8)=3) 3 bits are
tag bits.
So 6bits are used to represent the line number.
Or
That size of MM/size of cache
=128KB/16KB=27*210/24*210=23
➔3 bits
Tag Directory size: each tag information is going to be 3 bits. And Every line is containing
tag. So tag directory size is 3*Number of lines=3*26bits.
Dr. Venkata Phanikrishna B, SCOPE, VIT-Vellore
Tag Index Offset
For instance, where are you putting the 100th MM block if there are 4 cache lines?
The 100th MM block will be in the 0th line of the cache, because 100mod4=0.
So, if there is any xth block main memory will be place in x mod #cachelines or x mod 2#cach bits
If the cache has 4 lines (line 0 to line 3). Then according to the direct mapping where the following blocks are present. 5, 6, 4,
8, 9, 12, 15, and 20
➢ 5 is present at 5%4=1➔Line 1
➢ 6 is present at 6%4=2➔Line 2
➢ 4 is present at 4%4=0➔Line 0
➢ 8 is present at 8%4=0==Line 0, but the 4th block is already present there. Here 8th block
conflicts with the 4th block, therefore line-0 4th block is going to replace by the 8th block.
➢ 9 is present at 9%4=1==Line 1, but the 5th block is already present there. Here 9th block
conflicts with the 5th block, therefore line-1 5th block is going to replace by the 9th block.
➢ 12 is present at 12%4=0==Line 0, but the 8th block is already present there. Here 12th block
conflicts with the 8th block, therefore line-0 8th block is going to replace by the 12th block.
➢ 15 is present at 15%4=3➔Line 3
Direct Mapping
15 • If each block has only one place it can
14 appear in the cache, the cache is said to be
14 direct mapped.
13
7
12
6
11
5
10
4
9
3
8
2
7
1
6
0
5
4 Cache
3
2 =(MM Block address)
1 mod
0 (Number of lines in a cache)
Main Memory (12) mod (8) =4
Drawback of direct mapping
The drawback of direct mapping is conflict miss.
Consider a example, If the cache has 4 lines (line 0 to line 3). Then according to the direct mapping where
the following blocks are present. 4, 8, 16, 16, 20, 12, and 24.
Even if there are many lines in the cache, they will never be used due to the direct mapping restriction. This
is the conflict miss issue with direct mapping.