📝 Swap space use in Storage Structure (9 MCQs)
Secondary Storage Support for Virtual Memory
Swap space is a reserved area of secondary storage used by an operating system to hold selected memory contents that are temporarily removed from physical RAM. It supports virtual-memory management when available memory becomes insufficient. Swap space may be implemented as a dedicated partition or a file. Its contents allow certain nonresident pages, particularly anonymous memory, to be restored when processes reference them again.
Why Operating Systems Need Backing for Nonresident Pages
Physical memory is limited, but active processes may collectively require more memory than RAM can accommodate. The operating system can reclaim selected pages to create room for incoming requests. Clean file-backed pages can often be retrieved from their original files, while modified anonymous pages need suitable backing storage. Swap space provides a persistent backing location for such memory contents.
Page Eviction and Restoration Through Swap Space
When memory pressure requires reclaiming a modified anonymous page, the kernel selects an available swap location and writes the page contents there. Its page-table information is updated to indicate that the page is nonresident and backed by swap. If the process references it again, a page fault triggers allocation of a frame and retrieval of its stored contents.
Writing and Restoring a Swapped Memory Page
Suppose a process has a modified anonymous page of 4 KB and no suitable free frame is available. The operating system writes its contents to an allocated swap location and reuses the physical frame. Later, the process references that page. A page fault causes the kernel to read the saved 4 KB contents into an available frame and restore the mapping.
Memory Capacity, Fault Delays and Storage Wear
Swap space allows systems to support memory commitments beyond immediately available RAM and provides backing for reclaimed anonymous pages. However, storage access is much slower than physical memory, increasing response time when pages must be restored. Excessive swapping can cause thrashing, while SSD-backed swap introduces additional write activity. Swap space complements RAM but does not provide equivalent performance.
Common Misconceptions About Swap Space
'Swap space is as fast as RAM' is incorrect because secondary storage has much higher access latency. 'Every page removed from RAM must enter swap' is incorrect because clean file-backed pages can often be discarded and reloaded. 'Adding swap space increases physical memory capacity' is incorrect because it increases backing capacity, not installed RAM.
Exam Focus: Anonymous Pages and Swap Operations
Identify which pages may require swap backing and distinguish them from clean file-backed pages. Trace the eviction and restoration of an anonymous page. Calculate storage requirements using page size and page count. Explain why excessive swap activity increases page-fault service time and how available RAM, working-set requirements, and storage speed influence performance.
Key Terms of Swap-Space Management
- Swap space - Secondary-storage memory backing.
- Anonymous page - Page without file backing.
- Swap slot - Storage location for a page.
- Swap-out - Writes page contents to storage.
- Swap-in - Restores a page into RAM.
- Memory pressure - Insufficient available physical memory.
📝 All Swap space use in Storage Structure MCQs
Q1. A system receives disk I/O requests at cylinders 14, 37, 65, 67, 98, 122, 124, 183 with the read/write head currently at cylinder 53 and moving outward toward higher numbers. Using the SCAN algorithm, which cylinder will be serviced next?
📖 Explanation: The head is moving toward larger cylinder numbers, so the next request it encounters is the smallest cylinder that is still larger than 53. Among the pending requests, 65 is the first cylinder greater than 53, so it will be serviced next. Option B is correct. Option A (14) and C (67) are either behind the head or farther ahead, and D (183) is much farther, making them incorrect. This reflects how SCAN works by sweeping in one direction and picking the nearest upcoming request.
Q2. Why does the density of pending requests tend to be low for cylinders immediately after the disk head reverses direction in the SCAN algorithm?
📖 Explanation: When the head reaches an end and reverses, the cylinders it just passed have been accessed moments ago, so most of the queued requests for those cylinders have already been satisfied. Consequently, very few new requests are waiting right behind the head, creating a low request density. Option A captures this effect. Options B, C, and D describe unrelated or incorrect reasons, such as OS policy or physical layout, which do not explain the observed low density.
Q3. Which statement best defines the C‑SCAN (Circular SCAN) disk‑scheduling algorithm?
📖 Explanation: C‑SCAN is a variant of SCAN that sweeps the disk in a single direction, servicing all requests on the way to the far end, then instantly returns (or jumps) to the opposite end without servicing any requests during the return. This produces a consistent, one‑direction service pattern. Option B states this precisely. Option A describes ordinary SCAN, Option C describes FCFS, and Option D describes SSTF, none of which match the circular behavior of C‑SCAN.
Q4. Given a uniform distribution of requests across 200 cylinders, which region of the disk will on average experience the longest waiting time under the SCAN algorithm when the head is at the middle and moving toward the higher‑numbered cylinders?
📖 Explanation: When the head moves upward, it first reaches the higher‑numbered cylinders before reversing. Requests located near the far end (the highest cylinders) must wait for the head to travel all the way to that end and then reverse, which adds the greatest travel distance and thus the longest average wait. Option C correctly identifies this region. Options A and B describe areas that are reached sooner, and D is false because wait times differ across the disk.
Q5. What is the primary reason that C‑SCAN generally provides more uniform wait times than SCAN?
📖 Explanation: C‑SCAN moves the head in one direction only, servicing all requests on that pass and then jumping back to the start without servicing any on the return. Because the direction never changes, every request experiences a similar maximum distance before service, leading to more uniform waiting times. Option C states this key behavior. Option A is the opposite of C‑SCAN, Option B is inaccurate, and Option D describes a priority scheme that C‑SCAN does not implement.
Q6. A disk has 200 cylinders. The current head position is 120, moving toward lower numbers. The pending requests are at cylinders 10, 20, 30, 150, 160, 170. Under the SCAN algorithm, which request will be the last to be serviced before the head changes direction?
📖 Explanation: With the head moving downward, SCAN will service requests in decreasing order until it reaches the smallest pending cylinder, which is 10. After servicing 10, the head must reverse direction to address the higher‑numbered requests. Therefore, 10 is the final request before the reversal. Option A correctly reflects this ordering. Options B and C are serviced earlier in the downward sweep, and D (170) lies in the opposite direction, so it is not encountered until after the reversal.
Q7. Consider the same request set as in the previous question (10, 20, 30, 150, 160, 170) and a head at 120 moving toward higher numbers. Compute the total head movement for SCAN and for C‑SCAN. Which algorithm results in a smaller total movement?
📖 Explanation: For SCAN, the head travels from 120 up to 170 (50 cylinders), then reverses and goes down to 10 (160 cylinders), totaling 210 cylinders. For C‑SCAN, the head goes from 120 up to 170 (50), continues to the disk end at 200 (30), jumps back to 0 (200, no service), and moves up to 30 (30), giving 310 cylinders. Thus SCAN requires less movement, making option A correct. The other options contain incorrect distance calculations or claim equal movement, which do not match the computed totals.
Q8. In a multi‑programmed environment where many processes perform frequent swapping, how does using C‑SCAN instead of SCAN affect overall system throughput?
📖 Explanation: C‑SCAN delivers more predictable and uniform wait times because every request experiences a similar maximum distance before service. This predictability lets the operating system plan swap operations with tighter timing estimates, reducing idle CPU periods and improving overall throughput. Option B captures this benefit. Option A incorrectly assumes the jump cost outweighs benefits, Option C ignores the latency advantage, and Option D misstates C‑SCAN's behavior, as it does not ignore end‑range requests.
Q9. A database server experiences heavy write traffic, and the swap space is located on the same disk. Which scheduling algorithm would most likely minimize the time processes spend waiting for swap I/O, assuming the disk head frequently starts near the middle of the disk?
📖 Explanation: When the head often starts near the middle, C‑SCAN’s one‑direction sweep ensures that no request suffers a long pause after a reversal, providing the most consistent response time for swap I/O. This uniformity reduces the worst‑case waiting period for processes needing swap space. Therefore, C‑SCAN is the best choice. FCFS offers no ordering advantage, SCAN can cause longer waits for requests near the far end, and LOOK, while similar to SCAN, still reverses direction and can produce variable latencies.