Open In App

Lazy Swapping in Operating System

Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisites: Swapping in Operating System

Lazy swapping, also known as demand paging, is a memory management technique used in operating systems to allow programs to access more memory than is physically available in the system. Increasing the degree of multi-programming of the system means increasing the number of processes loaded into the RAM (Random Access Memory). The concept of virtual memory comes into the picture. 

In the system that used the lazy swapping technique, the whole process program is not loaded into the RAM but only the portion of a program is loaded. One part of the program is loaded into the RAM. when that portion is needed when the loaded program tries to access the data which is currently not loaded into the RAM. Because of it, the memory requirement is less than the whole program and so other processes can be loaded into the RAM and can run simultaneously, even total memory requirements of all program is greater than the physical memory available in the system. The operating system manages the swapping of data in and out of the memory as needed so that the user does not experience a delay in the process.

However, lazy swapping can result in slower program execution times due to the time, because of time taken by swapping to swap data in and out of memory. If the demand for memory is greater than the amount available, the system may need to use a portion of the hard drive as virtual memory, then further program execution will slow down.

Lazy Swapping

 

In the above diagram, Process 1 has pages P11, P12 on the RAM, and, Process 2 has pages P21, and P22. If page P12 is not required further to execute Process 1 then it is swapped out from RAM. Similarly for Process 2, if it needs a Page P21 then and then only that page will be loaded into the RAM.

In conclusion, Lazy Swapping is a technique used in Operating Systems to manage virtual memory and improve system performance. It does not load the pages to the swap file until it is necessary and reduces the number of disk I/O operations required. Lazy Swapping can help the system to not run out of physical memory and it maintains good performance of the system.


Last Updated : 07 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads