Operating System Design/Swapping
Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium term scheduler.Medium term scheduler removes process from CPU for duration and reduce the degree of multiprogramming. And after some time these process can again be reintroduced into main memory. Process execution will again be resumed from the point it left CPU. This scheme is called swapping. More generally we can say swapping is removing of process from memory to secondary memory and again back to main memory.
Example: Assume a multiprogramming environment with Round-Robin CPU scheduling algorithm. When a quantum expires memory manager will start to swap out the process that just finished, and swap in another price to the memory space that has been freed. In the meantime, CPU scheduler will allocate a time slice to some other process in memory. when each process finishes its quantum it will be swapped back with another process. Ideally, memory manager can swap process fast enough so that there are always process in memory, ready to execute, when CPU scheduler wants to reschedule the CPU. The quantum must also be sufficiently large that reasonable amounts of computing are done between swaps.
Swapping can be implemented in various ways. For example, swapping can be priority based. That means if a higher priority process arrives and wants service, the memory manager can swap out the lower priority process to the secondary memory so that it higher priority process can be loaded to main memory for execution. As soon higher priority process finishes, the lower priority process will swapped back to main memory and execution will be continued. Sometimes swapping is also called roll out, roll in.
Address binding rules over the memory space to be allocated to process. Because process that has been swapped out need to be swapped in on same memory location from where it let off. And address binding implements it.
Swapping requires a backing store. And this backing restore is as fast as disk. This backing store should be large enough to maintain copies of all memory images for all users. Swapping also means copying some data from one memory to another