0% found this document useful (0 votes)
51 views18 pages

Swapping: Unix OS by Deepak Mangal

The document discusses the process of swapping in Unix operating systems. It describes three parts of the swapping algorithm: managing space in the swap device, swapping processes out of main memory, and swapping processes back into main memory. The kernel allocates space on the swap device in blocks, tracks available space in a map, and uses an algorithm to allocate and free resources. When swapping a process out, it decrements reference counts and saves swap addresses, and when swapping back in it can reassign the process to its correct virtual addresses.

Uploaded by

fcaga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views18 pages

Swapping: Unix OS by Deepak Mangal

The document discusses the process of swapping in Unix operating systems. It describes three parts of the swapping algorithm: managing space in the swap device, swapping processes out of main memory, and swapping processes back into main memory. The kernel allocates space on the swap device in blocks, tracks available space in a map, and uses an algorithm to allocate and free resources. When swapping a process out, it decrements reference counts and saves swap addresses, and when swapping back in it can reassign the process to its correct virtual addresses.

Uploaded by

fcaga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Swapping

Unix OS
By Deepak Mangal

Memory Management
polices
CPU can not execute a process that exists
entirely in secondary memory, at least a part
of program must be in primary memory.
The memory mgmt. system will decide which
program reside in main memory.
It monitor the amount of memory available
in main memory and periodically write
processes in secondary memory device
called swap device.
At a later time, kernel read data from swap
device back to main memory.

Three Parts of Swapping


Algorithm
Managing Space in the Swap Device
Swapping process out of Main
Memory
Swapping process in Main Memory

Managing Space in the


Swap Device
Swap Device is a Block Device
(Section on a Disk)
The Kernel Allocates space on the
swap device in group of contiguous
blocks.
A process that reside on the swap
device will eventually migrate back
to main memory, freeing space it had
occupied in the swap device.

In-core table Map


The kernel maintain the free space for the
swap device in a in-core table map.
A map is an array where each entry consist
of an address of an allocatable resource and
the number of units available there.
The kernel allocate free resource and
update the map to have the accurate
information.
Kernel uses malloc algorithm for allocating
free space.

Intially
Address :1
Units:10000
100 units allocated
Address :101
Units:9900
50 units allocated
Address:151
Units:9850

Freeing the Resources


When freeing the resources, the kernel finds
their proper position in the map by address.
Three cases are possible:
The freed resource
1.completely fill a hole in the map, contiguous
both side.
2. Partially fills a hole in the map, contiguous
either side.
3. Partially fills a hole in the map, but not
contiguous to any resource in the map.

Swapping Process out


Kernel Steps
When kernel decides which process
swap out from MM, then
It decrements the reference count of
each region.
Swap the region out if its reference
count drops to zero.
It also saves the swap address of the
region in the region table entry.

Kernel steps
It is not necessary that the kernel
write the entire virtual address space
of a process to a swap device.
When the kernel swaps the process
back, it knows virtual address map of
the process, so it can reassign the
process to the correct virtual
address.

You might also like