Lab 03: Page tables & Swapping
Find a file
2025-12-17 12:08:10 +00:00
src add lab 3 content 2025-12-17 20:05:12 +08:00
.gitignore Initial commit 2025-12-17 10:58:04 +00:00
LICENSE Initial commit 2025-12-17 10:58:04 +00:00
README.md Update README.md 2025-12-17 12:08:10 +00:00

Lab 03: Page tables & Swapping

Operating Systems Lab Exercise

Duration: 90 minutes

Language: Java

Testing: JUnit 5

Learning Objectives

By completing this lab, you will be able to:

  • Address Slicing: Extract bit-segments from a 32-bit binary string to simulate CPU decoding.
  • Architecture Comparison: Implement and test Two-Level, Hashed, and Inverted Page Tables.
  • Swapping Policy: Simulate an OS policy to swap "victim" pages out to disk when RAM is full.
  • Fault Injection: Debug logical flaws in memory isolation and resource accounting.

Project Setup (10 Minutes)

Clone the repository

git clone https://forgejo.skynet.ie/andrew/cs4023-lab-03.git

Open in IntelliJ IDEA

Ensure JUnit 5 is configured in the project

You should find two files in your project structure:

  • AdvancedMemoryManager.java (Main logic code).
  • AdvancedMemoryTest.java (Unit test code).

Part A: Understand different page tables (35 Minutes)

In this section, you will focus only on how different page table works.

Task A.1: Two-level page table

Open AdvancedMemoryManager.java in the project.

Your initial focus is on the translateTwoLevel method for 2 level page table translation.

I have provided code with ** intentional bugs**. You must run the first 3 Unit Tests provided below, identify which tests fail, and fix the translateTwoLevel method.

  • Examine the logic used to get the outerBits, innerBits, and offsetBits. Find and fix the bug.

Locate the test_TwoLevel... methods in AdvancedMemoryTest.java. These tests verify the math behind the translation.

  1. Run all 3 unit tests in AdvancedMemoryTest.java with prefix test_TwoLevel....
  2. Expected Outcome: The tests prefixed with testDecomposition... should all PASS.

Task A.2: Inverted page table

We will be still looking into AdvancedMemoryManager.java in the project.

Your focus here is on the translateInverted method for inverted page table translation.

I have provided code with ** intentional bugs**. You must run the test_InvertedSecurityIsolation Unit Test provided below, check whether the test pass or fail, and fix the translateInverted method.

  • Examine the logic: does the code verify the PID, or just the Page Number? Find and fix the bug.

Locate the test_InvertedSecurityIsolation method in AdvancedMemoryTest.java. Theis test verifies the logic behind the translation.

  1. Run the test.
  2. Expected Outcome: The test should PASS.

Part B: Swapping & Bug Hunting (35 Minutes)

You will simulate a system with only 2 Physical Frames. When a 3rd page is requested, you must perform a Swap.

Task B.1: The "Bug Hunt"

I have provided code with intentional bugs. You must run the test_Swapping... methods provided below, identify which tests fail, and fix the AdvancedMemoryManager.java file.

You might want to check the accessWithSwapping method, Is framesOccupied correctly updated during a swap-out?

After fix the bug, re-run the tests, and they should all pass.


Task B.2: Checkpoint Questions (10 Minutes)

  1. Architecture: Why does the Inverted Page Table help save memory on systems running hundreds of processes?

  2. Logic: In your swapping simulation, which page was chosen as the "victim"? Is this a fair policy (FIFO)?

  3. Security: Why is the PID check in translateInverted essential for system stability?

  4. That's all for today's and also the final lab of my teaching here, well done everybody!