Virtual Memory
Virtual Memory
Virtual Memory
CoursesTutorialsJobsPracticeContests
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 1/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
If these characteristics are present then, 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 or Demand Segmentation.
Demand Paging
The process of loading the page into memory on demand (whenever a
page fault occurs) is known as demand paging. The process includes
the following steps are as follows:
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 2/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Demand Paging
Hence whenever a page fault occurs these steps are followed by the
operating system and the required page is brought into memory.
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 3/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Page Fault Service Time: The time taken to service the page fault is
called page fault service time. The page fault service time includes the
time taken to perform all the above six steps.
Swapping
Swapping is a process out means removing all of its pages from
memory, or marking them so that they will be removed by the normal
page replacement process. Suspending a process ensures that it is not
runnable while it is swapped out. At some later time, the system
swaps back the process from the secondary storage to the main
memory. When a process is busy swapping pages in and out then this
situation is called thrashing.
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 5/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Swappinghierar
Thrashing
At any given time, only a few pages of any process are in the main
memory, and therefore more processes can be maintained in memory.
Furthermore, time is saved because unused pages are not swapped in
and out of memory. However, the OS must be clever about how it
manages this scheme. In the steady state practically, all of the main
memory will be occupied with process pages, so that the processor
and OS have direct access to as many processes as possible. Thus
when the OS brings one page in, it must throw another out. If it throws
out a page just before it is used, then it will just have to get that page
again almost immediately. Too much of this leads to a condition called
Thrashing. The system spends most of its time swapping pages rather
than executing instructions. So a good page replacement algorithm is
required.
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 6/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
down and the system will spend more time only on the page
replacement and the time taken to complete the execution of the
process will increase. This situation in the system is called thrashing.
Causes of Thrashing
For example:
Let free frames = 400
Case 1: Number of processes = 100
Then, each process will get 4 frames.
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 7/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Recovery of Thrashing
Do not allow the system to go into thrashing by instructing the
long-term scheduler not to bring the processes into memory after
the threshold.
If the system is already thrashing then instruct the mid-term
scheduler to suspend some of the processes so that we can recover
the system from thrashing.
Frame Allocation
A number of frames allocated to each process in either static or
dynamic.
Paging Policies
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 8/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Answer:
Answer:
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 9/15
5/16/24, 12:26 PM Virtual Memory in Operating System - GeeksforGeeks
Answer:
https://www.geeksforgeeks.org/virtual-memory-in-operating-system/ 10/15