Skip to content

Secondary Storage Management**

🧠 What is Secondary Storage?

  • Secondary Storage refers to non-volatile, long-term data storage devices like:

  • Hard Disk Drives (HDDs)

  • Solid State Drives (SSDs)
  • Magnetic Tapes
  • Optical Discs (CDs/DVDs)

📌 It stores data permanently, even after the system is turned off, unlike primary memory (RAM).


🔧 Need for Secondary Storage Management

  • To store large amounts of data not currently in use.
  • To allow efficient retrieval, updating, and deletion of data.
  • To manage the limited space efficiently.
  • To support file systems, backups, and virtual memory.

🔄 Responsibilities of the OS in Secondary Storage Management

Responsibility Description
Disk Scheduling Efficient ordering of read/write requests to minimize disk head movement
📂 File Allocation Managing where files are stored on disk (contiguously or scattered)
🧹 Free Space Management Keeping track of used and unused disk blocks
🛡️ Protection Preventing unauthorized access to stored data
🗃️ Directory Management Maintaining directory structure for file organization
♻️ Storage Reclamation Reusing disk space freed by deleted files

💽 Disk Structure

  • Disk = multiple platters coated with magnetic material
  • Each platter has:

  • Tracks (concentric circles)

  • Sectors (divisions of each track)
  • Data is read/written by a moving head

📊 Access Time Components

Term Description
Seek Time Time to move the read/write head to the correct track
Rotational Delay Time for disk to rotate and position the desired sector
Transfer Time Time to actually read or write data

📌 Disk Scheduling Algorithms

(Used to manage multiple read/write requests efficiently)

Algorithm Description
FCFS (First Come First Serve) Serve requests in the order they arrive
SSTF (Shortest Seek Time First) Choose the request closest to current head
SCAN (Elevator Algorithm) Move head in one direction, then reverse
C-SCAN (Circular SCAN) Like SCAN, but returns directly to start
LOOK & C-LOOK Similar to SCAN/C-SCAN but stops at last request, not disk end

🧩 Free Space Management Techniques

Method Description
Bit Map Use bits (0/1) to represent free/used blocks
Linked List Keep a list of free blocks
Grouping Keep a list of block groups
Counting Track starting block and number of free blocks in sequence

📂 File Allocation Methods (how files are stored on disk)

Method Description
Contiguous File occupies a set of consecutive blocks
Linked Each block points to the next block
Indexed Use a separate index block to store all block addresses

Advantages of Proper Secondary Storage Management

  • Better disk utilization
  • Faster read/write operations
  • Easier file retrieval and storage
  • Enhanced data security
  • Support for large-scale multitasking systems

Summary

Key Area Purpose
Disk Scheduling Optimize performance of I/O operations
File Allocation Efficiently manage storage space for files
Free Space Management Track and reuse available disk blocks
Access Time Management Reduce seek and latency delays
Protection & Security Prevent unauthorized data access

🧩 Topic: Disk Structure

💽 What is Disk Structure?

The disk structure defines the physical and logical organization of data on a hard disk drive (HDD) or solid-state drive (SSD).

It includes:

  • How data is stored and accessed
  • How the disk is divided (tracks, sectors, cylinders)
  • How the OS interacts with disk components for I/O

🧱 Physical Structure of a Disk

A hard disk typically consists of the following:

1. Platters

  • Flat circular disks coated with magnetic material
  • Rotate around a spindle
  • Data is stored on both surfaces

2. Tracks

  • Concentric circles on the surface of each platter
  • Each track is divided into sectors

3. Sectors

  • The smallest unit of storage on a disk (commonly 512 bytes or 4 KB)
  • Each track contains multiple sectors

4. Cylinders

  • A set of tracks vertically aligned across platters (same track number on all platters)
  • Allows simultaneous access across platters

5. Read/Write Head

  • One head per surface
  • Mounted on a moving arm to access data on different tracks

6. Spindle

  • Rotates all platters together at high speed (e.g., 5400 or 7200 RPM)

🖼️ Diagram: Disk Structure Overview

           Top View of a Platter
         +------------------------+
         |   +----+----+----+    | ← Track 0, 1, 2...
         |   | T0 | T1 | T2 |    |
         |   +----+----+----+    |
         +------------------------+
                  ↑
              Read/Write Head

        Side View: Multiple Platters

     Platter 0:  T0   T1   T2   ...  ← Track
     Platter 1:  T0   T1   T2   ...
                 ↑
             Cylinder (all T1s)

⚙️ Disk Addressing: CHS vs LBA

Method Description
CHS (Cylinder-Head-Sector) Old method using physical geometry (rarely used now)
LBA (Logical Block Addressing) Modern method – assigns unique number to each sector

⏱️ Disk Access Time

Component Description
Seek Time Time to move head to correct track (avg: 2–10 ms)
Rotational Delay Time for sector to rotate under head (avg: 3–5 ms)
Transfer Time Time to read/write data (depends on RPM and size)

🧮 Total Access Time = Seek Time + Rotational Delay + Transfer Time


📊 Summary Table: Disk Components

Component Function
Platters Store data magnetically
Tracks Concentric circles storing data
Sectors Smallest storage unit
Cylinders All tracks aligned vertically across platters
R/W Head Reads/writes data from/to disk
Arm Assembly Moves heads across tracks
Spindle Rotates the platters

Key Points for Exams

  • Track: circular path on disk
  • Sector: subdivision of a track
  • Cylinder: same track number across all platters
  • Seek Time: time to move head
  • Rotational Delay: wait for sector under head
  • Transfer Time: time to read/write

🧩 Topic: Free Space Management

🧠 What is Free Space Management?

Free space management is the process of tracking all the unallocated (free) blocks or sectors on the disk so that:

  • New files can be allocated space
  • Deleted files can free up their space for reuse

📌 It helps the OS manage disk storage efficiently and avoid fragmentation.


🎯 Objectives

  • Keep track of which disk blocks are free
  • Allocate space for new files or growth
  • Deallocate space when files are deleted

🧱 Techniques for Free Space Management


🔹 1. Bit Map (Bit Vector)

  • A bit array is used to represent each block on the disk:

  • 1 → block is allocated

  • 0 → block is free

✅ Advantages:

  • Simple and compact
  • Easy to find contiguous free blocks

❌ Disadvantages:

  • Needs memory to store bit map (1 bit per block)
  • Slow for large disks (scanning required)

🔍 Example:

For 8 blocks: 0 1 1 0 0 1 0 0 ⇒ Blocks 0, 3, 4, 6, 7 are free


🔹 2. Linked List (Free List)

  • All free blocks are linked together using pointers
  • Each free block contains a pointer to the next free block

✅ Advantages:

  • Easy to manage
  • No extra memory needed (uses block itself)

❌ Disadvantages:

  • Cannot quickly find multiple free blocks
  • Pointer overhead reduces usable space

🔹 3. Grouping

  • First free block contains addresses of n free blocks
  • One of those n blocks contains the next group of n free blocks, and so on

✅ Advantages:

  • Fast allocation of multiple free blocks
  • Better than simple linked list

❌ Disadvantages:

  • Slightly more complex than simple linked list

🔹 4. Counting

  • Keeps track of:

  • Starting block address

  • Number of contiguous free blocks

✅ Advantages:

  • Good for managing large contiguous blocks
  • Requires less memory

❌ Disadvantages:

  • May not be helpful in highly fragmented disks

🔍 Example:

[Start: 12, Count: 5] → Blocks 12 to 16 are free

📊 Comparison Table

Method Space Efficiency Search Speed Suitable For
Bit Map High Medium Contiguous allocation
Linked List Low (pointer overhead) Low Small files
Grouping Medium High Bulk allocation
Counting High High (for contiguous) Large free blocks

Summary

Concept Key Point
Free space management Tracks unallocated disk blocks
Bit map Uses bits (0 = free, 1 = used)
Linked list Each free block links to the next
Grouping Groups of free block addresses stored together
Counting Stores start address and number of free blocks

🧩 Topic: File Allocation Methods

🧠 What is File Allocation?

File Allocation refers to the way the blocks on disk are assigned to files so that:

  • File data can be stored and accessed efficiently.
  • The operating system knows where a file’s contents are located.

🎯 Objectives of File Allocation

  • Maximize disk space utilization
  • Minimize file access time
  • Support for growing files
  • Handle fragmentation efficiently

📦 Main File Allocation Methods

Method Key Idea Suitable For
1. Contiguous Store file in a single continuous block Simple & fast access
2. Linked Store blocks anywhere; link using pointers Dynamic file size
3. Indexed Use index block to store all addresses Random access

🔹 1. Contiguous Allocation

  • Each file occupies consecutive disk blocks.

🧱 Structure:

File A → Blocks 5, 6, 7, 8

✅ Advantages:

  • Simple and fast (direct access)
  • Excellent read performance

❌ Disadvantages:

  • External fragmentation
  • Difficult to grow file if adjacent blocks are full
  • Wastes space if reserved blocks are unused

🔹 2. Linked Allocation

  • Each file is a linked list of disk blocks, which may be scattered on disk.
  • Each block stores data + pointer to next block.

🧱 Structure:

File B → Block 2 → Block 10 → Block 17 → null

✅ Advantages:

  • No external fragmentation
  • File size can grow easily

❌ Disadvantages:

  • Sequential access only
  • Pointer overhead in each block
  • Can be unreliable if pointer is lost

🔹 3. Indexed Allocation

  • Uses a special index block to store all block addresses of the file.
  • Supports direct access to any block.

🧱 Structure:

Index Block (File C) → [3, 7, 11, 14]
→ File data in: Block 3, Block 7, Block 11, Block 14

✅ Advantages:

  • Supports random access
  • No external fragmentation
  • Easy to grow file

❌ Disadvantages:

  • Overhead of index block
  • For large files, may need multi-level indexing

📊 Comparison Table

Feature Contiguous Linked Indexed
Access Type Direct & Sequential Sequential only Direct & Sequential
File Growth Difficult Easy Easy
Fragmentation External None None
Overhead Low Pointer per block Index block(s)
Access Speed Fast Slow Medium–Fast

Summary

  • Contiguous: Simple and fast, but causes fragmentation.
  • Linked: Flexible, but slower and no direct access.
  • Indexed: Supports random access, but has indexing overhead.

🧩 Topic: Disk Scheduling

🧠 What is Disk Scheduling?

Disk Scheduling refers to the method of choosing the order in which pending disk I/O requests are served.

Since disk head movement is slow, the goal is to:

  • Minimize seek time (head movement)
  • Improve throughput
  • Reduce latency

⚙️ Disk Access Time = Seek Time + Rotational Delay + Transfer Time

Since seek time is the most time-consuming, disk scheduling mainly focuses on minimizing head movement.


📦 Types of Disk Scheduling Algorithms

Algorithm Principle Best For
FCFS Serve requests in arrival order Simple & fair
SSTF Serve closest request (min seek time) High efficiency
SCAN Move head in one direction, then reverse Heavy loads
C-SCAN Only one-direction scan, jump to start Uniform service
LOOK Like SCAN but only go as far as needed Less movement
C-LOOK Like C-SCAN, optimized movement Balanced performance

🔹 1. FCFS (First-Come, First-Served)

  • Serve requests in the order they arrive.
  • Simple, fair, but can be inefficient.

🔍 Example:

Requests: 98, 183, 37, 122 Head at: 100

Total Head Movement = |100–98| + |98–183| + |183–37| + |37–122| = 345 tracks

✅ Fair ❌ Long seek times


🔹 2. SSTF (Shortest Seek Time First)

  • Serve the nearest request to current head position.
  • Like a greedy algorithm.

🔍 Example:

Requests: 98, 183, 37, 122 Head at: 100

Closest to 100 → 98 → 122 → 183 → 37 Total movement = less than FCFS

✅ Efficient ❌ May cause starvation


🔹 3. SCAN (Elevator Algorithm)

  • Head moves in one direction, serves all requests, then reverses.
  • Like an elevator going up and down.

🔍 Head at 50, moving right

Requests: 34, 78, 90, 123, 10 → Serve: 78 → 90 → 123 → reverse → 34 → 10

✅ Reduces variance ❌ Longer wait at the ends


🔹 4. C-SCAN (Circular SCAN)

  • Moves in one direction (e.g., right), and jumps to beginning after reaching end.

🔍 Example:

→ 78 → 90 → 123 → jump → 10 → 34

✅ Uniform response time ❌ Unused movement during jump


🔹 5. LOOK

  • Like SCAN, but stops at the last request (not end of disk).

🔍 Example:

→ 78 → 90 → 123 → reverse → 34 → 10

✅ Saves time (no full scan)


🔹 6. C-LOOK

  • Like C-SCAN but only moves as far as last request, then jumps to the first.

🔍 Example:

→ 78 → 90 → 123 → jump → 10 → 34

✅ Efficient version of C-SCAN


📊 Comparison Table

Algorithm Seek Time Fairness Starvation Directional
FCFS High High No No
SSTF Low Low Yes No
SCAN Medium Medium No Yes
C-SCAN Medium High No Yes
LOOK Low Medium No Yes
C-LOOK Low High No Yes

Summary

  • FCFS: Simple, but may cause long delays.
  • SSTF: Efficient but may starve far requests.
  • SCAN / LOOK: Balanced, like elevator.
  • C-SCAN / C-LOOK: Uniform service for all tracks.

🧩 Topic: Performance and Reliability Improvements in Disk Systems

🎯 Objective

Modern operating systems and storage hardware apply various techniques to improve:

  • 📈 Performance (speed of data access and transfer)
  • 🔒 Reliability (safety and consistency of stored data)

⚙️ 1. Performance Improvements


🔹 A. Disk Caching

  • Uses fast memory (RAM) as a buffer for frequently accessed data.
  • Reduces physical disk access.
  • Improves read/write speed dramatically.

✅ Example: OS caches file system metadata in RAM for faster access.


🔹 B. Read-Ahead and Write-Behind

  • Read-Ahead: OS predicts future data use and preloads blocks into cache.
  • Write-Behind: Delays writes to group multiple writes together.

✅ Reduces disk I/O ✅ Boosts throughput


🔹 C. Disk Scheduling Algorithms

  • Techniques like SSTF, SCAN, and LOOK reduce head movement.
  • Optimize the order of disk access for minimal seek time.

🔹 D. Disk Striping (RAID-0)

  • Splits data across multiple disks for parallel read/write operations.

✅ Increases speed, especially for large files ❌ No redundancy (not reliable)


🔹 E. Solid-State Drives (SSD)

  • Use flash memory, no moving parts.
  • Faster than HDDs in access time and data transfer.

✅ High-speed storage ✅ No mechanical delays


🛡️ 2. Reliability Improvements


🔹 A. Redundant Array of Independent Disks (RAID)

RAID = group of multiple disks working together to improve reliability & performance

Level Feature Benefit
RAID 1 Disk Mirroring Full data redundancy
RAID 5 Striping with Parity Balanced reliability and speed
RAID 6 Dual Parity Can survive 2 disk failures

🔹 B. Disk Mirroring (RAID-1)

  • Data is written to two identical disks.
  • If one fails, the other has a complete copy.

✅ Ensures data safety ❌ Expensive (requires double storage)


🔹 C. Journaling File Systems

  • File systems like ext4, NTFS, and XFS maintain a log (journal) of changes.
  • In case of a crash, the system can recover data from the journal.

✅ Prevents data corruption ✅ Fast recovery after crashes


🔹 D. ECC (Error Correction Code)

  • Used to detect and correct errors in data stored on disk.
  • Ensures data integrity.

🔹 E. Backups and Snapshots

  • Backup: Copy of data stored elsewhere for recovery.
  • Snapshot: Point-in-time copy of disk state (used in cloud systems and databases)

✅ Ensures recoverability ✅ Minimizes data loss


📌 Summary Table

Category Technique Purpose
Performance Disk Caching, SSDs Fast data access
Scheduling Algorithms Reduce seek time
RAID-0 (Striping) Faster read/write
Reliability RAID-1, RAID-5/6 Data redundancy
Journaling File Systems Crash recovery
ECC, Backups Error correction & data safety

Key Takeaways

  • Performance is enhanced by reducing mechanical delays and caching.
  • Reliability is improved through redundancy, journaling, and backups.
  • Modern systems often combine performance and fault-tolerance techniques.

🧩 Topic: Storage Hierarchy

🧠 What is Storage Hierarchy?

The storage hierarchy refers to the organization of different types of memory and storage devices in a computer system, based on:

  • Speed
  • Cost
  • Volatility
  • Capacity
  • Access time

📌 It is designed to balance performance and cost by storing frequently used data in faster (but expensive) memory and infrequently used data in slower (but cheaper) memory.


🏛️ Structure of Storage Hierarchy

   ↑   Faster, More Expensive, Smaller
   |   
   |   CPU Registers
   |   Cache Memory (L1, L2, L3)
   |   Main Memory (RAM)
   |   Solid-State Drive (SSD)
   |   Hard Disk Drive (HDD)
   |   Optical Disks (CD/DVD)
   |   Magnetic Tapes
   ↓   Slower, Cheaper, Larger

📊 Hierarchy Table

Level Storage Type Access Time Cost per Bit Volatile Capacity
1 CPU Registers 1 ns Very High Yes Very Low
2 Cache (L1/L2/L3) 1–10 ns High Yes Low
3 Main Memory (RAM) 10–100 ns Medium Yes Moderate
4 SSD 0.1–1 ms Low No High
5 HDD 1–10 ms Very Low No Very High
6 Optical/Magnetic Seconds Very Low No Huge

🎯 Key Characteristics

Term Description
Volatile Data is lost when power is off (e.g., RAM)
Non-Volatile Data is retained without power (e.g., HDD, SSD)
Access Time Time taken to read/write data
Cost per Bit Cost of storing a single bit (decreases down the hierarchy)
Capacity Amount of data that can be stored (increases down the levels)

🔁 Why Use a Storage Hierarchy?

  • Fast memory (like cache) is expensive and small.
  • Slow memory (like HDD) is cheap and large.
  • Combining different types of memory:

  • Keeps hot data close to the CPU

  • Moves cold data to slower storage

✅ Achieves high performance at low cost


📌 Examples in Practice

  • CPU uses cache for recently used instructions
  • OS uses RAM for active programs
  • Virtual memory uses HDD/SSD as an extension of RAM
  • Backup data is stored in magnetic tapes or external drives

Summary

Feature Upper Levels (e.g., Cache, RAM) Lower Levels (e.g., HDD, Tape)
Speed Very Fast Slow
Cost High Low
Volatility Volatile Non-Volatile
Capacity Low High