←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Swap Space Management, Disk Reliability (RAID) & Disk Recovery

Study material and explanations for Unit 5

Swap Space Management, Disk Reliability (RAID) & Disk Recovery

1. Swap-Space Management

In Unit 4, we learned that Virtual Memory and Swapping move inactive pages or entire processes out of Main Memory (RAM) onto the Hard Disk/SSD. The dedicated portion of the disk used for this purpose is called Swap Space!

What is Swap-Space Management? Swap-Space Management is a low-level task of the Operating System that designs and manages the disk space used as an extension of Virtual Memory to provide the best possible throughput (speed) for the virtual memory system.

Three Key Aspects of Swap-Space Management:

Figure 5.7: The Three Core Aspects of Swap-Space Management
1. Swap-Space Use
Used to hold swapped-out processes & anonymous virtual memory pages (Heap/Stack)
2. Swap-Space Location
Can be a Swap File inside the normal file system OR a Separate Raw Swap Partition
3. Swap-Space Allocation
Allocated either at process creation time or dynamically when a page is forced out of RAM

1. Swap-Space Use

  • How much swap space does an OS need? Depending on the physical RAM size, operating systems recommend swap space ranging from 1× to 2× the size of physical RAM.
  • If swap space runs out completely, the OS may be forced to abort processes or refuse to start new programs.

2. Swap-Space Location (Where Does Swap Space Reside on Disk?)

Swap space can be created in two places:

  • Approach A — Inside the Normal File System (Swap File): Swap space is simply a large special file inside the normal file system (e.g., pagefile.sys in Microsoft Windows).
    • Pros: Easy to create, resize, or delete using standard file-system routines.
    • Cons: Slightly slower because navigating directory structures and disk allocation tables adds extra overhead.
  • Approach B — In a Separate Raw Disk Partition (Swap Partition): Swap space is placed on its own dedicated, separate raw disk partition without any normal file-system or directory structure (standard in Linux / UNIX!).
    • Pros: Much faster! A dedicated swap-space storage manager optimizes exclusively for speed (since swap data only lives until the next reboot, internal fragmentation is less of a concern than raw I/O speed).

2. Disk Reliability (RAID — Redundant Array of Independent Disks)

A single hard disk has mechanical moving parts and can fail at any moment—causing permanent loss of critical data and system downtime.

How do Operating Systems and servers achieve high Disk Reliability and high Disk Speed? By grouping multiple inexpensive disks together using RAID (Redundant Array of Independent Disks)!

Two Core Techniques Used in RAID:

  1. Data Striping (For High Speed / Performance): Splits data bits or blocks across multiple disks simultaneously so that 4 disks can read/write a single file 4 times faster in parallel!
  2. Redundancy — Mirroring or Parity (For High Reliability): Stores extra duplicate copies (Mirroring) or error-correcting Parity bits on separate disks so that even if a whole hard disk catches fire or crashes, ZERO data is lost!
Figure 5.8: Key RAID Levels Used for Disk Reliability and Performance
RAID 0Block-Level Striping (No Redundancy)
Fastest read/write speed, but 0% fault tolerance (If 1 disk fails, all data is lost)
RAID 1Disk Mirroring (100% Duplicate Copy)
Every write is duplicated onto a Mirror Disk — Highest Reliability, but costs 2× disk space
RAID 5Block-Level Striping with Distributed Parity
Distributes data + error-correcting Parity across N disks; survives any 1 disk failure using only 1 disk's worth of overhead!
RAID 10 (1+0)Striped Mirrors (Mirroring + Striping)
Combines the speed of RAID 0 with the bullet-proof reliability of RAID 1 (Needs min 4 disks)

3. Disk Recovery & File System Recovery

When a disk sector physically wears out or the computer suddenly loses power in the middle of writing a file, how does the Operating System recover the disk and file system?

1. Bad-Block Recovery (Hardware/Controller Level)

Over time, certain magnetic sectors on a hard disk become damaged and unreadable, known as Bad Blocks. The OS recovers from Bad Blocks using two techniques:

  • Sector Sparing (Forwarding): The disk manufacturer sets aside extra hidden “Spare Sectors” on every cylinder. When the disk controller detects a Bad Block, it copies the recovered data to a Spare Sector and transparently redirects all future requests from the bad block to the spare sector!
  • Sector Slipping: Shifts all sectors after the bad block down by one position to free up a healthy replacement sector right in sequence.

2. Consistency Checking (fsck / chkdsk)

  • If a system crashes or loses power while directory metadata is still cached in RAM, the directory structure on disk becomes inconsistent (corrupted).
  • On reboot, the OS runs a Consistency Checker (fsck in UNIX/Linux, chkdsk in Windows) that compares the data in the directory structure with the actual allocated data blocks on disk and repairs lost clusters or broken links.

3. Log-Structured / Journaling File Systems (Modern Recovery)

  • Modern file systems (NTFS, ext4, APFS) use Database Journaling (Write-Ahead Logging)!
  • Before making any change to a file or directory, the OS first writes the intended transaction into a circular Journal (Log) on disk. If the power fails mid-operation, on reboot the OS simply replays or rolls back the Journal in 1 second without scanning the entire terabyte drive!

4. Backup and Restore (Disaster Recovery)

  • Since even RAID cannot protect against accidental file deletion, ransomware, or physical theft, the OS provides utilities for Full Backup and Incremental Backup (copying only files modified since the last backup) to an external drive, magnetic tape, or Cloud storage.

💡 Exam Preparation Tips for DAVV BCA

  • If asked about Swap Space Management, always explain the two locations: Swap File (pagefile.sys in Windows) vs Dedicated Raw Swap Partition (in Linux).
  • For Disk Reliability & Recovery, always explain RAID (Mirroring vs Striping) alongside Bad-Block Recovery (Sector Sparing) and Journaling / Consistency Checking (fsck / chkdsk).