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

Virtual Memory in Operating System.

Virtual memory is a method that allows computers to use storage space on hard disks like RAM. It works by transferring inactive memory pages stored in RAM to the hard disk to free up space. When needed pages are accessed again, they are swapped back into RAM. This makes more memory space available virtually than the actual RAM by allowing quick swapping between RAM and disk storage.

Uploaded by

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

Virtual Memory in Operating System.

Virtual memory is a method that allows computers to use storage space on hard disks like RAM. It works by transferring inactive memory pages stored in RAM to the hard disk to free up space. When needed pages are accessed again, they are swapped back into RAM. This makes more memory space available virtually than the actual RAM by allowing quick swapping between RAM and disk storage.

Uploaded by

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

Virtual Memory

What is virtual memory?


• Virtual memory is a method that computers use to manage storage
space to keep systems running quickly and efficiently.

• Using the technique, operating systems can transfer data between


different types of storage, such as random access memory (RAM),
also known as main memory, and hard drive or solid-state disk
storage.
What is virtual memory?

• At any particular time, the computer only needs


enough active memory to support active processes.

• The system can move those that are dormant into virtual memory
until needed.
What is Virtual Memory in OS?
• Imagine the physical memory of your computer in the front section of
your wardrobe.

• You keep the clothes that you would like to wear in front so that they are
handy.

• Now, in the above scenario, consider yourself to be the operating system


and the backside of your wardrobe to be the hard disk.
What is Virtual Memory in OS?
• The clothes at the back can also be accessed when needed although
they may take a little more time.

• To make it easy to search, you may keep a note of where you have
placed what clothing items.

• Such a mapping mechanism is called a page table.
What is Virtual Memory in OS?
• Virtual memory is a part of the system's secondary memory that acts
and gives us a feel as if it is a part of the main memory.

• Virtual memory allows a system to execute heavier applications or


multiple applications simultaneously without exhausting the RAM
(Random Access Memory).
What is Virtual Memory in OS?
• When running multiple heavy applications at once, the system's RAM
may get overloaded.

• To mitigate this issue, some data stored in RAM that isn't being
actively used can be temporarily relocated to virtual memory.
What is Virtual Memory in OS?

• This frees up RAM space, which may then be utilized to store data
that the system will need to access.

• A system can continue to run smoothly with significantly less physical


RAM than it would normally require.

• This can be done by exchanging data between RAM and virtual


memory based on its need.
History of Virtual Memory in OS
• Early computers had two types of storage namely primary and
secondary.
• Back in those times, storage was highly expensive, and thus expanding
it would cause trouble.
• When programs grew and required more memory than there was
present, the system ran out of memory.
• When this happened, they were forced to use the hard drive's memory.
• However, since access to this was slow, they thought that it would be
good to have some kind of fast cheap memory that would help in
solving this problem
How does virtual memory work?
• Virtual memory uses both the computer's software and hardware to
work.

• It transfers processes between the computer's RAM and hard disk by


copying any files from the computer's RAM that aren't currently in
use and moving them to the hard disk.

• By moving unused files to the hard disk, a computer frees up space in


its RAM to perform current tasks, such as opening a new application.
How does virtual memory work?
• If the computer later needs to use its RAM for a more urgent task, it can
again swap files to make the most of the available RAM.

• RAM is a limited resource stored on chips in the computer's CPU.

• Installing more RAM chips can be expensive, so virtual memory allows


the computer to move files between systems as needed to optimize its
use of the available RAM.
How Virtual Memory Works?
• Let's understand the working of virtual memory using the example
shown below.
How Virtual Memory Works?
• Assume that an operating system uses 500 MB of RAM to hold all of
the running processes.

• There is now only 10 MB of actual capacity accessible on the RAM.

• The operating system will then allocate 490 MB of virtual memory and
manage it with an application called the Virtual Memory Manager
(VMM).
How Virtual Memory Works?
• As a result, the VMM will generate a 490 MB file on the hard disc to
contain the extra RAM that is necessary.

• The OS will now proceed to address memory, even if only 10 MB of


space is available because it considers 500 MB of actual memory saved
in RAM.

• It is the VMM's responsibility to handle 500 MB of memory, even if


only 10 MB is available.
Types of virtual memory

Paging
• Paging is a virtual memory technique that separates memory into
sections called paging files.

• When a computer reaches its RAM limits, it transfers any currently


unused pages into the part of its hard drive used for virtual memory.
Types of virtual memory

• The computer performs this process using a swap file, a designated


space within its hard drive for extending the virtual memory of the
computer's RAM.

• By moving unused files into its hard drive, the computer frees its RAM
space for other memory tasks and ensures that it doesn't run out of
real memory.
Demand Paging

• Imagine that you are scrolling through an e-commerce platform and like
some clothes.

• However, since you don't have space in your wardrobe, you save it in
your wishlist and decide to buy them only when needed.

• As compared to this process, demand paging is a process that keeps


pages of a process that are infrequently used in secondary memory, and
pulls them only when required to satisfy the demand.
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.

• A page is copied to the main memory when its demand is made or


page fault occurs.
Demand Paging
• A demand paging system is quite similar to a paging system with
swapping where processes reside in secondary memory and pages are
loaded only on demand, not in advance.

• When a context switch occurs, the operating system does not copy any
of the old program’s pages out to the disk or any of the new program’s
pages into the main memory Instead.

• it just begins executing the new program after loading the first page
and fetches that program’s pages as they are referenced
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.
Demand Paging
• In the above image, when Program A finishes executing, it swaps out
the memory that was in use.

• Program B then swaps in the memory that was required by it to fulfill


the timely demand.

• This is a typical example of demand paging.


Page Table

• A page table is a logical data structure that is used by a virtual


memory to record the mapping between virtual and physical
addresses.

• The programs performed by the accessing process use virtual


addresses, whereas the hardware, notably the random-access
memory (RAM) subsystem, uses physical addresses.

• The page table is an important part of virtual address translation,


which is required to access data in memory.
Types of virtual memory

• As part of this process, the computer uses page tables, which translate
virtual addresses into the physical addresses that the computer's
memory management unit (MMU) uses to process instructions.

• When the user performs a task, the OS searches its RAM for the
processes to conduct the task.

• If it can't find the processes to complete the task in RAM,


the MMU prompts the OS to move the required pages into RAM and
uses a page table to note the new storage location of the pages.
Swap In and Swap Out

• When the primary memory (RAM) is insufficient to store data required by


several applications, we use a method known as swap out to transfer
certain programs from RAM to the hard drive.

• Similarly, when RAM becomes available, we swap in the applications from


hard disk to RAM.

• We may manage many processes inside the same RAM by using swaps.

• Swapping aids in the creation of virtual memory and is cost-effective.


Swap In and Swap Out

• In the above diagram, process 1 is seen to swap in the applications


from hard disk to RAM when they are required,

• further, when there is a lack of available memory, process 2 swaps out


transferring certain programs from RAM to hard disk.

You might also like