Top Banner Ad

BCS401 — Unit 5: I/O Management and Disk Scheduling

Table of Contents (20 sections)

BCS401 · Operating system · Unit 5

I/O Management and Disk Scheduling

Unit Scope & Exam Weightage: This unit covers I/O devices and the I/O subsystem, I/O buffering, disk storage and disk scheduling, RAID levels, file concepts, organization, access mechanisms, directories and sharing, file-system implementation issues and protection/security. AKTU asks 7-mark theory on RAID/directories/allocation and 2-mark definitions plus a predicted disk-head-movement numerical.


Importance-Wise Roadmap (BCS401 Unit 5)

Priority Exact Syllabus Topic PYQ Evidence Marks Pattern Tag
1 RAID (advantages, levels 0/1/5) and disk technologies 2023-24, 2024-25, 2025-26 7m × 3 Repeat cluster
2 Disk scheduling + seek time / rotational latency 2024-25, 2025-26 7m + 2m Numerical predicted
3 File directories and directory structures 2023-24, 2024-25 7m × 2 Diagram
4 File organization / allocation methods 2023-24 7m Comparison
5 DMA, interrupt, polling, I/O subsystem 2023-24, 2025-26 7m + 2m Core theory
6 Buffering, file protection/security, implementation issues Not directly asked Predicted Backup

Disk-specific examiner guidance: In head-movement numericals, list the visited cylinders in service order and sum each absolute difference — including the wraparound jump. State explicitly whether cylinders end at 199 (C-SCAN) or at the last request (C-LOOK); mixing the two is the classic error.


1. I/O Devices, Subsystem and Transfer Methods

1.1 I/O Subsystem

I/O subsystem (PYQ 2023-24, 2 marks): the layered collection of hardware and software that mediates between the CPU and peripheral devices — device controllers, device drivers, interrupt handlers, buffers/caches, DMA controllers and the kernel I/O framework. It hides device-specific details from user processes and provides a uniform system-call interface.

Layer Role
User process Issues read/write system calls
Kernel I/O subsystem Buffering, caching, spooling, error handling, device allocation
Device driver Translates generic requests to controller commands
Device controller Hardware that moves data between device and memory; raises interrupts
Device Disk, keyboard, printer, network card, etc.

Device types: character devices (keyboard, mouse — byte stream) and block devices (disk, SSD — addressable blocks); also network devices and timers.

1.2 Polling, Interrupt-Driven I/O and DMA

PYQ (2025-26, 7 marks): "Explain the following in detail: i. Direct Memory Access ii. Interrupt iii. Polling."

Method How CPU learns data is ready CPU involvement Efficiency
Polling (programmed I/O) CPU repeatedly reads the controller's status/busy bit in a loop CPU waits and transfers every byte Very wasteful; simple hardware
Interrupt-driven I/O Controller raises an interrupt; CPU services an ISR and transfers data CPU does other work until interrupted; still transfers each byte Better than polling; per-byte interrupt overhead
DMA DMA controller transfers a whole block between device and memory; interrupts CPU only at completion CPU programs address/count once, then is free Best for bulk transfers; needs DMA controller and bus arbitration

DMA sequence: CPU writes memory address, byte count and direction into DMA registers → device transfers data directly to/from memory → DMA raises one interrupt on completion → CPU continues. The CPU is suspended for one bus cycle during each word transfer (cycle stealing).

Interrupt handling: device raises interrupt line → CPU finishes the current instruction, saves PC/state → jumps to the ISR via the interrupt vector → ISR services the device and acknowledges it → return from interrupt restores state. Interrupt priority and masking allow nested handling.

1.3 I/O Buffering

A buffer is a memory area holding data while it moves between two devices or between a device and a process. Purposes: handle speed mismatch (keyboard vs. disk), reduce interrupt frequency, allow block-sized transfers for character devices, and support spooling (holding print jobs on disk). Single buffering, double buffering (one filled while the other is consumed) and circular buffering are the common designs.


2. Disk Storage and Disk Scheduling

2.1 Disk Geometry and Access Time

        track / cylinder k
     +-----------------------------------+
     |  sector 1 |  sector 2 | ...       |   <- read/write head on an arm
     +-----------------------------------+

Seek time = time to move the arm to the target cylinder (dominant cost).
Rotational latency = time for the desired sector to rotate under the head; average ≈12\approx \dfrac{1}{2} revolution.
Transfer time = time to read the sector's bits.
Disk access time = seek + rotational latency + transfer.

PYQ (2025-26, 2 marks): "Explain seek time and rotational latency while accessing the disk." Seek = arm movement to the correct track/cylinder; rotational latency = waiting for the platter to rotate the desired sector beneath the head. At 7200 RPM one revolution is 8.33 ms, so average latency ≈ 4.17 ms.

2.2 HDD vs. SSD

PYQ (2023-24, 7 marks): "Compare and contrast different disk storage technologies, such as HDDs and SSDs?"

Feature HDD SSD
Medium Rotating magnetic platters NAND flash cells
Access Mechanical seek + rotation (~ms) Pure electronics (~µs)
Random I/O Slow Very fast
Sequential throughput Moderate (~150 MB/s) High (~500 MB/s+)
Durability Vulnerable to shock Shock-resistant, no moving parts
Power / noise Higher, audible Lower, silent
Write endurance Effectively unlimited rewrites Limited program/erase cycles (wear levelling)
Cost per GB Low Higher
Best use Bulk archival storage OS, databases, laptops

2.3 Scheduling Algorithms

Algorithm Service order Property
FCFS arrival order Fair, may have large movement
SSTF nearest cylinder to current head Good but may starve far requests
SCAN (elevator) sweep one direction serving all, then reverse No starvation; ends at cylinder edge
C-SCAN sweep one direction, wrap directly to opposite edge, continue same direction More uniform wait; wrap counts as large jump
LOOK like SCAN but reverses at last request, not at edge Less movement than SCAN
C-LOOK like C-SCAN but wraps to lowest pending request Uniform waits without edge travel

2.4 Solved: C-SCAN and C-LOOK Head Movement

Predicted (bank PRED, 2024-25 & 2025-26, 7 marks): "Queue: 47, 38, 121, 191, 87, 11, 92, 10; head at 63 moving toward larger cylinders; cylinders 0–199. Find total head movement for C-SCAN and C-LOOK."

Sorted requests: 10, 11, 38, 47, 87, 92, 121, 191.

C-SCAN service order: 87 → 92 → 121 → 191 → 199 → 0 → 10 → 11 → 38 → 47.

Move Distance
63 → 87 24
87 → 92 5
92 → 121 29
121 → 191 70
191 → 199 (end of disk) 8
199 → 0 (wraparound) 199
0 → 10 10
10 → 11 1
11 → 38 27
38 → 47 9

Total C-SCAN = 24+5+29+70+8+199+10+1+27+9 = 382 cylinders.

C-LOOK service order: 87 → 92 → 121 → 191 → 10 → 11 → 38 → 47 (no travel to 199/0; jump directly from highest to lowest request).

Move Distance
63 → 87 24
87 → 92 5
92 → 121 29
121 → 191 70
191 → 10 (wrap to first pending request) 181
10 → 11 1
11 → 38 27
38 → 47 9

Total C-LOOK = 24+5+29+70+181+1+27+9 = 346 cylinders.

Conclusion: C-LOOK saves 36 cylinders by not travelling to the physical edges; both avoid the starvation of SSTF.


3. RAID (Redundant Array of Independent Disks)

RAID: a scheme that combines several physical disks into one logical unit to improve performance (parallel I/O), reliability (redundancy) or both. Data is distributed using striping, mirroring and/or parity.

PYQ (2025-26, 7 marks): "What are the advantages of using RAID architecture in disk drive? Explain in detail." Advantages: (1) higher throughput via striping across multiple spindles; (2) fault tolerance — continued operation after a disk failure; (3) larger logical capacity and transparent capacity expansion; (4) hot spares and faster rebuild; (5) improved mean time to data loss. Trade-offs: extra disks cost, parity-update overhead on writes, controller complexity.

PYQ (2024-25, 7 marks): "Discuss RAID 0, RAID 1, and RAID 5 in detail."

Level Layout Minimum disks Fault tolerance Read / write performance Usable capacity
RAID 0 Block-level striping, no redundancy 2 None — one failure loses all data Best read/write; parallel access N×DN \times D
RAID 1 Mirroring: identical copy on each disk 2 Can survive N−1N-1 failures Fast reads, writes to all mirrors N×D/2N \times D / 2 (for 2 disks: DD)
RAID 5 Block striping + distributed parity 3 Survives one disk failure Fast reads; writes slower due to parity read-modify-write (N−1)×D(N-1)\times D

RAID 5 parity idea: for stripe blocks B0,B1,B2B_0,B_1,B_2: P=B0⊕B1⊕B2P = B_0 \oplus B_1 \oplus B_2. If B1B_1 is lost, recover it as B1=B0⊕P⊕B2B_1 = B_0 \oplus P \oplus B_2. Parity is rotated among disks so no single disk is a bottleneck. RAID 6 adds a second independent parity → survives two failures.


4. File System: Concepts, Organization and Directories

4.1 File Concept and Operations

File: a named collection of related information stored on secondary storage. Attributes include name, type, size, location, timestamps, owner, permissions and access control list. Operations: create, open, read, write, seek, delete, truncate, rename, append, close.

Access mechanisms:

  • Sequential access: read records in order (tape model); read_next.
  • Direct/random access: read(n) using a logical record number; essential for databases.
  • Indexed access: an index block maps keys to block addresses; combines both.

4.2 File Allocation Methods

PYQ (2023-24, 7 marks): "Discuss the organization of files within file systems, including contiguous, linked, and indexed allocation methods?"

Method Description Advantage Disadvantage
Contiguous File occupies consecutive blocks; directory stores start + length Fast sequential and direct access; simple External fragmentation; file cannot grow in place
Linked Each block holds data + pointer to next block; directory stores first block No external fragmentation; grows easily Slow direct access (O(n)O(n) pointer chasing); pointer overhead; pointer loss = data loss
Indexed One index block holds pointers to all data blocks; directory stores index address Direct access + no external fragmentation Index-block overhead; large files need multi-level indexes
FAT Linked list of block pointers stored in a separate table Improves linked allocation for random access FAT must be cached; table size grows with disk

Free-space management: bit map (one bit per block, fast but memory cost) or free block list/linked list (space-efficient, slower).

4.3 File Directories

PYQ (2024-25, 7 marks): "Explain file directories and directory structures in operating systems." PYQ (2023-24, 7 marks): "Explain the structure and management of file directories, including hierarchical and flat directory structures?"

A directory is a special file whose entries map file names to file control blocks/inodes. Operations: search, create file, delete file, list, rename, traverse.

Structure Layout Pros Cons
Single-level / flat One directory for all files Simple; supports one user Name collisions; no grouping
Two-level One directory per user Solves collisions between users No subdirectories within a user
Tree (hierarchical) Root with nested subdirectories Logical grouping, unique path names, easy protection Long path traversal; sharing needs links
Acyclic graph Tree + shared subdirectories/files (links) True sharing without duplication Cycle avoidance needed; link maintenance
General graph Arbitrary cycles allowed Maximum flexibility Garbage collection and cycle detection required
                       /  (root)
               +-------+--------+
             /home   /etc      /tmp
             /  |     |
        alice  bob  passwd
          /  |
       notes  project

Path names: absolute /home/alice/notes vs. relative notes from the current working directory. File sharing is via symbolic links (path stored) or hard links (same inode; reference count). UNIX permissions use owner/group/other with read/write/execute bits.

4.4 Implementation and Protection Issues

  • On-disk layout: boot block, volume control block (superblock), directory structure per volume, file data blocks, free-space structure.
  • In-memory structures: mount table, directory cache, open-file table with file descriptors and access counts, buffer cache.
  • Volatile vs. non-volatile: metadata writes must be ordered (journaling/log-structured FS) so a crash does not corrupt the directory.
  • Protection/security: access-control lists, UNIX mode bits, capability lists, encryption, authentication; file sharing must respect these permissions and prevent unauthorized deletion.

5. Exam-Ready and Practice Questions

Model answers at a glance

Question (source) Answer skeleton
RAID advantages (2025-26, 7m) striping + redundancy + capacity + hot spare + trade-offs
RAID 0/1/5 (2024-25, 7m) three-row layout table + XOR recovery formula
HDD vs SSD (2023-24, 7m) seven-row comparison table
Seek & rotational latency (2025-26, 2m) definitions + 7200 RPM average
DMA / interrupt / polling (2025-26, 7m) three-row transfer-method table + DMA sequence
I/O subsystem (2023-24, 2m) layered definition
Directory structures (2023-24/24-25, 7m) five-row structure table + tree diagram + path names
Allocation methods (2023-24, 7m) contiguous/linked/indexed table + free-space note
C-SCAN / C-LOOK (predicted, 7m) sorted queue, service order, distance table, totals 382 / 346

Practice questions (label: practice, not real PYQs)

  1. Practice: Repeat the disk example for SSTF and LOOK; compare totals with 382/346.
  2. Practice: A disk rotates at 10,000 RPM. Compute one revolution and the average rotational latency. (6 ms; average 3 ms.)
  3. Practice: Why can RAID 5 survive exactly one disk failure but RAID 6 two? Write the parity expressions.
  4. Practice: Show how a 10-block file is stored under contiguous, linked and indexed allocation, and count the block reads needed to access block 7.
  5. Practice: Explain why a symbolic link can dangle while a hard link cannot.

6. Last-Night Survival Checklist (Unit 5 only)

  1. Two numbers to remember: C-SCAN = 382 cylinders, C-LOOK = 346 cylinders for the standard 8-request queue from cylinder 63.
  2. RAID table: 0 = striping/no fault tolerance, 1 = mirroring, 5 = distributed parity (N−1)D(N-1)D; know the XOR recovery line.
  3. Transfer methods: polling (CPU loops), interrupt (ISR per event), DMA (one interrupt per block).
  4. Directory types: flat → two-level → tree → acyclic graph → general graph, with one advantage and one problem each.
  5. Timing definitions: seek = arm motion, rotational latency = half a revolution on average, access = seek + latency + transfer.

Final I/O reminder: For a 7-mark RAID answer, always name the minimum disk count and usable capacity, not just the concept; for a disk-scheduling numerical, show the service order before summing distances. These two habits convert partial answers into full-score answers.