0% found this document useful (0 votes)
133 views

Module 4 Extra Problems On Cache

The document discusses different levels of memory in a computer system including cache memory. It describes three types of cache memory mapping: direct mapping, set associative mapping, and fully associative mapping. For each mapping type, it provides details on how a memory block is mapped to the cache and examples of solving problems to determine the number of bits in tags, sets, offsets and calculating tag directory sizes for given cache and memory configurations.

Uploaded by

Lalala Land
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

Module 4 Extra Problems On Cache

The document discusses different levels of memory in a computer system including cache memory. It describes three types of cache memory mapping: direct mapping, set associative mapping, and fully associative mapping. For each mapping type, it provides details on how a memory block is mapped to the cache and examples of solving problems to determine the number of bits in tags, sets, offsets and calculating tag directory sizes for given cache and memory configurations.

Uploaded by

Lalala Land
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Module 4

ROM chip
Cache Memory (Levels of memory)
Cache Memory (Levels of memory)
• Level 1 or Register : Data is stored and accepted that are
immediately stored in CPU. Most commonly used
registers are accumulator, Program counter, address
register etc.
• Level 2 or Cache memory: Fastest memory which has
faster access time where data is temporarily stored.
• Level 3 or Main Memory: Memory on which computer
works currently. It is small in size and once power is off
data no longer stays in this memory.
• Level 4 or Secondary Memory: External memory which is
not as fast as main memory but data stays permanently in
this memory.
Cache Mapping
• Direct mapping, Associative mapping, and Set-
Associative mapping
Cache Mapping: Direct mapping
• Maps each block of main memory into only one
possible cache line.
Consider a direct mapped cache of size 16 KB with block
size 256 bytes. The size of main memory is 128 KB. Find the
number of bits in tag and Tag directory size.
• Solution:
Given:-
– Cache memory size = 16 KB
– Block size = Frame size = Line size = 256 bytes
– Main memory size = 128 KB
•  Consider that the memory is byte addressable
•  Number of Bits in Physical Address-
• Size of main memory= 128 KB = 217 bytes
• Thus, Number of bits in physical address = 17 bits
Problem 1
Consider a direct mapped cache of size 16 KB with block
size 256 bytes. The size of main memory is 128 KB. Find the
number of bits in tag and Tag directory size.

• Solution:
Number of bits in physical address = 17 bits
Consider a direct mapped cache of size 16 KB with block
size 256 bytes. The size of main memory is 128 KB. Find the
number of bits in tag and Tag directory size.

• Number of Bits in Block Offset-


•  Block size = 256 bytes = 28 bytes
• Thus, Number of bits in block offset = 8 bits
Consider a direct mapped cache of size 16 KB with block size
256 bytes. The size of main memory is 128 KB. Find the
number of bits in tag and Tag directory size.
• Number of Bits in Line Number-
Total number of lines in cache = Cache size /Line size
• = 16 KB / 256 bytes
• = 214 bytes / 28 bytes = = 26 lines
• Thus, Number of bits in line number = 6 bits
• Number of Bits in Tag-
•  = Number of bits in physical address – (Number
of bits in line number + Number of bits in block
offset)
• = 17 bits – (6 bits + 8 bits) = 17 bits – 14 bits
• = 3 bits
• Thus, Number of bits in tag = 3 bits
• Tag Directory Size
•  = Number of tags x Tag size
• = Number of lines in cache x Number of bits in tag
• = 26 x 3 bits
• = 192 bits
• = 24 bytes
• Thus, size of tag directory = 24 bytes
Problem 2
Problem-02: Consider a direct mapped cache of size 512 KB
with block size 1 KB. There are 7 bits in the tag. Find Size of
main memory, Tag directory size

• Solution
• Given:
• Cache memory size = 512 KB
• Block size = Frame size = Line size = 1 KB
• Number of bits in tag = 7 bits
• Consider that the memory is byte addressable.
Problem-02: Consider a direct mapped cache of size 512 KB
with block size 1 KB. There are 7 bits in the tag. Find Size of
main memory, Tag directory size
• Number of Bits in Block Offset-
•  Block size = 1 KB = 210 bytes
• Thus, Number of bits in block offset = 10 bits

Number of Bits in Line Number


• Cache size / Line size = 512 KB / 1 KB = 29 lines
• Number of bits in line number = 9 bits
Problem-02: Consider a direct mapped cache of size 512 KB
with block size 1 KB. There are 7 bits in the tag. Find Size of
main memory, Tag directory size
• Number of Bits in Block Offset-
•  Block size = 1 KB = 210 bytes
• Thus, Number of bits in block offset = 10 bits

Number of Bits in Line Number


• Cache size / Line size = 512 KB / 1 KB = 29 lines
• Number of bits in line number = 9 bits
Number of bits in physical address
= Number of bits in tag + Number of bits in line number +
Number of bits in block offset
• = 7 bits + 9 bits + 10 bits = 26 bits
Number of bits in physical address = 26 bits
Size of Main Memory-
•  Number of bits in physical address = 26 bits
• Thus, Size of main memory = 226 bytes = 64 MB
• Tag Directory Size-
•  Tag directory size = Number of tags x Tag size
= Number of lines in cache x Number of bits in tag = = 2 9 x 7 bits
• = 3584 bits = 448 bytes
• Thus, size of tag directory = 448 bytes
Problem 3
3. Consider a direct mapped cache with block size 4 KB. The size of
main memory is 16 GB and there are 10 bits in the tag. Find the Size
of cache memory and Tag directory size.

• Block size = Frame size = Line size = 4 KB


• Size of main memory = 16 GB
• Number of bits in tag = 10 bits

Number of Bits in Physical Address ?


Number of Bits in Block Offset ?
Number of Bits in Line Number ?
Number of Lines in Cache ?
Size of Cache Memory?
Tag Directory Size?
Set Associative Mapping
• A particular block of main memory can be mapped
to one particular cache set only.
• Block ‘j’ of main memory will map to set number (j
mod number of sets in cache) of the cache.
• A replacement algorithm is needed if the cache is
full.
Problem 4
Consider a 2-way set associative mapped cache of size 16 KB with
block size 256 bytes. The size of main memory is 128 KB. Find
Number of bits in tag and Tag directory size

• Given: Set size = 2, Cache memory size = 16 K,


Block size = Frame size = Line size = 256 bytes,
Main memory size = 128 KB, consider that the
memory is byte addressable.
• Number of Bits in Physical Address-
• Size of main memory= 128 KB = 217 bytes
• Thus, Number of bits in physical address = 17 bits
Consider a 2-way set associative mapped cache of size 16 KB with
block size 256 bytes. The size of main memory is 128 KB. Find
Number of bits in tag and Tag directory size

Number of Bits in Block Offset-


• Block size = 256 bytes = 28 bytes
• Thus, Number of bits in block offset = 8 bits

• Number of Lines in Cache-


Total number of lines in cache = Cache size /Line size
= 16 KB / 256 bytes = 214 bytes / 28 bytes = 64 lines
Consider a 2-way set associative mapped cache of size 16 KB with
block size 256 bytes. The size of main memory is 128 KB. Find
Number of bits in tag and Tag directory size

• Number of Sets in Cache-


Total number of sets in cache
• = Total number of lines in cache / Set size
• = 64 / 2 = 32 sets = 25 sets
• Thus, Number of bits in set number = 5 bits
Consider a 2-way set associative mapped cache of size 16 KB with
block size 256 bytes. The size of main memory is 128 KB. Find
Number of bits in tag and Tag directory size

• Number of Bits in Tag-


= Number of bits in physical address – (Number of
bits in set number + Number of bits in block offset)
= 17 bits – (5 bits + 8 bits) = 17 bits – 13 bits = 4 bits
• Thus, Number of bits in tag = 4 bits
Consider a 2-way set associative mapped cache of size 16 KB with
block size 256 bytes. The size of main memory is 128 KB. Find
Number of bits in tag and Tag directory size

• Tag Directory Size-


= Number of tags x Tag size
• = Number of lines in cache x Number of bits in tag
• = 64 x 4 bits = 256 bits = 32 bytes
• Thus, size of tag directory = 32 bytes
Three types of cache memory mapping
Three types of cache memory mapping
• In a fully associative cache every memory location can
be cached in any cache line. This memory type
significantly decreases amount of cache-line misses,
considered as complex type of cache memory
implementation.
• In direct-mapped cache memory location maps to a
single cache line. It can be used once per address per
amount of time. Performance of this cache memory
type is lower than others.
• In N-way-set-associative cache, the most common
cache implementation, memory address can be stored
in any N lines of cache.
Three types of cache memory mapping
• In a fully associative cache every memory location can
be cached in any cache line. This memory type
significantly decreases amount of cache-line misses,
considered as complex type of cache memory
implementation.
• In direct-mapped cache memory location maps to a
single cache line. It can be used once per address per
amount of time. Performance of this cache memory
type is lower than others.
• In N-way-set-associative cache, the most common
cache implementation, memory address can be stored
in any N lines of cache.
Fully Associative Mapping
• A block of main memory can be mapped to
any freely available cache line.
• This makes fully associative mapping more
flexible than direct mapping.
• A replacement algorithm is needed to replace
a block if the cache is full.
Problem 5
Consider a fully associative mapped cache of size 16 KB
with block size 256 bytes. The size of main memory is 128
KB. Find the number of bits in tag, Tag directory size.
• Cache memory size = 16 KB
• Block size = Frame size = Line size = 256 bytes
• Main memory size = 128 KB
• Size of main memory= 128 KB = 217 bytes
• Number of bits in physical address = 17 bits
Number of Bits in Block Offset
• Block size = 256 bytes = 28 bytes
• Number of bits in block offset = 8 bits

• Number of Bits in Tag


Number of Lines in Cache
• Total number of lines in cache = Cache size/Line size
• = 16 KB / 256 bytes = 214 bytes / 28 bytes = 26 lines
• Tag Directory Size = Number of tags x Tag size
• = Number of lines in cache x Number of bits in tag
• = 26 x 9 bits = 576 bits = 72 bytes
• Size of tag directory = 72 bytes
Problem 6
Consider a fully associative mapped cache of size 512
KB with block size 1 KB. There are 17 bits in the tag.
Find the size of main memory, Tag directory size

• Cache memory size = 512 KB


• Block size = Frame size = Line size = 1 KB
• Number of bits in tag = 17 bits
Consider a fully associative mapped cache of size 512
KB with block size 1 KB. There are 17 bits in the tag.
Find the size of main memory, Tag directory size

• Cache memory size = 512 KB


• Block size = Frame size = Line size = 1 KB
• Number of bits in tag = 17 bits
• Number of Bits in Block Offset
• Block size = 1 KB = 210 bytes
• Thus, Number of bits in block offset = 10 bits
• Number of Bits in Physical Address
Number of bits in physical address = Number of bits
in tag + Number of bits in block offset
• = 17 bits + 10 bits = 27 bits

• Size of Main Memory= Number of bits in physical


address = 27 bits
• Size of main memory = 227 bytes = 128 MB
• Number of Lines in Cache-
Total number of lines in cache = Cache size / Line size
• = 512 KB / 1 KB = 512 lines = 29 lines

• Tag Directory Size-


• = Number of tags x Tag size
• = Number of lines in cache x Number of bits in tag
• = 29 x 17 bits = 8704 bits = 1088 bytes
• Thus, size of tag directory = 1088 bytes
Problem 7 : Consider a 8-way set associative mapped cache of size
512 KB with block size 1 KB. There are 7 bits in the tag. Find Size of
main memory and Tag directory size.

You might also like