Lecture 6 MSCS
Lecture 6 MSCS
2. Load time: It is the time taken to link all related program file
and load into the main memory. It must generate relocatable
code if memory location is not known at compile time.
3. Execution time: It is the time taken to execute the program
in main memory by processor. Binding delayed until run time if
the process can be moved during its execution from one memory
segment to another. Need hardware support for address maps
(e.g., base and limit registers).
Binding of Instructions and Data to Memory
Demand paging
Demand segmentation
DEMAND PAGING
A demand-paging system is similar to a paging system with swapping.
Generally, 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, i swaps the required page. This can
be done by a lazy swapper. A lazy swapper never swaps a page into memory
unless that page will be needed. A swapper manipulates entire processes,
whereas a pager is concerned with the individual pages of a process.
Page transfer Method:
The page replacement is a mechanism that loads a page from disc to memory when a
page of memory needs to be allocated. Page replacement can be described as follows:
1. Find the location of the desired page on the disk.
2. Find a free frame:
a. If there is a free frame, use it.
b. If there is no free frame, use a page-replacement algorithm to select a victim frame.
c. Write the victim page to the disk; change the page and frame tables accordingly.
3. Read the desired page into the (newly) free frame; change the page and frame tables.
4. Restart the user process.
Page Replacement
Algorithms:
The page replacement algorithms decide which
memory pages to page out (swap out, write to disk) when a page of
memory needs to be allocated. We evaluate an algorithm by running it
on a particular string of memory references and computing the number
of page faults. The string of memory references is called a reference
string.
The different page replacement algorithms are described as follows:
1. First-In-First-Out (FIFO) Algorithm:
A FIFO replacement algorithm associates with each page the time when
that page was brought into memory. When a page must be replaced, the
oldest page is chosen to swap out. We can create a FIFO queue to hold
all pages in memory. We replace the page at the head of the queue.
When a page is brought into memory, we insert it at the tail of the queue
Example
Optimal Page Replacement algorithm: