A process needs to be in the memory to be executed.
A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution
Total physical memory space of processes can exceed physical memory
Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Operating system 33 swapping
1. Operating System 33
Swapping
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2. Swapping
• A process needs to be in the memory to be
executed.
• A process can be swapped temporarily out of
memory to a backing store, and then brought back
into memory for continued execution
• Total physical memory space of processes can
exceed physical memory
• Backing store – fast disk large enough to
accommodate copies of all memory images for all
users; must provide direct access to these memory
images
3. Swapping
• Roll out, roll in – swapping variant used for
priority-based scheduling algorithms; lower-
priority process is swapped out so higher-
priority process can be loaded and executed
• Major part of swap time is transfer time; total
transfer time is directly proportional to the
amount of memory swapped
• System maintains a ready queue of ready-to-
run processes which have memory images on
disk
4. Swapping (Cont.)
• Does the swapped out process need to
swap back in to same physical addresses?
• Depends on address binding method
– Plus consider pending I/O to / from process
memory space
• Modified versions of swapping are found
on many systems (i.e., UNIX, Linux, and
Windows)
– Swapping normally disabled
– Started if more than threshold amount of
memory allocated
– Disabled again once memory demand reduced
below threshold
6. Context Switch Time including Swapping
• If next processes to be put on CPU is not in memory,
need to swap out a process and swap in target process
• Context switch time can then be very high
• 100MB process swapping to hard disk with transfer rate
of 50MB/sec
– Swap out time of 2000 ms
– Plus swap in of same sized process
– Total context switch swapping component time of 4000ms
(4 seconds)
• Can reduce if reduce size of memory swapped – by
knowing how much memory really being used
– System calls to inform OS of memory use via
request_memory() and release_memory()
7. Context Switch Time and Swapping (Cont.)
• Other constraints as well on swapping
– Pending I/O – can’t swap out as I/O would
occur to wrong process
– Or always transfer I/O to kernel space, then
to I/O device
• Known as double buffering, adds overhead
• Standard swapping not used in modern
operating systems
– But modified version common
• Swap only when free memory extremely low
8. Binding to physical memory
• Normally, a process that is swapped out will be
swapped back into the same memory space that it
occupied previously.
• This restriction is dictated by the method of address
binding.
• If binding is done at assembly time or load time, then
the process cannot be moved to different locations.
• If execution-time binding is being used, then it is
possible to swap a process into a different memory
space, because physical addresses are computed
during execution time
9. Swapping Considerations
• If we want to swap a process, we must be sure that it is completely
idle.
• Of particular concern is any pending I/O. If a process is waiting for
an I/O operation, we may want to swap that process to free up its
memory.
• However, if the I/O is asynchronously accessing the user memory
for I/O buffers, then the process cannot be swapped.
• Assume the I/O operation was queued because the device was
busy. Then, if were to swap out process P1 and swap in process P2,
the I/O operation might attempt to use memory that now belongs
to process P1.
• The two main solutions to this problem are
– (1) never to swap a process with pending I/O, or
– (2) to execute I/O operations only into operating system buffers.
10. Swapping on Mobile Systems
• Not typically supported
– Flash memory based
• Small amount of space
• Limited number of write cycles
• Poor throughput between flash memory and CPU on mobile
platform
• Instead use other methods to free memory if low
– iOS asks apps to voluntarily relinquish allocated
memory
• Read-only data thrown out and reloaded from flash if needed
• Failure to free can result in termination
– Android terminates apps if low free memory, but first
writes application state to flash for fast restart
– Both OSes support paging as discussed below