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:
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.sysin 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:
- 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!
- 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!
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 (
fsckin UNIX/Linux,chkdskin 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.sysin 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).