Swapping & Page Replacement

Duration: 24 min

This video lesson is available to enrolled students.

Return to /learn/UPPSC-POLYTECHNIC-LECTURER-2025-CS/paper-2-operating-systems/linux-os/memory-management/asset-swapping-page-replacement after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. About Course: UPPSC Course Overview
  2. Interview Preparation & Guidance: Interview Preparation
  3. Paper 1 | General Hindi: भाषा, लिपि, ध्वनि, वर्ण, अक्षर, स्वर, व्यंजन, मात्रा और संयुक्ताक्षर, वर्तनी, वर्ण-विन्यास, अनुस्वार, अनुनासिक, चंद्रबिंदु और ‘र’ के रूप, शब्द, पद और शब्द-भेद, संज्ञा और सर्वनाम, विशेषण और क्रिया, लिंग, वचन, पुरुष और कारक, काल, वाच्य, वाक्य और वाक्य-भेद, वर्णमाला, समास, संधि, विलोम शब्द, पर्यायवाची शब्द, सामान्य अशुद्धियाँ, अनेक शब्दों के लिए एक शब्द, मुहावरे और लोकोक्तियाँ, अपठित गद्यांश और अपठित पद्यांश, Multi-Topic Content (Cross-Concept Material)
  4. Paper 2 | General Studies: State Wise GK, Polity, Geography, History, GK- Current Affairs
  5. Paper 1 | Programming Language: Language Design, C Fundamentals, Control Flow, Functions, Arrays & Pointers, Storage Classes, Structures & Enums, DMA, Macros, Scoping & File Handling, OOPS with C++
  6. Paper 1 | Database Management Systems: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, SQL, Relational Calculus, Transaction Management, Concurrency Control, ORDBMS, NoSQL
  7. Paper 1 | Cyber Security: Society, Law & Ethics, Cyber Threats and Malware Attacks, Role of Internet and Web Services, Security in Mobile and Wireless Computing, Electronic Data Interchange and E-Commerce, Physical Security and Cryptography Basics, Intrusion Detection Systems (IDS), Cyber Safety and Security, Ethical Hacking
  8. Paper 1 | Computer Organization and Architecture: Basics of COA, Programming the Basic Computer, Cache Memory Organization, Input Output Organisation, Instr Formats & Modes, Register Transfer and Microoperations, Control Unit Design
  9. Paper 1 | Computer Networks: Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics, Network Security
  10. Paper 1 | Design and Analysis of Algorithms: Algorithm Analysis, Time Complexity Analysis, Sorting Algorithms, Greedy Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos, Advanced Algorithms
  11. Paper 1 | Data Structures: Introduction to DS, Array, Linked List, Stack, Queue, Tree, Graphs, Hashing
  12. Paper 1 | Discrete Structures and Theory of Logic: Permutation and Combination, Set Theory, Relations, Functions, Propositional and Predicate Logic, Graph Theory, Group Theory
  13. Paper 1 | Software Project Management: Software Project Management
  14. Paper 2 | Operating Systems: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management, Unix OS, Linux OS, Security
  15. Paper 2 | Compiler Design: Intro to Compilers, Lexical Analysis, Grammar & CFG, Syntax Analysis: Top-Down, Syntax Analysis: Bottom-Up, Semantic Analysis & SDT, Intermediate Code Gen, Code Optimization, Run Time Environment, Introduction to TOC, Deterministic FA (DFA), Non-Deterministic FA, Regular Expressions, Pushdown Automata & CFG, Complexity Theory
  16. Paper 2 | Artificial Intelligence & High Performance Computing: Approaches to AI, Search Algorithms, Game Playing, Knowledge Representation, Planning, Multi Agent Systems, Natural Language Processing, Emerging Tech Trends
  17. Paper 2 | Image Processing: Digital Image Fundamentals, Image Enhancement, Image Restoration, Color Image Processing, Image Compression
  18. Paper 2 | Software Engineering: Fundamentals of Software Engineering, Software Requirements and Quality Assurance, Software Design, Estimation and Metrics, Software Testing, Software Maintenance and Configuration Management
  19. Paper 2 | Computer Graphics: Basics of Computer Graphics, 2-D Geometrical Transforms and Viewing, 3-D Object Representation, Geometric Transformations and Viewing
  20. Paper 2 | Web Technologies: Website, Browser & Services, Internet Fundamentals, Web Design & Development, Protocols & Services, Web Publishing & Hosting, Server Side & Security, Emerging Technologies, HTML Basics, JavaScript-Basics, Java
  21. Paper 2 | Soft Computing: Fuzzy Sets, Artificial Neural Networks, Genetic Algorithms
  22. Paper 2 | Distributed System: Distributed Systems
  23. UPPSC Live Class Recordings: UPPSC Polytechnic Lecturer 2025 (CS)
  24. Previous Year Papers:
  25. Mock Test:
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…