Allocating Swap Space
16
1 10000 101 9900
151 9750251 9850
Allocate 100 unit
Allocate 100 unit
Allocate 50 unit
Map
AddressUnit
Freeing Swap Space
17
251 9750
50 unit free at 101
Map
Address Unit
101 50
251 9750
Case 1: Free resources fill a hole,
but not contiguous to any resources in the map
Freeing Swap Space
18
251 9750
50 unit free at 101
Map
Address Unit
101 50
251 9750
100 unit free at 1
1 150
251 9750
Case 2: Free resources fill a hole,
and immediately precedes an entry in the map
19
Freeing Swap Space
251 9750
50 unit free at 101
Allocate 200 unit
Map
AddressUnit
101 50
251 9750
100 unit free at 1
1 150
251 9750
1 150
451 9550
1 10000
300 unit free at 151
Case 3: Free resources fill a
hole, and completely fills the
gap between entries in the
map
Page frame data table
•The page frame data table holds information about each
physical frame of memory (indexed by frame number).
•This table is of primary importance for the replacement
algorithm.
Page State Reference
Count
Logical
device
Block
number
Pf data
pointer
25
•Page state indicates whether or not the frame is available or
has an associated page (i.e. whether its been allocated to a
process or not).
•Ref. Count holds the number of processes that refer to this
page (remember, processes can share the same physical
page).
•Logical device contains the device number of the disk that
holds a physical copy of the page.
26
•Block # holds the block number on that disk where the
page data is located.
•Pfdata pointeris a pointer field that is used to thread a
singly-linked list of free frames through the frame table. If
the page is free, this points to the next free page (useful for
free list-style allocation).
27
Swap use table
•Reference Count: Number of page table entries that point
to a page on the swap device.
•Page/storage unit number : Page identifier on storage unit
28
Reference
count
Page/storage
unit number
Page Replacement Algorithm
•The Page frame data table is used for page replacement.
•All of the available frames are linked together in a list of free
frames available for bringing in pages.
•The two-handed clock algorithm uses the reference bit in the
page table entry for each page in memory that is eligible
(not locked) to be swapped out.
•This bit is set to 0 when when the page is first brought in and
set to 1 when the page is refernced for a read or write .
29
•The parameter varies linearly between the values slowscan
and fastscan as the amount of free memory varies between
the values lotsfree and minfree.
•The handspread parameter determines the gap between the
fronthand and the backhand and therefore, together with
scanrate,determines the window of oppurtunity to use a
page before it is swapped out due to lack of use.
32
34
Advantages
•easy to implement
•not restricted to memory allocation
•no wastage of space
•can release any part of the region
•allows reuse of memory by coalescing
References
Books :
*********
1. Os Internals & design
---William Stallings
2.The design of the unix operating system
---Maurice J. Bach prentice hall
35