Page 180 - DCAP103_Principle of operating system
P. 180
Unit 5: Memory Management
Notes
5.9 Demand Paging
A demand-paging system is similar to a paging system. Processes reside on secondary memory
(which is usually a disk). When we want to execute a process, we swap it into memory. Rather
than swapping the entire process into memory, however, we use a lazy swapper. A lazy swapper
never swaps a page into memory unless that page will be needed. Since we are now viewing a
process as a sequence of pages, rather than as one large contiguous address space, use of swap
is technically incorrect. A swapper manipulates entire processes, whereas a pager is concerned
with the individual pages of a process. We thus use pager, rather than swapper, in connection
with demand paging.
5.9.1 Basic Concepts
When a process is to be swapped in, the pager guesses which pages will be used before the
process is swapped out again. Instead of swapping in a whole process, the pager brings only
those necessary pages into memory. Thus, it avoids reading into memory pages that will not be
used anyway, decreasing the swap time and the amount of physical memory needed.
Figure 5.23: Transfer of a Paged Memory to Contiguous Disk Space
0 1 2 3
Swap out
Program
A
4 5 6 7
8 9 10 11
1 2 13 14 15
Program
B 1 6 17 18 19
Swap in
2 0 21 22 2 3
Main
memory
With this scheme, we need some form of hardware support to distinguish between those pages
that are in memory and those pages that are on the disk. The valid-invalid bit scheme already
described and can be used for this purpose. This time, however, when this bit is set to “valid,”
LOVELY PROFESSIONAL UNIVERSITY 173