Back to the 2014 paper

Module 4: Memory Organization

20147m

Explain swapping. Why is it used in memory management?

Worked SolutionAI Assisted

Swapping in Memory Management

Definition

Swapping is the technique of temporarily moving a process (whole or part) from main memory (RAM) to secondary storage (swap space/backing store) and bringing it back later for execution.Introduced in early time-sharing systems (Atlas, UNIX) to support multiprogramming beyond physical memory size.

Stored image on disk is called swap-out; retrieving is swap-in (roll-out / roll-in).

How it Works

  1. Scheduler detects low free frames or blocked process waiting for I/O.
  2. Swapper (mid-term scheduler) selects victim process → copies its entire address space (code, data, stack, PCB) to contiguous swap area on disk.
  3. Page tables / base-limit registers updated, frames freed.
  4. Later when memory available and process scheduled, swapper reads image back (possibly at different physical address → requires relocation / dynamic binding via relocation register).

Modern systems swap pages/segments, not whole processes (demand paging is a lazy swap).

Diagram: Main Memory [P1|P2|P3|hole] ↔ Disk Swap Area [P4(swapped)] ↔ Scheduler

Why Used? (Objectives)

  • Multiprogramming degree: Run more processes than fits in RAM. Example 88 processes ×200KB=1.6MB\times 200KB =1.6MB on 1MB1MB RAM via time-multiplexing.
  • Memory compaction / fragmentation removal: Swapping out creates large contiguous free blocks, reducing external fragmentation.
  • Priority & scheduling: Swap out low-priority/blocked processes to give room to urgent ones (mid-term suspend).
  • Fairness & time-sharing: Quantum expired → swap out to let next process in.
  • Emergency handling: Low-memory handler frees RAM quickly.
  • I/O overlap & backing store for paging: Pages not resident stay on disk.

Types

  • Whole-process swapping: Simple but heavy I/O (entire address space).
  • Page swapping (paging): Swap only pages, more efficient, foundation for virtual memory.
  • Segment swapping: Similar for segmented systems.

Cost & Issues

  • Transfer time: Main cost Tswap=2×(size/transfer−rate)+seek/latencyT_{swap}=2\times (size/transfer-rate) + seek/latency. e.g. 10MB/100MBps=100ms10MB/100MBps=100ms. So swap only if process idle for longer.
  • Blocked I/O: Process with pending I/O or pinned pages cannot be swapped.
  • Thrashing risk: Excessive swapping degrades CPU utilization → need working set / locality.

Today pure swapping rare; virtual memory + demand paging is generalized swapping with finer granularity, and swap file/partition remains as overflow store.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.