Bird
Raised Fist0
Interview Prepoperating-systemsmediumGoogleAmazonFlipkartCRED

Paging vs Segmentation - Address Translation

Choose your preparation mode3 modes available
▶
Steps
setup

Initialize Segment Table and Page Table

The system initializes the segment table and page table with predefined entries for segment 1 and its pages.

💡 Setting up tables is essential because address translation depends on these mappings from virtual to physical memory.
Line:segment_table = {1: {'base': 0x1000, 'limit': 0x2000, 'page_table': {0: 0x10, 1: 0x11}}}
💡 The segment table entry for segment 1 points to a base physical address and a page table mapping virtual pages to physical frames.
📊
Paging vs Segmentation - Address Translation - Watch the Algorithm Execute, Step by Step
Watching each step of address translation helps you understand how virtual memory maps to physical memory, clarifying the roles of segments and pages without needing to read dense code.
Step 1/10
·Active fill★Answer cell
Transition new → ready pid:1 - Initialization complete
1
ready
burst: 10
Ready Queue
1
Waiting Queue
empty
🖥CPUidlet=0
Transition ready → running pid:1 - Process scheduled
1
running
burst: 10
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=1
1
Transition running → running pid:1 - Segment table lookup
1
running
burst: 9
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=2
1
Transition running → running pid:1 - Offset validation
1
running
burst: 8
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=3
1
Transition running → running pid:1 - Calculate page number and offset
1
running
burst: 7
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=4
1
Transition running → running pid:1 - Page table lookup
1
running
burst: 6
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=5
1
Transition running → running pid:1 - Calculate physical address
1
running
burst: 5
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=6
1
Transition running → running pid:1 - Page fault check
1
running
burst: 4
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=7
1
Transition running → terminated pid:1 - Translation complete
1
terminated
burst: 0
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=8
1
Transition terminated → idle - No active processes
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=9
1
idle

Key Takeaways

✓ Address translation combines segmentation and paging by first validating the segment and then mapping pages within it.

This layered approach is hard to grasp from code alone but becomes clear when you see each lookup and calculation step.

✓ Offset validation against segment limit prevents illegal memory access, a critical safety check.

Visualizing this check shows why segmentation protects memory boundaries.

✓ Page faults are detected during page table lookup, showing when the system must load pages from disk.

Seeing the decision point for page faults clarifies how virtual memory handles missing pages.

Practice

(1/5)
1. Which component is primarily responsible for saving and restoring CPU registers during a context switch?
easy
A. The Interrupt Handler
B. The CPU scheduler
C. The Memory Management Unit (MMU)
D. The Process Control Block (PCB)

Solution

  1. Step 1: Understand the role of PCB

    The PCB stores the CPU register states and other process information needed to resume execution later.
  2. Step 2: Differentiate from scheduler and interrupt handler

    The scheduler decides which process runs next but does not save registers; the interrupt handler triggers context switches but does not save registers itself.
  3. Step 3: MMU role

    The MMU handles memory address translation, unrelated to register saving.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    PCB contains saved CPU state -> correct component for saving/restoring registers.
Hint: PCB = process snapshot including CPU registers [OK]
Common Mistakes:
  • Confusing scheduler with register saving
  • Assuming interrupt handler saves registers
  • Thinking MMU handles CPU state
2. Which of the following statements best explains why eliminating the 'No Preemption' condition is often impractical in operating systems?
medium
A. Preemption increases the chance of circular wait conditions.
B. Preemption always leads to starvation of some processes.
C. Preempting resources can cause inconsistent states and data corruption if not handled carefully.
D. Preemption is unnecessary because hold and wait can be eliminated instead.

Solution

  1. Step 1: Understand 'No Preemption'

    This condition means resources cannot be forcibly taken from a process.
  2. Step 2: Analyze why preemption is hard

    Preempting resources like CPU or I/O devices can cause inconsistent states or data corruption if the process is interrupted mid-operation.
  3. Step 3: Evaluate other options

    Preemption always leads to starvation of some processes is incorrect because preemption does not always cause starvation; proper scheduling can prevent it. Preemption increases the chance of circular wait conditions is false; preemption reduces circular wait. Preemption is unnecessary because hold and wait can be eliminated instead is misleading; eliminating hold and wait is difficult and does not negate the challenges of preemption.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Preemption risks inconsistent states, making it impractical in many cases.
Hint: No preemption exists because forcibly taking resources risks corruption [OK]
Common Mistakes:
  • Believing preemption always causes starvation
  • Confusing preemption effects with circular wait
  • Assuming eliminating hold and wait removes need for preemption
3. Which of the following statements best describes a limitation of the buddy system in managing memory fragmentation?
medium
A. It can cause significant internal fragmentation due to rounding up allocation sizes to powers of two
B. It completely eliminates external fragmentation by merging all free blocks
C. It requires compaction to handle fragmentation effectively
D. It is inefficient for fixed-size memory allocation requests

Solution

  1. Step 1: Analyze buddy system behavior

    Buddy system allocates blocks in powers of two, causing internal fragmentation when requested size is not a power of two.
  2. Step 2: Evaluate other options

    It does not eliminate external fragmentation completely (B); compaction is a separate technique (C); it is efficient for fixed-size allocations (D is incorrect).
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Internal fragmentation is a known trade-off in buddy system [OK]
Hint: Buddy system = power-of-two blocks -> internal fragmentation [OK]
Common Mistakes:
  • Believing buddy system removes all external fragmentation
  • Confusing compaction as part of buddy system
  • Assuming buddy system is inefficient for variable sizes
4. In a system with multiple CPUs (multi-core), how does context switching overhead differ compared to a single-core system, and what additional factors must be considered?
hard
A. Context switching overhead per CPU remains the same, but inter-CPU cache coherence and synchronization add extra overhead
B. Context switching overhead is eliminated because each CPU runs its own process independently
C. Context switching overhead doubles because each CPU must save and restore registers twice
D. Context switching overhead is reduced because the scheduler can switch processes faster across CPUs

Solution

  1. Step 1: Per-CPU context switch cost

    Each CPU still saves/restores registers during context switches, so overhead per CPU is similar to single-core.
  2. Step 2: Additional multi-core factors

    Multi-core systems require cache coherence protocols and synchronization mechanisms, adding overhead beyond single-core context switching.
  3. Step 3: Misconceptions

    Context switching is not eliminated; CPUs do not save/restore registers twice per switch; scheduler speedup is not guaranteed.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Multi-core adds complexity beyond per-CPU context switch overhead.
Hint: Multi-core = same per-CPU cost + extra sync overhead [OK]
Common Mistakes:
  • Thinking multi-core removes context switch overhead
  • Assuming overhead doubles incorrectly
  • Believing scheduler is always faster on multi-core
5. If a process in the Waiting state is waiting for multiple I/O events simultaneously, how does the five-state model handle this scenario, and what is a key limitation of the model in this context?
hard
A. The process moves to Ready state after the first I/O event completes, ignoring others, which can cause errors
B. The process remains in Waiting until all I/O events complete; the model does not distinguish multiple waits, limiting concurrency handling
C. The process splits into multiple processes for each I/O event, which the model explicitly supports
D. The process moves to Running state and polls each I/O event, which the model assumes

Solution

  1. Step 1: Understand Waiting state semantics

    Waiting means blocked until the awaited event(s) complete.
  2. Step 2: Multiple I/O waits in five-state model

    The model treats Waiting as a single state without differentiating multiple simultaneous waits.
  3. Step 3: Limitation

    This means the process stays in Waiting until all I/O events complete, limiting fine-grained concurrency.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Five-state model does not handle multiple simultaneous waits distinctly [OK]
Hint: Waiting state is a single block; multiple waits are not distinguished [OK]
Common Mistakes:
  • Assuming process moves to Ready after any I/O completes
  • Believing process can split into multiple processes automatically
  • Thinking process polls I/O events while Running
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard