Swapping, Swap in, Swap out in Operating Systems (OS)
Swapping, Swap in, Swap out in Operating Systems (OS)
In this tutorial, we will learn about the followings;
What is Swapping? What is Swap in? What is Swap out in Operating Systems (OS)?
As we know that hard disk is very cheap in price as compared to RAM (main memory), so it is economical for us to buy a big hard disk with a data storage capacity of GB’s and TB’s. But we need to know that the purpose of RAM and Hard disk is a little bit different. RAM stores temporary data and hard disk stores permanent data.
Further today we are living in the age of multiprogramming and multi-processing, and we have a very strong CPU, so we know to program our Operating system in such a way that OS can manage multiple programs running at the same time. But when we try to execute multiple programs on CPU with a little RAM, the OS needs a mechanism for swapping the processes. Now let’s see what is swapping.
What is Swapping?
When our main memory(RAM) is not enough to temporarily store multiple programs then we take some program from RAM and store them into the hard disk by a mechanism called swap out. Similarly when RAM is free, then we again swap in the programs from hard disk to RAM.
What is Swap out and swap in?
Swap out means to take the program from RAM and to bring them in Hard disk. Swap in means to take the program from Hard disk and again bring them to the RAM.
What are the advantages of swapping?
- With the help of swapping we can manage many processes within the same RAM.
- Swapping helps to create virtual memory.
- Swapping is economical.
How much amount of swap space is used by Solaris and Linux?
OS | Swap Space |
Linux | Swap space is double the amount of physical memory |
Solaris | Swap space is equal to the amount of the physical memory |
Question : Consider a swapping system in which memory consists of the following hole sizes in memory and in order of 16K, 14K, 4K, 20K, 18K, 7K, 9K, 12K, and 15K.
Which memory hole is taken for successive segment requests of (a) 12K (b) 10K (c) 9K for first fit, best fit, worst fit, and next fit.
Solution:
First Fit
12k segment will reside memory hole of 16k.
10k segment will reside memory hole of 14k.
9k segment will reside memory hole of 20k.
Best Fit
12k segment will reside memory hole of 12k.
10k segment will reside memory hole of 14k.
9k segment will reside memory hole of 9 .
Worst Fit
12k segment will reside memory hole of 20k.
10k segment will reside memory hole of 18k.
9k segment will reside memory hole of 15k.
Next Fit
12k segment will reside memory hole of 16k.
10k segment will reside memory hole of 14k.
9k segment will reside memory hole of 20k.
Frequently Asked Questions (FAQ)
What is the term for the process of swapping items between memory and storage?
Swapping items between memory and storage is called Paging.
In unix, swapping uses a round robin memory-management policy.
True/False
Answer :True
Swapping is typically not supported on mobile platforms.
True/False
Answer :True
How to disable the swapping in OS?
We can use the command “swapoff -a” to disable the swapping in operating systems.
MCQs on swapping