Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE) PDF Download

Virtual Memory in Operating System

Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory. The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites, and program generated addresses are translated automatically to the corresponding machine addresses.
The size of virtual storage is limited by the addressing scheme of the computer system and the amount of secondary memory is available not by the actual number of the main storage locations.
It is a technique that is implemented using both hardware and software. It maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory.

  1. All memory references within a process are logical addresses that are dynamically translated into physical addresses at run time. This means that a process can be swapped in and out of the main memory such that it occupies different places in the main memory at different times during the course of execution.
  2. A process may be broken into a number of pieces and these pieces need not be continuously located in the main memory during execution. The combination of dynamic run-time address translation and use of page or segment table permits this.

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 page fault occurs) is known as demand paging.

The process includes the following steps
Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

  1. If CPU try to refer a page that is currently not available in the main memory, it generates an interrupt indicating memory access fault.
  2. The OS puts the interrupted process in a blocking state. For the execution to proceed the OS must bring the required page into the memory.
  3. The OS will search for the required page in the logical address space.
  4. The required page will be brought from logical address space to physical address space. The page replacement algorithms are used for the decision making of replacing the page in physical address space.
  5. The page table will updated accordingly.
  6. The signal will be sent to the CPU to continue the program execution and it will place the process back into ready state.

Hence whenever a page fault occurs these steps are followed by the operating system and the required page is brought into memory.

Advantages

  1. More processes may be maintained in the main memory: Because we are going to load only some of the pages of any particular process, there is room for more processes. This leads to more efficient utilization of the processor because it is more likely that at least one of the more numerous processes will be in the ready state at any particular time.
  2. A process may be larger than all of main memory: One of the most fundamental restrictions in programming is lifted. A process larger than the main memory can be executed because of demand paging. The OS itself loads pages of a process in main memory as required.
  3. It allows greater multiprogramming levels by using less of the available (primary) memory for each process.

Page Fault Service Time

The time taken to service the page fault is called as page fault service time. The page fault service time includes the time taken to perform all the above six steps.

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

Swapping

  • Swapping 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 main memory. When a process is busy swapping pages in and out then this situation is called thrashing.

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

Thrashing

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

  • At any given time, only few pages of any process are in 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 main memory will be occupied with process’s pages, so that the processor and OS has 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.
  • In the given diagram, initial degree of multi programming upto some extent of point(lamda), the CPU utilization is very high and the system resources are utilized 100%. But if we further increase the degree of multi programming the CPU utilization will drastically fall down and the system will spent more time only in the page replacement and the time taken to complete the execution of the process will increase. This situation in the system is called as thrashing.

Causes of Thrashing

  1. High degree of multiprogramming: If the number of processes keeps on increasing in the memory than number of frames allocated to each process will be decreased. So, less number of frames will be available to each process. Due to this, page fault will occur more frequently and more CPU time will be wasted in just swapping in and out of pages and the utilization will keep on decreasing.
    For example:
    Let free frames = 400
    Case 1: Number of process = 100
    Then, each process will get 4 frames.
    Case 2: Number of process = 400
    Each process will get 1 frame.
    Case 2 is a condition of thrashing, as the number of processes are increased, frames per process are decreased. Hence CPU time will be consumed in just swapping pages.
  2. Lacks of Frames: If a process has less number of frames then less pages of that process will be able to reside in memory and hence more frequent swapping in and out will be required. This may lead to thrashing. Hence sufficient amount of frames must be allocated to each process in order to prevent thrashing.

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 in thrashing then instruct the mid term schedular to suspend some of the processes so that we can recover the system from thrashing.
The document Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Virtual Memory (Overview) - Operating System - Computer Science Engineering (CSE)

1. What is virtual memory in an operating system?
Ans. Virtual memory is a memory management technique used by operating systems to provide the illusion of having more memory than is physically available. It allows the operating system to use a combination of physical memory (RAM) and disk storage to store and retrieve data, thereby increasing the overall system performance.
2. What is swapping in the context of virtual memory?
Ans. Swapping is a technique used by the operating system to transfer data between the main memory (RAM) and the disk storage. When the available physical memory is insufficient to hold all the processes in execution, the operating system will swap out some processes from the RAM to the disk, freeing up space for other processes.
3. What is thrashing in the context of virtual memory?
Ans. Thrashing refers to a phenomenon where the system spends a significant amount of time and resources swapping data between the main memory and the disk, instead of executing actual instructions. It occurs when the system is overloaded with too many processes, causing excessive paging activity and degrading the overall system performance.
4. How does virtual memory improve system performance?
Ans. Virtual memory improves system performance by allowing the operating system to utilize the disk storage as an extension of the physical memory. It enables the system to run more processes simultaneously, even if the physical memory is limited. By swapping out less frequently used processes to the disk, it frees up memory for other processes and reduces the chances of running out of memory altogether.
5. What are some advantages of using virtual memory in an operating system?
Ans. Some advantages of using virtual memory are: - Increased overall system performance by utilizing disk storage as an extension of physical memory. - Ability to run more processes simultaneously, even with limited physical memory. - Simplified memory management for programmers, as they can write code assuming a larger memory space. - Enhanced system stability, as virtual memory protects processes from interfering with each other's memory. - Facilitates efficient sharing and protection of memory resources among multiple processes.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Summary

,

mock tests for examination

,

Free

,

Exam

,

ppt

,

Sample Paper

,

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

,

study material

,

Viva Questions

,

Important questions

,

pdf

,

video lectures

,

practice quizzes

,

Objective type Questions

,

past year papers

,

Previous Year Questions with Solutions

,

Extra Questions

,

Semester Notes

,

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

,

Virtual Memory (Overview) | Operating System - Computer Science Engineering (CSE)

,

MCQs

,

shortcuts and tricks

;