Download presentation
Presentation is loading. Please wait.
1
Module IV Memory Organization
2
Paging Paging method Paging avoids external fragmentation
breaks physical memory into fixed-sized blocks called frames and breaks logical memory into blocks of same size called pages Paging avoids external fragmentation Disadv: Internal Fragmentation When a process is to be executed, its pages are loaded into available memory frames from their source.
3
Paging Hardware Every address by CPU is divided into two parts: page number (p) & page offset (d). Page number is an index to page table Page table contains base address of the page This base address is combined with page offset to get physical address
4
Paging Hardware
5
Paging Model
6
Demand Paging To load an executable program from disk into memory
Option 1: load entire program at execution time. But for a program with options, it is inefficient Option 2: load pages only as they are needed and is known as demand paging
7
Demand Paging A pager swaps a page into memory when a page is needed
Pager find whether the page is in memory or disk by valid–invalid bit. When this bit is set to “valid,” the page is legal and is in memory. If it is set to “invalid,” the page either is not valid ( not in logical address space of process) or is valid but is in the disk.
8
Demand Paging Page-table entry is brought into memory for each process
Page-table entry for a page that is not currently in memory is either marked invalid or contains the address of the page on disk. Access to a page that is not in memory causes page fault invoking a trap to OS.
9
Demand Paging Paging allows multiprogramming
It lead to over-allocation of memory When no free frames are available, a page replacement algorithm is applied
10
Page Fault Service Routine
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 victim frame to disk & update page & frame table. 3. Read the desired page into the newly freed frame; change the page and frame tables. 4. Restart the user process.
11
Basic Page Replacement
12
Page Replacement Algorithms
Many algorithms are available One with the lowest page-fault rate is considered as best. They are: FIFO Page Replacement Optimal Page Replacement LRU Page Replacement. LFU Page Replacement
13
FIFO Page Replacement It associates each page with the time it was brought into memory. To replace a page, the oldest one is chosen. Implementation create a FIFO queue to hold all pages. replace the page at the head of the queue Insert the page at the tail of the queue.
14
FIFO Page Replacement Example Consider the reference string :
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 for a memory with three frames.
15
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7
16
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7
17
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1
18
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2
19
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2
20
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3
21
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3
22
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4
23
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4
24
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4
25
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4
26
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
27
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
28
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
29
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
30
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
31
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1
32
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1 7
33
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1 7
34
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1 7
35
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Page Frame Hit -1 7 1 2 3 4 Page Frame Hit 3 2 1 7 Hit Ratio = 5/20 No. of Page Faults = 15
36
FIFO Page Replacement It is easy to understand and program.
Its performance is not always good If initial page contain an initialization module, it works good If it contain a heavily used variable in constant use, the performance degrades.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.