The third access resumes and checks the TLB again, this time finding the translation (TLB hit).
💡 A hit means the translation is found quickly, avoiding page table lookup delay.
Line:if page_number in tlb:
tlb_hit = True
💡 TLB hits drastically reduce access time.
traverse
Complete Third Access Translation
The third access completes translation and terminates, ending the simulation of all memory accesses.
💡 Completing the last access concludes the simulation.
Line:process.state = 'terminated'
💡 All accesses have been processed sequentially with TLB hits and misses.
reconstruct
Calculate Effective Access Time
Calculate the effective access time using the formula: EAT = (hit ratio * TLB access time) + (miss ratio * (TLB access time + page table access time + memory access time)).
💡 This calculation summarizes the overall performance impact of TLB hits and misses.
💡 Effective access time quantifies the average memory access delay considering TLB behavior.
tlb = {}
memory_accesses = [0x1A3, 0x1A4, 0x2B7]
tlb_time = 1 # TLB access time
page_table_time = 100 # Page table access time
memory_time = 1 # Memory access time
current_time = 0
# STEP 1: Initialize simulation
for i, address in enumerate(memory_accesses):
pid = i + 1
# STEP 2: Start translation
page_number = address >> 4 # example page number extraction
if page_number not in tlb:
# STEP 3: TLB miss
# STEP 4: Wait for page table lookup
current_time += page_table_time
# STEP 5: Update TLB
tlb[page_number] = 'frame'
# STEP 6: TLB hit
current_time += tlb_time + memory_time
# STEP 7: Complete translation
# STEP 17: Calculate Effective Access Time
hit_ratio = 2/3
miss_ratio = 1/3
EAT = hit_ratio * tlb_time + miss_ratio * (tlb_time + page_table_time + memory_time)
📊
TLB - Translation Lookaside Buffer & Effective Access Time - Watch the Algorithm Execute, Step by Step
Watching each step reveals how the TLB cache speeds up address translation and how misses affect performance, which is difficult to grasp from code alone.
Transitionterminated → terminated - calculated effective access time
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=213
idle
Key Takeaways
✓ TLB hits significantly reduce memory access time by avoiding slow page table lookups.
This speedup is hard to see from code alone because it depends on runtime cache state and hit/miss patterns.
✓ TLB misses cause the process to wait for page table lookup, which adds substantial delay.
Visualizing the waiting state clarifies why misses are costly.
✓ The effective access time formula combines hit ratio and miss penalty to quantify average performance.
Seeing the formula applied after the simulation connects theory to practice.
Practice
(1/5)
1. Trace the sequence of events when a user program invokes a system call to read a file. Which step happens immediately after the CPU switches to kernel mode?
easy
A. The kernel verifies the system call number and arguments
B. The hardware raises an interrupt to the device
C. The user program resumes execution in user mode
D. The kernel copies data directly to the user buffer without validation
Solution
Step 1: User program issues system call
The user program executes a special instruction causing a trap to kernel mode.
Step 2: CPU switches to kernel mode
Control transfers to the OS kernel with elevated privileges.
Step 3: Kernel validates system call
The kernel inspects the system call number and arguments to ensure they are valid and safe.
Step 4: Why other options are incorrect
The kernel copies data directly to the user buffer without validation is unsafe; kernel must validate before copying data. The user program resumes execution in user mode happens after system call completion, not immediately after mode switch. The hardware raises an interrupt to the device is unrelated here; hardware interrupts occur asynchronously, not immediately after mode switch.
Final Answer:
Option A -> Option A
Quick Check:
System call trap -> kernel mode -> validate call -> execute service [OK]
Hint: Kernel validates system call immediately after mode switch
Common Mistakes:
Assuming kernel copies data before validation
Confusing interrupt handling with system call flow
Thinking user mode resumes immediately after trap
2. Which of the following statements about the LRU page replacement algorithm's complexity and implementation is TRUE?
medium
A. LRU requires hardware support or additional data structures to track usage efficiently
B. LRU can be implemented with O(1) time complexity per page reference using a stack
C. LRU always performs better than FIFO regardless of workload
D. LRU does not require any extra space beyond the page frames
Solution
Step 1: Analyze LRU Implementation Complexity
LRU needs to track the order of page usage, which is costly without hardware or data structures.
Step 2: Evaluate Each Option
LRU requires hardware support or additional data structures to track usage efficiently is true; LRU requires hardware support or additional data structures to track usage efficiently. LRU can be implemented with O(1) time complexity per page reference using a stack is false; a stack alone cannot provide O(1) updates on every reference. LRU always performs better than FIFO regardless of workload is false; LRU can perform worse than FIFO in some workloads (e.g., scan patterns). LRU does not require any extra space beyond the page frames is false; LRU requires extra space for tracking usage metadata.
Final Answer:
Option A -> Option A
Quick Check:
Efficient LRU needs support beyond just frames.
Hint: LRU needs extra tracking structures or hardware support [OK]
Common Mistakes:
Assuming LRU is always better than FIFO
Believing LRU can be done with no extra space
Thinking a simple stack suffices for O(1) LRU
3. If a process requests resources that would keep the system in a safe state but the system is currently in an unsafe state, what does the Banker's Algorithm do and why?
hard
A. It denies the request because the system must always remain in a safe state, and starting from an unsafe state invalidates the algorithm's assumptions.
B. It restarts the system to reset resource allocations and ensure safety.
C. It preempts resources from other processes to restore a safe state before granting the request.
D. It grants the request because the immediate allocation is safe, ignoring the current unsafe state.
Solution
Step 1: Recall Banker's Algorithm assumptions
The algorithm assumes the system starts in a safe state to guarantee deadlock avoidance.
Step 2: Analyze the scenario
If the system is already unsafe, granting requests--even if individually safe--cannot guarantee overall safety.
Step 3: Evaluate options
A ignores the unsafe starting state. B and C describe actions outside the algorithm's scope.
Final Answer:
Option A -> Option A
Quick Check:
Banker's Algorithm cannot recover from unsafe states; it only avoids entering them.
Hint: Banker's Algorithm requires starting safe state to function correctly [OK]
Common Mistakes:
Assuming safe requests can fix unsafe states
Believing the algorithm preempts resources
Thinking system restarts are part of the algorithm
4. If the Dining Philosophers problem is extended to allow philosophers to pick up forks in any order but with a timeout mechanism to release held forks after waiting too long, what is a potential downside of this approach?
hard
A. It completely eliminates deadlock and starvation without any performance penalty
B. It may cause livelock where philosophers repeatedly pick up and release forks without eating
C. It guarantees fairness by enforcing strict turn-taking among philosophers
D. It simplifies synchronization by removing the need for semaphores or locks
Solution
Step 1: Understand timeout-based fork release
Philosophers release forks if waiting too long, preventing indefinite blocking.
Step 2: Analyze consequences
This can cause livelock, where philosophers continuously pick up and release forks without making progress.
Step 3: Evaluate other options
It completely eliminates deadlock and starvation without any performance penalty is false because performance penalties and livelock can occur; It simplifies synchronization by removing the need for semaphores or locks is false as synchronization primitives are still needed; It guarantees fairness by enforcing strict turn-taking among philosophers is false as fairness is not guaranteed.
Final Answer:
Option B -> Option B
Quick Check:
Timeouts prevent deadlock but risk livelock due to repeated retries.
Hint: Timeouts prevent deadlock but can cause livelock [OK]
Common Mistakes:
Assuming timeouts solve all synchronization issues
Confusing livelock with deadlock
Believing fairness is guaranteed by timeouts
5. If the time quantum is set equal to the longest CPU burst among all processes in Round Robin scheduling, what is the expected impact on turnaround time and fairness?
hard
A. Both turnaround time and fairness improve because processes get longer uninterrupted CPU bursts
B. Turnaround time approaches that of First-Come-First-Serve scheduling, but fairness among processes decreases
C. Fairness remains the same but turnaround time increases due to longer waiting times
D. Turnaround time decreases significantly and fairness improves due to fewer context switches
Solution
Step 1: Understand quantum equal to longest burst
Setting quantum to longest burst means processes run mostly to completion without preemption.
Step 2: Compare to FCFS
This behavior mimics FCFS, where processes run in arrival order without interruption.
Step 3: Analyze fairness and turnaround
Fairness decreases because shorter processes wait longer, losing RR's time-sharing benefit. Turnaround time approaches FCFS values.
Step 4: Evaluate incorrect options
Turnaround time decreases significantly and fairness improves due to fewer context switches is wrong because fewer context switches do not improve fairness. Fairness remains the same but turnaround time increases due to longer waiting times is wrong as fairness changes. Both turnaround time and fairness improve because processes get longer uninterrupted CPU bursts is wrong because fairness does not improve.