📝 Caching in Kernel I/O Subsystem (8 MCQs)
Retaining Frequently Used Data for Faster Access
Caching in the kernel I/O subsystem stores copies of data in faster memory so later requests can be served without repeating slower device operations. File systems commonly use page caches or buffer caches to retain file contents and storage blocks. Cache management aims to reduce I/O latency and device traffic while preserving consistency with the underlying storage.
Why Repeated Device Access Is Expensive
Storage devices are slower than main memory, and applications may repeatedly access the same files or blocks. Fetching every requested item from the device would waste time and bandwidth. Caching exploits temporal and spatial locality, but it must also manage limited memory and account for modifications that have not yet reached persistent storage.
Cache Lookup, Hit and Miss Processing
When a request arrives, the kernel checks whether the required data is already cached. A cache hit allows access from memory. On a miss, the system retrieves data from the device and may place it in the cache for reuse. Modified cached data may be marked dirty and written back later or synchronously.
Example of Repeated File Access
A process reads a 4 KB file block that is not cached. The kernel retrieves it from storage and keeps a copy in memory. When the same process reads that block again, the cache can supply the data without another device read, provided the cached copy remains valid.
Cache Performance and Consistency Requirements
Caching can reduce average read latency and device workload, particularly for frequently accessed data. It requires memory management, replacement policies, and consistency controls. Write-through policies propagate changes promptly, while write-back policies defer device updates. Cache coherence and crash recovery become important when several layers or devices hold copies of modified information.
Misconceptions About Caching
'A cache and a buffer have identical purposes' is incorrect because caching promotes reuse while buffering coordinates transfers. 'A cache hit always means permanent data is stored' is false because entries may be evicted. 'A successful write to cache guarantees persistent storage' ignores delayed write-back and possible failure before data reaches the device.
Exam Focus: Cache Hits, Misses and Write Policies
Calculate hit ratio as hits divided by total accesses and explain its effect on average access time. Trace a cache miss followed by a later hit. Compare write-through and write-back policies, including the treatment of dirty blocks and the risk of losing updates before they reach persistent storage.
Key Terms of I/O Caching
- Cache hit - Requested data is already cached.
- Cache miss - Requested data must be fetched.
- Hit ratio - Fraction of accesses served by cache.
- Dirty block - Cached data modified but not written back.
- Write-through - Propagates updates promptly to storage.
📝 All Caching in Kernel I/O Subsystem MCQs
Q1. A device driver receives an interrupt with vector number 45. Which of the following statements is true about this interrupt?
📖 Explanation: Vector numbers 32–255 are defined as maskable, meaning the CPU can temporarily ignore them if a higher‑priority condition is being serviced. Vector 45 falls in this range, so the interrupt can be masked by software and will not trigger an immediate non‑maskable exception. Option A correctly states this property. Option B is wrong because non‑maskable vectors are limited to 0–31. Option C describes a divide‑by‑zero exception, which uses vector 0. Option D refers to double‑fault (vector 8), which is unrelated to vector 45.
Q2. What is the primary purpose of having interrupt priority levels in a CPU?
📖 Explanation: Interrupt priority levels let the CPU decide which interrupt to handle first when several arrive simultaneously. A high‑priority interrupt can interrupt the service routine of a lower‑priority one, ensuring that urgent events are processed quickly. Therefore option C is correct. Option A reverses the relationship and is false. Option B describes a global mask, which is a different mechanism. Option D suggests equal treatment, which contradicts the purpose of priority levels. In practice, this hierarchy reduces response time for critical hardware events.
Q3. During system boot the OS installs interrupt handlers. If a new network card is added after boot without updating the interrupt vector, what is the most likely outcome?
📖 Explanation: When a new network card appears after the OS has already installed its interrupt vector table, the hardware will generate an interrupt on a vector that currently has no valid handler. The CPU will then jump to an undefined address, often causing a crash or a freeze. Option B captures this result. Option A is incorrect because the OS does not automatically allocate vectors without explicit registration. Option C is wrong; ignored interrupts would leave the device non‑functional. Option D is false because dynamic assignment does not happen without driver code.
Q4. Why are the first 32 interrupt vectors (0‑31) designated as non‑maskable on an Intel Pentium processor?
📖 Explanation: The first thirty‑two vectors are reserved for processor‑generated exceptions such as divide‑by‑zero, invalid opcode, and protection faults. These conditions are critical and must be handled immediately, so they are defined as non‑maskable to prevent software from accidentally disabling them. Option B correctly identifies this reason. Option A is incorrect because low‑priority tasks are not placed in this range. Option C misstates the purpose; user‑defined interrupts are typically placed in the maskable range. Option D is false because future extensions still respect the non‑maskable designation for these vectors.
Q5. Which interrupt vector number is assigned to the page‑fault exception?
📖 Explanation: The page‑fault exception is assigned vector number 14 in the Intel Pentium interrupt table. This vector is invoked whenever a program accesses a page that is not currently resident in physical memory, prompting the OS to load the needed page. Option A correctly names the vector. Options B, C, and D list neighboring vectors: 13 corresponds to a general‑protection fault, 12 to a stack‑fault, and 15 to a floating‑point error. Knowing the exact mapping is essential for low‑level debugging and for writing correct exception handlers.
Q6. A real‑time embedded system must guarantee that a timer interrupt (vector 32) is serviced within 5 µs. Which design choice best ensures this timing guarantee?
📖 Explanation: In a hard‑real‑time environment, meeting a strict latency bound requires that the timer interrupt be serviced before any lower‑priority work can delay it. Assigning the timer the highest priority ensures the CPU will always pre‑empt other ISRs to handle the timer within the 5 µs window. Option A therefore satisfies the requirement. Option B, enabling global interrupts after every instruction, does not affect priority. Option C replaces the interrupt with polling, which typically adds overhead and cannot guarantee the deadline. Option D would slow the handler by preventing cache use, worsening latency.
Q7. How does the ability of a high‑priority interrupt to pre‑empt a low‑priority ISR affect overall system latency and throughput?
📖 Explanation: When a high‑priority interrupt can pre‑empt a low‑priority ISR, the low‑priority task may have to wait longer, increasing its latency, while the system can quickly respond to urgent events, improving overall throughput. However, if low‑priority interrupts are constantly pre‑empted, they may suffer starvation. Option C accurately reflects this trade‑off. Option A is partially true but omits the throughput benefit. Option B reverses the effect on latency. Option D claims no impact, which contradicts observed behavior in priority‑based interrupt systems.
Q8. If a programmer mistakenly registers a handler for vector 7 (reserved for coprocessor segment overrun) to service a user‑defined I/O device, what consequence is most likely?
📖 Explanation: Vector 7 is reserved for the coprocessor segment overrun exception, a condition that the CPU uses for a specific error state. Registering a user‑defined handler for this vector overwrites the expected exception handling, leading to undefined behavior when the CPU triggers the real exception or when the device generates its interrupt. Option D correctly predicts a possible system crash. Option A is false because the handler will be called, but for the wrong reason. Option B mischaracterizes the fault as a double‑fault. Option C is unrealistic; the OS will not simply misinterpret the interrupt without adverse effects.)