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

Virtual Memory - 5

The document discusses the memory hierarchy in computers, detailing its five levels: registers, cache, main memory, magnetic discs/SSDs, and external hard drives. It explains the concepts of virtual memory, swapping, demand paging, and the role of the Memory Management Unit (MMU) in translating logical addresses to physical addresses. Additionally, it covers the importance of cache memory, access time, and performance in optimizing memory usage and system efficiency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Virtual Memory - 5

The document discusses the memory hierarchy in computers, detailing its five levels: registers, cache, main memory, magnetic discs/SSDs, and external hard drives. It explains the concepts of virtual memory, swapping, demand paging, and the role of the Memory Management Unit (MMU) in translating logical addresses to physical addresses. Additionally, it covers the importance of cache memory, access time, and performance in optimizing memory usage and system efficiency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

MEMORY HIERARCHY

ASSIGNMENT

Introduction to Cache memory


Types/Hierarchy of cache memory
Cache organization and replacement policies
Cache Hit Cache Miss
Principles of locality
MEMORY HIERARCHY

The memory in a computer can


be divided into five hierarchies
based on the speed as well as
use. The processor can move
from one level to another based
on its requirements. It is the
organization of the memory for
saving the access time.
MEMORY HIERARCHY
 The five hierarchies in the memory are

1. Registers
2. Cache
3. Main memory
4. Magnetic Discs/ Solid-state drive (SSD).
5. External Hard Drives/Optical Disk
This Memory Hierarchy Design is divided into 2 main types:
 Internal Memory or Primary Memory: Comprising of Main Memory, Cache Memory & CPU registers. This is directly
accessible by the processor. These are volatile memories which means when there is no power, and then
automatically they lose their stored data.
 External Memory or Secondary Memory: Comprising of Magnetic Disk, Optical Disk, and Magnetic Tape i.e.
peripheral storage devices which are accessible by the processor via an I/O Module. Secondary storage, such
as hard disk drives (HDD) and solid-state drives (SSD), is a non-volatile memory unit that has a larger storage
capacity than main memory. It is used to store data and instructions that are not currently in use by the CPU. they
store the data permanently.
CHARACTERISTICS OF MEMORY HIERARCHY

 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.
 Capacity: It is the global volume of information the memory can store. 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
VIRTUAL MEMORY

 Basic Concept: Virtual memory is a memory management technique where secondary memory
can be used as if it were a part of the main memory. In this way a computer can address more
memory than the amount physically installed on the system. This extra memory is actually
called virtual memory and it is a section of a hard disk that's set up to emulate the computer's
RAM.

 Cause: Today, most personal computers (PCs) come with at least 8 GB (gigabytes) of RAM. But,
sometimes, this is not enough to run several programs at one time. This is where virtual memory
comes in.
HOW VIRTUAL MEMORY WORKS

 Virtual memory frees up RAM by swapping data that has not been used recently over to a storage
device, such as a hard drive or solid-state drive (SSD).

 If, at any point, the RAM space is needed for something more urgent, data can be swapped out of RAM
and into virtual memory.

 The computer's memory manager is in charge of keeping track of the shifts between physical and virtual
memory. If that data is needed again, the computer’s Memory Management Unit (MMU) will manage to
resume execution.

 VM is handled by the operating system.


VIRTUAL MEMORY USES

 Virtual memory is important for Improving system performance, multitasking and using large programs.

 Computers have a finite amount of RAM, so memory will eventually run out when multiple programs
run at the same time. With virtual memory, a system can load larger or multiple programs running at
the same time, enabling each one to operate as if it has more space, without having to purchase more
RAM.
 Program can be given consistent view of memory, even though physical memory is scrambled.

 Makes multithreading reasonable (now used a lot!)

 Since all this procedure happens automatically, therefore it makes the computer feel like it is having
the unlimited RAM.
SWAPPING

 Swapping is a memory management scheme in which any process can be temporarily swapped from
main memory to secondary memory so that the main memory can be made available for other
processes. It is used to improve main memory utilization. In secondary memory, the place where the
swapped-out process is stored is called swap space.

 The purpose of the swapping-in, is to access the data present in the hard disk and bring it to RAM so
that the application programs can use it. The thing to remember is that swapping is used only when data
is not present in RAM.
SWAPPING

 Swap In

Swap-in is a method of removing a program from a


hard disk and putting it back into the main memory
or RAM.

 Swap Out

Swap-out is a method of removing a process from


RAM and adding it to the hard disk.
DEMAND PAGING

 Demand Paging is a popular method of virtual memory management. In demand paging, the pages of a process
which are least used, get stored in the secondary memory.

 It is not necessary that all the pages or segments are present in the main memory during execution. This means that
the required pages need to be loaded into memory whenever required. Virtual memory is implemented using
Demand Paging.

 While executing a program, if the program references a page which is not available in the main memory because it
was swapped out a little ago, the processor treats this invalid memory reference as a Page fault and transfers
control from the program to the operating system to demand the page back into the memory.

 A page is copied to the main memory when its demand is made or page fault occurs. There are various page
replacement algorithms which are used to determine the pages which will be replaced.
PAGING

One of the most popular methods of virtual memory management is memory paging. The process of
retrieving processes in the form of pages from the secondary storage into the main memory is known as
paging. Paging is a memory management scheme that eliminates the need for a contiguous allocation of
physical memory. The basic purpose of paging is to separate each procedure into pages. In that way
computer moves unnecessary files to its hard drive, freeing up RAM for other memory-intensive operations.
LOGICAL VS PHYSICAL ADDRESS

 What is a Logical Address?

An address that is created by the CPU while a program is running is known as a logical address. It is
assumed as a virtual address because it doesn’t have a physical presence and that is why it is also known
as a virtual address.
 What is a Physical Address?

A physical address is the actual address in the main memory where data is stored. It is a location in
physical memory, as opposed to a virtual address. Physical addresses are computed by the MMU. MMU
translate logical addresses into physical addresses.
PAGING

• Virtual memory uses both hardware and software to operate. When an application is in use, data from
that program is stored in RAM using a physical address. A memory management unit (MMU) maps the
address to RAM and automatically translates addresses. The MMU can, for example, map a logical
address space to a corresponding physical address.

• The Physical Address Space is conceptually divided into a number of fixed-size blocks, called frames.
• The Logical Address Space is also split into fixed-size blocks, called pages.
• Page Size = Frame Size
PAGING

 In paging, the physical memory is divided into fixed-size


blocks called page frames, which are the same size as
the pages used by the process. The process’s logical
address space is also divided into fixed-size blocks
called pages, which are the same size as the page
frames. When a process requests memory, the
operating system allocates one or more page frames to
the process and maps the process’s logical pages to
the physical page frames.
PAGING
PAGING

Suppose process P2 and P4 are


swapped out.

Given the fact that, we have 8 non


contiguous frames available in the
memory and paging provides the
flexibility of storing the process at
the different places. Therefore, we
can load the pages of process P5 in
the place of P2 and P4.
MEMORY MANAGEMENT UNIT (MMU)

The mapping from virtual to physical


address is done by the Memory
management unit (MMU) which is a
hardware device and this mapping is
known as the paging technique.
PAGING
Proces
PAGE TABLE s

A Page table is a data structure used by a virtual


memory system in a computer to store mappings
between logical addresses and physical addresses.
Logical addresses are used by the program executed by
the accessing process, while physical addresses are
used by random-access memory (RAM) subsystem.
The mapping between logical pages and physical page
frames is maintained by the page table, which is used
by the memory management unit to translate logical
addresses into physical addresses. The page table
maps each logical page number to a physical page
frame number.
The page table is a key component of virtual address
translation that is necessary to access data in memory.
PAGING
 Let us assume 2 processes, P1 and P2,
contains 4 pages each. Each page size is 1
KB. The main memory contains 8 frame of
1 KB each. The OS resides in the first two
partitions. In the third partition, 1st page of
P1 is stored and the other frames are also
shown as filled with the different pages of
processes in the main memory.
 The page tables of both the pages are 1
KB size each and therefore they can be fit
in one frame each. The page tables of
both the processes contain various
information that is also shown in the
image.
PAGING

 The CPU contains a register which


contains the base address of page table
that is 5 in the case of P1 and 7 in the
case of P2.
PAGING

“Logical “Physical
Addresses” Addresses”
Logical Physical

Address
CPU Translation Memory

Data

User programs run in a standardized virtual address space

Address Translation hardware managed by the operating system (OS)


maps virtual address to physical memory
TRANSLATION LOOKASIDE BUFFER (TLB)

“Virtual Addresses” “Physical


Addresses”
A0-A31 Virtual Physical A0-A31
Translation
CPU Look-Aside Memory
D0-D31 Buffer D0-D31
(TLB)
Data

A translation lookaside buffer is a memory cache that stores the recent translations of
virtual memory to physical memory. It is used to reduce the time taken to access a user
memory location. It can be called an address-translation cache. It is a part of the chip's
memory-management unit. 23
Logical Addresses Physical Addresses

You might also like