🎓 BookMCQ
← Back to 8. Main Memory

📝 Standard swapping in main memory (15 MCQs)

Moving Entire Processes Between RAM and Backing Store

Standard swapping is a traditional memory-management technique in which the operating system temporarily transfers a process's memory image from main memory to a backing store and later restores it for execution. Its purpose is to release physical memory for other processes when RAM becomes insufficient. The medium-term scheduler and memory manager coordinate process suspension, removal from memory, and subsequent resumption.

Why Process Suspension Creates a Need for Swapping

Multiprogramming improves CPU utilisation, but physical memory cannot accommodate unlimited active processes. When memory pressure increases, keeping every process resident may prevent additional work from entering the system. Swapping provides a way to reclaim a process's allocated memory temporarily. Its effectiveness depends on storage capacity, transfer speed, process size, and whether the suspended process can safely resume.

Swap-Out, Suspension and Swap-In Operations

When a process is selected for removal, the operating system suspends its execution and transfers its required memory image to backing storage. The released physical memory becomes available for other processes. When the suspended process is selected again, its image is restored into RAM, and execution can resume. The kernel must restore relevant process state and ensure that memory references remain valid.

Swapping a Process with an Eighty-Megabyte Image

Assume process P1 occupies 80 MB of memory and is suspended because another process requires additional RAM. The operating system transfers P1's memory image to the backing store, releasing approximately 80 MB of resident space. Later, P1 is restored into an available region. If its destination differs from the original location, relocation or address translation must support the change.

Memory Reclamation Costs and Scheduling Effects

Swapping allows more processes to participate in multiprogramming than available RAM can hold simultaneously. However, transferring large memory images creates substantial storage I/O, increasing suspension and resumption delays. Excessive swapping can reduce throughput and leave the CPU underutilised while processes wait for transfers. Modern systems generally rely more heavily on demand paging than traditional whole-process swapping.

Common Misunderstandings About Traditional Swapping

'Swapping always transfers only one page' is incorrect because the traditional whole-process model transfers a process memory image. 'A swapped-out process continues executing' is incorrect because it remains suspended while absent from RAM. 'Swapping directly increases physical RAM capacity' is incorrect because it uses secondary storage to extend available memory resources at much higher access cost.

Exam Focus: Swap Time and Process-State Changes

Trace transitions between ready, running, and suspended states when swapping occurs. Calculate transfer time using memory-image size and effective storage bandwidth, including both transfer directions when necessary. Distinguish whole-process swapping from page replacement and demand paging. Explain why excessive swapping increases turnaround time and why relocation may be necessary after a process returns to memory.

Key Terms of Traditional Swapping

  • Swap-out - Transfers a process out of RAM.
  • Swap-in - Restores a suspended process.
  • Backing store - Holds swapped process images.
  • Suspended process - Temporarily removed from execution.
  • Medium-term scheduler - Selects processes for suspension.
  • Transfer time - Time required for data movement.
3
Easy
7
Medium
5
Hard

📝 All Standard swapping in main memory MCQs

Q1. A user program requests to load its code into memory. Which action performed by the operating system guarantees that the program cannot modify the OS code or other users' memory?

A.Load base and limit registers using a privileged instruction ✅
B.Allow the program to set its own base register
C.Disable paging
D.Run the program in user mode without checks
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The operating system uses a privileged instruction that can only run in kernel mode to load the base and limit registers. Because only the OS can execute privileged instructions, a user program cannot change these registers, preventing it from accessing or altering memory belonging to the OS or other users. Options B, C, and D either give the user too much control or remove protection, so they would not stop unauthorized modification.

Q2. What is the primary purpose of the base register in a protected memory system?

A.Store the size of the process
B.Hold the starting physical address of a process's address space ✅
C.Indicate the current instruction pointer
D.Keep track of I/O device status
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The base register contains the physical address where a process's logical address space begins. By adding the base value to a logical address, the hardware translates it to a real memory location. This ensures each process accesses only its own allocated region. The other options describe unrelated functions: size is managed by the limit register, the instruction pointer tracks execution, and I/O status is handled by separate registers.

Q3. Why can only the operating system modify the contents of base and limit registers?

A.Because they are stored in read‑only memory
B.Because modifying them requires a privileged instruction executable only in kernel mode ✅
C.Because user programs lack arithmetic capability
D.Because the registers are physically inaccessible to user code
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Base and limit registers are changed only through a privileged instruction, which the CPU permits when running in kernel (supervisor) mode. User programs execute in user mode and cannot invoke privileged instructions, so they cannot alter these registers. This restriction keeps user code from expanding its address space or bypassing protection. The other choices are incorrect: the registers are not read‑only, arithmetic ability is unrelated, and physical inaccessibility is not the enforcement mechanism.

Q4. A process has base register = 3000 and limit register = 1200. The process generates a logical address 4250. Which outcome will occur?

A.The address is translated to 4250 and accessed
B.The address triggers a trap because it exceeds the limit
C.The address is wrapped around to 250 ✅
D.The OS silently adjusts the limit
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The logical address 4250 is compared to the limit value 1200. Since 4250 > 1200, the address exceeds the allowed range, causing the hardware to raise a protection fault (trap) and transfer control to the operating system. The OS can then handle the error, typically terminating the offending process. Options A and D incorrectly assume the address is permitted, and option C suggests an undefined wrap‑around behavior that does not exist in base/limit protection.

Q5. How does adding a base register to a logical address implement address translation?

A.It replaces the logical address with the base value
B.It shifts the logical address by the limit amount
C.It adds the base to the logical address to produce a physical address
D.It encrypts the address for security ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: When a process generates a logical address, the hardware adds the value stored in the base register to this address, yielding the corresponding physical address in main memory. This simple arithmetic provides isolation because each process can have a different base value. Options A and B describe unrelated operations, and option D introduces encryption, which is not part of base/limit translation.

Q6. During a context switch on a multiprocessor, the OS must save the current process's registers to memory. Which register must be stored before loading the next process's base register?

A.Program Counter
B.Base Register
C.Limit Register
D.All of the above ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: A complete context switch requires preserving the program counter (to know where to resume), the base register (to retain the current address space), and the limit register (to keep the protection bounds). Saving all three ensures that when the next process is loaded, its own base and limit can be installed without losing the previous process's state. Any answer that omits one of these registers would risk incorrect execution after the switch.

Q7. A user program attempts to write to address 8500 while its limit register is 8000. What will the hardware do?

A.Allow the write
B.Raise a protection fault and transfer control to the OS
C.Ignore the write
D.Automatically increase the limit register ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The hardware compares the requested address with the limit value. Because 8500 > 8000, the access violates the defined bounds, so the CPU generates a protection fault (trap) and passes control to the operating system. The OS can then terminate the program or take corrective action. Options A and C incorrectly assume the hardware permits the out‑of‑range operation, and option D suggests automatic limit expansion, which is not part of base/limit protection.

Q8. Compared to segmentation, what is a key advantage of using simple base and limit registers for protection?

A.They support variable‑size segments
B.They require fewer hardware checks per memory reference
C.They allow overlapping address spaces ✅
D.They enable dynamic code loading
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Base and limit registers perform a single bound check for each memory reference, making the hardware logic simpler and faster than the multiple checks often needed in segmented schemes. This reduction in complexity speeds up address translation. Options A and D describe capabilities of more sophisticated schemes, while option C is not a typical advantage of simple base/limit protection.

Q9. Two processes, P1 and P2, need to share a read‑only data region located at physical addresses 15000–15999. The OS sets base registers to 15000 for both and limit registers to 1000. Which additional configuration ensures P2 cannot write to this region while P1 can?

A.Set P2’s limit to 0
B.Use a separate write‑protect bit in P2’s page table entry ✅
C.Load P2 in user mode with a read‑only flag
D.Enable a hardware write‑protect bit for P2’s segment
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Base and limit registers only enforce address bounds, not read‑only versus read‑write permissions. To prevent P2 from writing, the OS must run P2 with a read‑only privilege flag (or similar protection mode) so that any write attempt to the shared region triggers a fault. Options A and D either remove access entirely or rely on hardware features not described, while option B refers to paging, which is outside the simple base/limit model.

Q10. Why are base and limit registers insufficient by themselves to prevent buffer‑overflow attacks that overwrite adjacent data structures?

A.Because they only check address bounds, not the logical structure of data ✅
B.Because they can be altered by user programs
C.Because they automatically expand limits when overflow occurs
D.Because they encrypt memory contents
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Base and limit registers guarantee that a program cannot access memory outside its allocated range, but they do not understand the layout of variables inside that range. A buffer overflow can corrupt neighboring structures while staying within the allowed address space, so the protection fails. Options B, C, and D are incorrect: user programs cannot modify the registers, limits are not auto‑expanded, and encryption is unrelated to overflow detection.

Q11. Given base = 2000, limit = 500, a program issues a logical address 2300. Determine whether the access is allowed and, if so, compute the physical address.

A.Allowed, physical address = 4300
B.Allowed, physical address = 2300 ✅
C.Not allowed, trap occurs
D.Allowed, physical address = 2000 + 2300 = 4300 (same as A)
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The logical address 2300 exceeds the limit of 500, meaning it lies outside the process's permitted range. The hardware therefore generates a protection fault, and the access is denied. Because the address is invalid, no physical address is calculated. Options A and D incorrectly assume the address is valid and perform the addition, while option B mistakenly treats the logical address as the physical address without applying the base.

Q12. During swapping, which register must be saved to ensure the process can resume execution at the correct point after being swapped back in?

A.Base Register
B.Stack Pointer
C.Program Counter ✅
D.Limit Register
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The program counter holds the address of the next instruction to execute. When a process is swapped out, its current execution point must be preserved so that, after being swapped back in, it can continue exactly where it left off. Saving the base, limit, or stack pointer alone would not guarantee correct continuation; only the program counter provides that precise location.

Q13. How does enforcing privileged instruction execution only in kernel mode enhance the security of a swapping system?

A.It prevents user programs from directly modifying hardware registers that control memory protection ✅
B.It allows user programs to bypass OS checks
C.It encrypts swapped pages
D.It speeds up context switches
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Privileged instructions, such as those that load base and limit registers, are only allowed in kernel mode. This restriction stops user programs from altering the memory protection mechanism, ensuring that only the operating system can change address limits or base addresses. Consequently, malicious or buggy user code cannot compromise isolation. Options B, C, and D describe effects that are either opposite of the security goal or unrelated to privilege enforcement.

Q14. The system is low on free memory and decides to swap out Process X. Which ordered steps does the OS typically perform?

A.Save registers, write process memory to disk, update page table, release frames ✅
B.Release frames, write registers to disk, update page table, write memory to disk
C.Write process memory to disk, save registers, update page table, free frames
D.Save registers, update page table, write memory to disk, free frames
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The usual sequence begins by saving the process's registers so its execution state is preserved. Next, the OS writes the process's memory contents to secondary storage, updates the page table to mark those pages as swapped out, and finally releases the physical frames for other uses. Options B, C, and D reorder these steps in ways that could lose state or waste resources.

Q15. What is the relationship between a limit register's value and the maximum size of a process's address space?

A.Limit register equals the number of processes
B.Limit register defines the highest permissible logical address plus one ✅
C.Limit register stores the physical address of the last byte
D.Limit register is unrelated to process size
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The limit register holds the size of the addressable range for a process; it specifies the largest legal logical offset (often expressed as the highest address plus one). This value, together with the base register, determines the total size of the process's virtual address space. The other options misinterpret the purpose of the limit register or claim no relationship, which is inaccurate.

🔗 Related Topics (MCQs)