Virtual Memory - 5
Virtual Memory - 5
ASSIGNMENT
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.
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.
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 Out
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
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
“Logical “Physical
Addresses” Addresses”
Logical Physical
Address
CPU Translation Memory
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