You are on page 1of 41

Unit – 4 (Memory Unit)

Memory Hierarchy
The memory hierarchy design in a computer system mainly includes different
storage devices. Most of the computers were inbuilt with extra storage to run more
powerfully beyond the main memory capacity. The following memory hierarchy
diagram is a hierarchical pyramid for computer memory. The designing of the
memory hierarchy is divided into two types such as primary (Internal) memory and
secondary (External) memory.

Primary Memory
The primary memory is also known as internal memory, and this is accessible by
the processor straightly. This memory includes main, cache, as well as CPU
registers.

Secondary Memory

The secondary memory is also known as external memory, and this is accessible
by the processor through an input/output module. This memory includes an optical
disk, magnetic disk, and magnetic tape.
Characteristics of Memory Hierarchy

The memory hierarchy characteristics mainly include the following.

Performance
Previously, the designing of a computer system was done without memory
hierarchy, and the speed gap among the main memory as well as the CPU registers
enhances because of the huge disparity in access time, which will cause the lower
performance of the system. So, the enhancement was mandatory. The enhancement
of this was designed in the memory hierarchy model due to the system’s
performance increase.

Ability
The ability of the memory hierarchy is the total amount of data the memory can
store. Because whenever we shift from top to bottom inside the memory hierarchy,
then the capacity will increase.

Access Time
The access time in the memory hierarchy is the interval of the time among the data
availability as well as request to read or write. Because whenever we shift from top
to bottom inside the memory hierarchy, then the access time will increase

Cost per bit


When we shift from bottom to top inside the memory hierarchy, then the cost for
each bit will increase which means an internal Memory is expensive compared
with external memory.

Primary memories-

Primary memory is a segment of computer memory that can be accessed directly


by the processor. In a hierarchy of memory, primary memory have access time less
than secondary memory and greater than cache memory. Generally, primary
memory has a storage capacity lesser than secondary memory and greater than
cache memory.
Need of primary memory

In order to enhance the efficiency of the system, memory is organized in such a


way that access time for the ready process is minimized. The following approach is
followed to minimize access time for the ready process.

 All programs, files, and data are stored in secondary storage that is larger and
hence has greater access time.
 Secondary memory can not be accessed directly by a CPU or processor.
 In order, to execute any process operating system loads the process in primary
memory which is smaller and can be accessed directly by the CPU.
 Since only those processes are loaded in primary memory which is ready to be
executed, the CPU can access those processes efficiently and this optimizes the
performance of the system.

Classification of Primary Memory

Primary memory can be broadly classified into two parts:


1. Read-Only Memory (ROM)
2. Random Access Memory (RAM)

Read-Only Memory

Any data which need not be altered are stored in ROM. ROM includes those programs
which run on booting of the system (know as a bootstrap
program that initializes OS) along with data like algorithm required by OS. Anything
stored in ROM cannot be altered or changed.
Types of ROM:
ROM can be broadly classified into 4 types based on their behavior:
 MROM: Masked ROM are hardwired and pre-programmed ROM. Any content that is once
written cannot be altered anyhow.
 PROM: Programmable ROM can be modified once by the user. The user buys a blank
PROM and writes the desired content but once written content cannot be altered.
 EPROM: Erasable and Programmable ROM Content can be changed by erasing the initial
content which can be done by exposing EPROM to UV radiation. This exposure to ultra-
violet light dissipates the charge on ROM and content can be rewritten on it.
 EEPROM: Electrically Erasable and Programmable ROM Content can be changed by
erasing the initial content which could be easily erased electrically. However, one byte can
be erased at a time instead of deleting in one go. Hence, reprogramming of EEPROM is a
slow process.

Random Access Memory

Any process in the system which needs to be executed is loaded in RAM which is
processed by the CPU as per Instructions in the program. Like if we click on
applications like Browser, firstly browser code will be loaded by the Operating system
into the RAM after which the CPU will execute and open up the Browser.
Types of RAM:
RAM can be broadly classified into SRAM (Static RAM) and DRAM (Dynamic RAM)
based on their behavior:
 DRAM: Dynamic RAM or DRAM needs to periodically refresh in few milliseconds to retain
data. DRAM is made up of capacitors and transistors and electric charge leaks from
capacitors and DRAM needs to be charged periodically. DRAM is widely used in home
PCs and servers as it is cheaper than SRAM.
 SRAM: Static RAM or SRAM keeps the data as long as power is supplied to the system.
SRAM uses Sequential circuits like a flip-flop to store a bit and hence need not be
periodically refreshed. SRAM is expensive and hence only used where speed is the utmost
priority.

Secondary Memory

We have read so far, that primary memory is volatile and has limited capacity. So, it is
important to have another form of memory that has a larger storage capacity and from
which data and programs are not lost when the computer is turned off. Such a type of
memory is called secondary memory. In secondary memory, programs and data are
stored. It is also called auxiliary memory. It is different from primary memory as it is
not directly accessible through the CPU and is non-volatile. Secondary or external
storage devices have a much larger storage capacity and the cost of secondary
memory is less as compared to primary memory.
Use of Secondary memory

Secondary memory is used for different purposes but the main purposes of using
secondary memory are:
 Permanent storage: As we know that primary memory stores data only when the power
supply is on, it loses data when the power is off. So we need a secondary memory to
stores data permanently even if the power supply is off.
 Large Storage: Secondary memory provides large storage space so that we can store
large data like videos, images, audios, files, etc permanently.
 Portable: Some secondary devices are removable. So, we can easily store or transfer
data from one computer or device to another.

Types of Secondary memory

Secondary memory is of two types:


1. Fixed storage
In secondary memory, a fixed storage is an internal media device that is used to store
data in a computer system. Fixed storage is generally known as fixed disk drives or
hard drives. Generally, the data of the computer system is stored in a built-in fixed
storage device. Fixed storage does not mean that you can not remove them from the
computer system, you can remove the fixed storage device for repairing, for the
upgrade, or for maintenance, etc. with the help of an expert or engineer.
Types of fixed storage:
Following are the types of fixed storage:
 Internal flash memory (rare)
 SSD (solid-state disk)
 Hard disk drives (HDD)
2. Removable storage
In secondary memory, removable storage is an external media device that is used to
store data in a computer system. Removable storage is generally known as disks
drives or external drives. It is a storage device that can be inserted or removed from
the computer according to our requirements. We can easily remove them from the
computer system while the computer system is running. Removable storage devices
are portable so we can easily transfer data from one computer to another. Also,
removable storage devices provide the fast data transfer rates associated with storage
area networks (SANs).
Types of Removable Storage:
 Optical discs (like CDs, DVDs, Blu-ray discs, etc.)
 Memory cards
 Floppy disks
 Magnetic tapes
 Disk packs
 Paper storage (like punched tapes, punched cards, etc.)
Secondary memory devices

Following are the commonly used secondary memory devices are:


1. Floppy Disk: A floppy disk consists of a magnetic disc in a square plastic case. It is
used to store data and to transfer data from one device to another device. Floppy
disks are available in two sizes (a) Size: 3.5 inches, the Storage capacity of 1.44 MB
(b) Size: 5.25 inches, the Storage capacity of 1.2 MB. To use a floppy disk, our
computer needs to have a floppy disk drive. This storage device becomes obsolete
now and has been replaced by CDs, DVDs, and flash drives.
2. Compact Disc: A Compact Disc (CD) is a commonly used secondary storage
device. It contains tracks and sectors on its surface. Its shape is circular and is made
up of polycarbonate plastic. The storage capacity of CD is up to 700 MB of data. A CD
may also be called a CD-ROM (Compact Disc Read-Only Memory), in this computers
can read the data present in a CD-ROM, but cannot write new data onto it. For a CD-
ROM, we require a CD-ROM. CD is of two types:
 CD-R (compact disc recordable): Once the data has been written onto it cannot be
erased, it can only be read.
 CD-RW (compact disc rewritable): It is a special type of CD in which data can be erased
and rewritten as many times as we want. It is also called an erasable CD.
3. Digital Versatile Disc: A Digital Versatile Disc also known as DVD it is looks just
like a CD, but the storage capacity is greater compared to CD, it stores up to 4.7 GB
of data. DVD-ROM drive is needed to use DVD on a computer. The video files, like
movies or video recordings, etc., are generally stored on DVD and you can run DVD
using the DVD player. DVD is of three types:
 DVD-ROM(Digital Versatile Disc Readonly): In DVD-ROM the manufacturer writes the
data in it and the user can only read that data, cannot write new data in it. For example
movie DVD, movie DVD is already written by the manufacturer we can only watch the
movie but we cannot write new data into it.
 DVD-R(Digital Versatile Disc Recordable): In DVD-R you can write the data but only one
time. Once the data has been written onto it cannot be erased, it can only be read.
 DVD-RW(Digital Versatile Disc Rewritable and Erasable): It is a special type of DVD in
which data can be erased and rewritten as many times as we want. It is also called an
erasable DVD.
4. Blu-ray Disc: A Blu-ray disc looks just like a CD or a DVD but it can store data or
information up to 25 GB data. If you want to use a Blu-ray disc, you need a Blu-ray
reader. The name Blu-ray is derived from the technology that is used to read the disc
‘Blu’ from the blue-violet laser and ‘ray’ from an optical ray.
5. Hard Disk: A hard disk is a part of a unit called a hard disk drive. It is used to
storing a large amount of data. Hard disks or hard disk drives come in different
storage capacities.(like 256 GB, 500 GB, 1 TB, and 2 TB, etc.). It is created using the
collection of discs known as platters. The platters are placed one below the other.
They are coated with magnetic material. Each platter consists of a number of invisible
circles and each circle having the same centre called tracks. Hard disk is of two types
(i) Internal hard disk (ii) External hard disk.
6. Flash Drive: A flash drive or pen drive comes in various storage capacities, such
as 1 GB, 2 GB, 4 GB, 8 GB, 16 GB, 32 GB, 64 GB, up to 1 TB. A flash drive is used to
transfer and store data. To use a flash drive, we need to plug it into a USB port on a
computer. As a flash drive is easy to use and compact in size, Nowadays it is very
popular.
7. Solid-state disk: It is also known as SDD. It is a non-volatile storage device that is
used to store and access data. It is faster, does noiseless operations(because it does
not contain any moving parts like the hard disk), consumes less power, etc. It is a
great replacement for standard hard drives in computers and laptops if the price is low
and it is also suitable for tablets, notebooks, etc because they do not require large
storage.
8. SD Card: It is known as a Secure Digital Card. It is generally used in portable
devices like mobile phones, cameras, etc., to store data. It is available in different
sizes like 1 GB, 2 GB, 4 GB, 8 GB, 16 GB, 32 GB, 64 GB, etc. To view the data stored
in the SD card you can remove them from the device and insert them into a computer
with help of a card reader. The data stores in the SD card is stored in memory
chips(present in the SD Card) and it does not contain any moving parts like the hard
disk.

2D and 2.5D Memory organization:


The internal structure of Memory either RAM or ROM is made up of memory cells that
contain a memory bit. A group of 8 bits makes a byte. The memory is in the form of a
multidimensional array of rows and columns. In which, each cell stores a bit and a complete row
contains a word. A memory simply can be divided into this below form.

2n = N
where n is the no. of address lines and N is the total memory in bytes.
There will be 2n words.

2D Memory organization –
In 2D organization, memory is divided in the form of rows and columns(Matrix). Each row
contains a word, now in this memory organization, there is a decoder. A decoder is a
combinational circuit that contains n input lines and 2n output lines. One of the output lines
selects the row by the address contained in the MAR and the word which is represented by that
row gets selected and is either read or written through the data lines.
2.5D Memory organization –
In 2.5D Organization the scenario is the same but we have two different decoders one is a
column decoder and another is a row decoder. Column decoder is used to select the column and a
row decoder is used to select the row. The address from the MAR goes as the decoders’ input.
Decoders will select the respective cell through the bit outline, then the data from that location
will be read or through the bit, inline data will be written at that memory location.
Read and Write Operations –
1. If the select line is in Reading mode then the Word/bit which is represented by the MAR will be
available to the data lines and will get read.
2. If the select line is in write mode then the data from the memory data register (MDR) will be sent to
the respective cell which is addressed by the memory address register (MAR).
3. With the help of the select line, we can select the desired data and we can perform read and write
operations on it.

Comparison between 2D & 2.5D Organizations –


1. In 2D organization hardware is fixed but in 2.5D hardware changes.
2. 2D Organization requires more gates while 2.5D requires less.
3. 2D is more complex in comparison to the 2.5D organization.
4. Error correction is not possible in the 2D organization but in 2.5D it could be done easily.
5. 2D is more difficult to fabricate in comparison to the 2.5D organization.

Cache Memory
is a special very high-speed memory. It is used to speed up and synchronizing with
high-speed CPU. Cache memory is costlier than main memory or disk memory but
economical than CPU registers. Cache memory is an extremely fast memory type that
acts as a buffer between RAM and the CPU. It holds frequently requested data and
instructions so that they are immediately available to the CPU when needed.
Cache memory is used to reduce the average time to access data from the Main
memory. The cache is a smaller and faster memory which stores copies of the data
from frequently used main memory locations. There are various different independent
caches in a CPU, which store instructions and data.

Levels of memory:
 Level 1 or Register –
It is a type of memory in which data is stored and accepted that are immediately
stored in CPU. Most commonly used register is accumulator, Program counter,
address register etc.
 Level 2 or Cache memory –
It is the fastest memory which has faster access time where data is temporarily
stored for faster access.
 Level 3 or Main Memory –
It is 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 –
It is external memory which is not as fast as main memory but data stays
permanently in this memory.
Cache Performance:
When the processor needs to read or write a location in main memory, it first checks
for a corresponding entry in the cache.
 If the processor finds that the memory location is in the cache, a cache hit has
occurred and data is read from cache
 If the processor does not find the memory location in the cache, a cache miss has
occurred. For a cache miss, the cache allocates a new entry and copies in data
from main memory, then the request is fulfilled from the contents of the cache.
The performance of cache memory is frequently measured in terms of a quantity
called Hit ratio.
Hit ratio = hit / (hit + miss) = no. of hits/total accesses
We can improve Cache performance using higher cache block size, higher
associativity, reduce miss rate, reduce miss penalty, and reduce the time to hit in the
cache.
Cache Mapping:
There are three different types of mapping used for the purpose of cache memory
which are as follows: Direct mapping, Associative mapping, and Set-Associative
mapping. These are explained below.
1. Direct Mapping –
The simplest technique, known as direct mapping, maps each block of main
memory into only one possible cache line. or
In Direct mapping, assign each memory block to a specific line in the cache. If a
line is previously taken up by a memory block when a new block needs to be
loaded, the old block is trashed. An address space is split into two parts index field
and a tag field. The cache is used to store the tag field whereas the rest is stored in
the main memory. Direct mapping`s performance is directly proportional to the Hit
ratio.
2. i = j modulo m
3. where
4. i=cache line number
5. j= main memory block number
m=number of lines in the cache
Division of Physical Address-

In direct mapping, the physical address is divided as-

2. Fully Associative Mapping-

In fully associative mapping,


 A block of main memory can map to any line of the cache that is freely available at that moment.
 This makes fully associative mapping more flexible than direct mapping.

Example-

Consider the following scenario-


Here,
 All the lines of cache are freely available.
 Thus, any block of main memory can map to any line of the cache.
 Had all the cache lines been occupied, then one of the existing blocks will have to be replaced.

Division of Physical Address-

In fully associative mapping, the physical address is divided as-

3. K-way Set Associative Mapping-

In k-way set associative mapping,


 Cache lines are grouped into sets where each set contains k number of lines.
 A particular block of main memory can map to only one particular set of the cache.
 However, within that set, the memory block can map any cache line that is freely available.
 The set of the cache to which a particular block of the main memory can map is given by-

Cache set number


= ( Main Memory Block Address ) Modulo (Number of sets in Cache)

Also Read- Set Associative Mapping | Implementation and Formulas

Example-

Consider the following example of 2-way set associative mapping-

Here,
 k = 2 suggests that each set contains two cache lines.
 Since cache contains 6 lines, so number of sets in the cache = 6 / 2 = 3 sets.
 Block ‘j’ of main memory can map to set number (j mod 3) only of the cache.
 Within that set, block ‘j’ can map to any cache line that is freely available at that moment.
 If all the cache lines are occupied, then one of the existing blocks will have to be replaced.

Division of Physical Address-

In set associative mapping, the physical address is divided as-

PRACTICE PROBLEMS BASED ON DIRECT MAPPING-

Problem-01:

Consider a direct mapped cache of size 16 KB with block size 256 bytes. The size of main memory
is 128 KB. Find-
1. Number of bits in tag
2. Tag directory size

Solution-

Given-
 Cache memory size = 16 KB
 Block size = Frame size = Line size = 256 bytes
 Main memory size = 128 KB

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 128 KB
= 217 bytes
Thus, Number of bits in physical address = 17 bits

Number of Bits in Block Offset-

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

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 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-

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-02:

Consider a direct mapped cache of size 512 KB with block size 1 KB. There are 7 bits in the tag.
Find-
1. Size of main memory
2. 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

We consider that the memory is byte addressable.

Number of Bits in Block Offset-

We have,
Block size
= 1 KB
= 210 bytes
Thus, Number of bits in block offset = 10 bits

Number of Bits in Line Number-

Total number of lines in cache


= Cache size / Line size
= 512 KB / 1 KB
= 29 lines
Thus, Number of bits in line number = 9 bits

Number of Bits in Physical Address-

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
Thus, Number of bits in physical address = 26 bits

Size of Main Memory-

We have,
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
= 29 x 7 bits
= 3584 bits
= 448 bytes
Thus, size of tag directory = 448 bytes

Problem-03:

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-
1. Size of cache memory
2. Tag directory size

Solution-

Given-
 Block size = Frame size = Line size = 4 KB
 Size of main memory = 16 GB
 Number of bits in tag = 10 bits

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 16 GB
= 234 bytes
Thus, Number of bits in physical address = 34 bits
Number of Bits in Block Offset-

We have,
Block size
= 4 KB
= 212 bytes
Thus, Number of bits in block offset = 12 bits

Number of Bits in Line Number-

Number of bits in line number


= Number of bits in physical address – (Number of bits in tag + Number of bits in block offset)
= 34 bits – (10 bits + 12 bits)
= 34 bits – 22 bits
= 12 bits
Thus, Number of bits in line number = 12 bits

Number of Lines in Cache-


We have-
Number of bits in line number = 12 bits
Thus, Total number of lines in cache = 2 12 lines

Size of Cache Memory-

Size of cache memory


= Total number of lines in cache x Line size
= 212 x 4 KB
= 214 KB
= 16 MB
Thus, Size of cache memory = 16 MB

Tag Directory Size-

Tag directory size


= Number of tags x Tag size
= Number of lines in cache x Number of bits in tag
= 212 x 10 bits
= 40960 bits
= 5120 bytes
Thus, size of tag directory = 5120 bytes

PRACTICE PROBLEMS BASED ON FULLY


ASSOCIATIVE MAPPING-

Problem-01:

Consider a fully associative mapped cache of size 16 KB with block size 256 bytes. The size of main
memory is 128 KB. Find-
1. Number of bits in tag
2. Tag directory size
Solution-

Given-
 Cache memory size = 16 KB
 Block size = Frame size = Line size = 256 bytes
 Main memory size = 128 KB

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 128 KB
= 217 bytes
Thus, Number of bits in physical address = 17 bits

Number of Bits in Block Offset-

We have,
Block size
= 256 bytes
= 28 bytes
Thus, Number of bits in block offset = 8 bits
Number of Bits in Tag-

Number of bits in tag


= Number of bits in physical address – Number of bits in block offset
= 17 bits – 8 bits
= 9 bits
Thus, Number of bits in tag = 9 bits

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-

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
Thus, size of tag directory = 72 bytes

Problem-02:

Consider a fully associative mapped cache of size 512 KB with block size 1 KB. There are 17 bits in
the tag. Find-
1. Size of main memory
2. Tag directory size

Solution-

Given-
 Cache memory size = 512 KB
 Block size = Frame size = Line size = 1 KB
 Number of bits in tag = 17 bits

We consider that the memory is byte addressable.

Number of Bits in Block Offset-

We have,
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
Thus, Number of bits in physical address = 27 bits

Size of Main Memory-

We have,
Number of bits in physical address = 27 bits
Thus, 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-

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-03:

Consider a fully associative mapped cache with block size 4 KB. The size of main memory is 16 GB.
Find the number of bits in tag.

Solution-

Given-
 Block size = Frame size = Line size = 4 KB
 Size of main memory = 16 GB

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 16 GB
= 234 bytes
Thus, Number of bits in physical address = 34 bits

Number of Bits in Block Offset-

We have,
Block size
= 4 KB
= 212 bytes
Thus, Number of bits in block offset = 12 bits

Number of Bits in Tag-

Number of bits in tag


= Number of bits in physical address – Number of bits in block offset
= 34 bits – 12 bits
= 22 bits
Thus, Number of bits in tag = 22 bits
PRACTICE PROBLEMS BASED ON SET ASSOCIATIVE
MAPPING-

Problem-01:

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-
1. Number of bits in tag
2. Tag directory size

Solution-

Given-
 Set size = 2
 Cache memory size = 16 KB
 Block size = Frame size = Line size = 256 bytes
 Main memory size = 128 KB

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 128 KB
= 217 bytes
Thus, Number of bits in physical address = 17 bits
Number of Bits in Block Offset-

We have,
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
Thus, Number of lines in cache = 64 lines

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

Number of Bits in Tag-

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

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

Also Read- Practice Problems On Direct Mapping

Problem-02:

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-
1. Size of main memory
2. Tag directory size

Solution-

Given-
 Set size = 8
 Cache memory size = 512 KB
 Block size = Frame size = Line size = 1 KB
 Number of bits in tag = 7 bits

We consider that the memory is byte addressable.

Number of Bits in Block Offset-

We have,
Block size
= 1 KB
= 210 bytes
Thus, Number of bits in block offset = 10 bits
Number of Lines in Cache-

Total number of lines in cache


= Cache size / Line size
= 512 KB / 1 KB
= 512 lines
Thus, Number of lines in cache = 512 lines

Number of Sets in Cache-

Total number of sets in cache


= Total number of lines in cache / Set size
= 512 / 8
= 64 sets
= 26 sets
Thus, Number of bits in set number = 6 bits

Number of Bits in Physical Address-

Number of bits in physical address


= Number of bits in tag + Number of bits in set number + Number of bits in block offset
= 7 bits + 6 bits + 10 bits
= 23 bits
Thus, Number of bits in physical address = 23 bits

Size of Main Memory-

We have,
Number of bits in physical address = 23 bits
Thus, Size of main memory
= 223 bytes
= 8 MB

Tag Directory Size-

Tag directory size


= Number of tags x Tag size
= Number of lines in cache x Number of bits in tag
= 512 x 7 bits
= 3584 bits
= 448 bytes
Thus, size of tag directory = 448 bytes

Problem-03:

Consider a 4-way set associative mapped cache with block size 4 KB. The size of main memory is
16 GB and there are 10 bits in the tag. Find-
1. Size of cache memory
2. Tag directory size

Solution-

Given-
 Set size = 4
 Block size = Frame size = Line size = 4 KB
 Main memory size = 16 GB
 Number of bits in tag = 10 bits

We consider that the memory is byte addressable.

Number of Bits in Physical Address-

We have,
Size of main memory
= 16 GB
= 234 bytes
Thus, Number of bits in physical address = 34 bits

Number of Bits in Block Offset-

We have,
Block size
= 4 KB
= 212 bytes
Thus, Number of bits in block offset = 12 bits
Number of Bits in Set Number-

Number of bits in set number


= Number of bits in physical address – (Number of bits in tag + Number of bits in block offset)
= 34 bits – (10 bits + 12 bits)
= 34 bits – 22 bits
= 12 bits
Thus, Number of bits in set number = 12 bits

Number of Sets in Cache-

We have-
Number of bits in set number = 12 bits
Thus, Total number of sets in cache = 212 sets

Number of Lines in Cache-

We have-
Total number of sets in cache = 212 sets
Each set contains 4 lines

Thus,
Total number of lines in cache
= Total number of sets in cache x Number of lines in each set
= 212 x 4 lines
= 214 lines

Size of Cache Memory-

Size of cache memory


= Total number of lines in cache x Line size
= 214 x 4 KB
= 216 KB
= 64 MB
Thus, Size of cache memory = 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
= 214 x 10 bits
= 163840 bits
= 20480 bytes
= 20 KB
Thus, size of tag directory = 20 KB

Virtual Memory
Virtual memory is the separation of logical memory from physical memory.
This separation provides large virtual memory for programmers when only
small physical memory is available.

Virtual memory is used to give programmers the illusion that they have a
very large memory even though the computer has a small main memory. It
makes the task of programming easier because the programmer no longer
needs to worry about the amount of physical memory available.

You might also like