Swapping & Page Replacement

Duration: 24 min

This video lesson is available to enrolled students.

Enroll to watch — ISRO Scientist/Engineer 'SC'

AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This lecture introduces swapping and page replacement in operating systems. Swapping moves a process or its memory pages between RAM and secondary storage to free RAM when memory is under pressure, represented as a bidirectional relationship: RAM ↔ Swap Space. Page replacement occurs when a page fault happens and no free frame is available; the OS must select a page to remove, and the selected page is replaced by the required page. The instructor uses a hand-drawn diagram of memory frames containing pages 1, 2, 3, and 4 to illustrate a page fault requiring a new page (5). The lecture then covers specific page replacement algorithms. FIFO (First-In, First-Out) replaces the page that has been in memory for the longest time and maintains pages in arrival order. It is simple to implement but may suffer from Belady's Anomaly. A worked example uses the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 4 page frames. The instructor marks hits (H) and misses (M) above each reference number and fills a grid to track the state of memory frames over time. The Optimal (OPT) algorithm replaces the page that will not be used for the longest time in the future, producing the minimum possible number of page faults. It is used mainly as a benchmark and cannot be perfectly implemented in practice because future references are unknown. In the worked example, OPT yields a total of 4 page faults (PF=4). The Least Recently Used (LRU) algorithm replaces the page that has not been used for the longest time in the past and is based on past references. The lecture also introduces NRU (Not Recently Used), which uses Reference and Modified bits to classify pages into four classes for replacement, and the Clock/Second Chance algorithm, which improves upon FIFO by giving pages a second chance before replacement (R=0 -> Replace the page). The segment concludes with a comparative table of FIFO, Optimal, LRU, NRU, and Clock algorithms, highlighting their basis and whether they exhibit Belady's Anomaly.

Chapters

  1. 0:00 2:00 00:00-02:00

    The slide titled 'Swapping & Page Replacement' defines the core concepts. Under Swapping, bullets read: 'Swapping moves a process or its memory pages between RAM and secondary storage' and 'Used to free RAM when memory is under pressure,' followed by the relationship 'RAM ↔ Swap Space.' Under Page Replacement, bullets state: 'When a page fault occurs and no free frame is available, the OS must select a page to remove' and 'The selected page is replaced by the required page.' The instructor highlights key terms like RAM and secondary storage, circles 'RAM <-> Swap Space' in red ink to emphasize bidirectional movement, and underlines key terms in the page replacement section.

  2. 2:00 5:00 02:00-05:00

    The instructor introduces a hand-drawn diagram of memory frames containing pages 1, 2, 3, and 4 to illustrate a page fault requiring a new page (5), writing the number '5' with an arrow pointing to a frame. The lecture then introduces the FIFO (First-In, First-Out) page replacement algorithm, explaining that it replaces the page in memory for the longest time and maintains pages in arrival order. Key properties highlighted include 'Simple to implement' and 'May suffer from Belady's Anomaly.' A specific example is presented with a page reference string of 20 numbers and 4 page frames, asking the viewer to calculate the total number of page faults. A grid is provided below the string for tracking the state of memory frames over time.

  3. 5:00 10:00 05:00-10:00

    The instructor demonstrates the FIFO page replacement algorithm using the reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 and 4 physical memory frames. Page hits (H) and misses (M) are annotated above each reference number as the algorithm progresses. The memory frame table is progressively filled to show the state of the FIFO queue after each step. At 455s, the table shows frames containing 7, 0, 1, and 2 after processing the first few references. At 545s, the table shows frames containing 3, 4, 2, and 1 after processing up to the reference '0.' The instructor underlines specific parts of the example text such as 'page reference string' and '4 page frames.'

  4. 10:00 15:00 10:00-15:00

    The video covers the FIFO and Optimal (OPT) page replacement algorithms. It begins by explaining that FIFO replaces the page in memory for the longest time and maintains pages in arrival order, noting it may suffer from Belady's Anomaly. The instructor then transitions to the Optimal (OPT) algorithm, which replaces the page that will not be used for the longest time in the future to produce the minimum possible number of page faults. The OPT algorithm is used mainly as a benchmark and cannot be perfectly implemented in practice because future references are unknown. The instructor begins an OPT worked example with 4 frames, using a grid to track page faults and memory frames step-by-step.

  5. 15:00 20:00 15:00-20:00

    The instructor walks through the Optimal (OPT) algorithm, identifying pages to replace based on future references and calculating a total of 4 page faults (PF=4) written at the bottom of the slide. The topic then shifts to the Least Recently Used (LRU) page replacement algorithm, which replaces the page that has not been used for the longest time in the past and is based on past references. The instructor begins processing the same reference string using LRU, marking hits (H) and misses (M) above the reference string to track faults. Key terms like 'future' for OPT and 'past' for LRU are highlighted to distinguish the algorithms.

  6. 20:00 24:19 20:00-24:19

    The segment introduces NRU (Not Recently Used), which uses Reference and Modified bits to classify pages into four classes for replacement, with on-screen text showing 'R (Reference Bit) = 1' and 'M (Modified Bit) = 0.' The Clock/Second Chance algorithm is introduced as an improved FIFO version, with a visual diagram of the circular/clock structure and the rule 'R=0 -> Replace the page.' The segment concludes with a comparative table of FIFO, Optimal, LRU, NRU, and Clock algorithms, highlighting their basis and whether they exhibit Belady's Anomaly. Important concepts like 'second chance' are underlined and circled.

The lecture progresses from foundational definitions to algorithmic implementations. It starts by defining swapping as the movement of processes or pages between RAM and secondary storage to alleviate memory pressure, and page replacement as the mechanism triggered when a page fault occurs with no free frames available. A hand-drawn diagram of memory frames (pages 1-4) with an incoming page (5) visually grounds the concept. The core of the lecture is a comparative analysis of five page replacement algorithms, each demonstrated with the same 20-number reference string and 4 frames to allow direct comparison. FIFO is presented first as the simplest approach, replacing the oldest page in arrival order, but it is noted to suffer from Belady's Anomaly. The worked example meticulously tracks hits and misses in a grid, showing the frame state evolving from [7,0,1,2] to [3,4,2,1]. OPT is introduced as the theoretical benchmark that minimizes faults by looking ahead into future references; it yields only 4 page faults in the example but is impractical because future references are unknown. LRU mirrors OPT's logic but looks backward at past usage, replacing the least recently used page. NRU and Clock/Second Chance are introduced as practical approximations; NRU uses R and M bits to classify pages, while Clock gives FIFO a 'second chance' by checking the reference bit before replacement. The final comparative table synthesizes these algorithms by their basis (past, future, bits) and susceptibility to Belady's Anomaly. The teaching method relies heavily on step-by-step grid tracking, H/M annotations above the reference string, and red-ink highlighting of key terms to guide student attention through each algorithm's decision logic.

Loading lesson…