Operating Systems Lecture 20: Hard disk internals

Operating Systems Lecture 20: Hard disk internals

Understanding Hard Disks and Their Impact on Operating Systems

Overview of Hard Disk Functionality

  • The lecture discusses the role of hard disks in operating systems, emphasizing that storage mediums operate using blocks (or sectors), typically sized at 512 bytes. Reading or writing occurs only in full blocks.

Internal Structure of Hard Disks

  • A hard disk consists of one or more platters connected by a spindle that rotates at high speeds. Each platter has tracks divided into sectors, with a disk head moving along these tracks to access data.

Disk Access Mechanics

  • When accessing sectors, the disk head moves based on requests (e.g., read/write). If moving from sector 13 to sector 11, the head performs a seek operation to reach the correct track.
  • The time for an I/O operation includes seek time (moving the head), rotational latency (waiting for the desired sector), and transfer time (actual data movement). Seek and rotational latencies are significant contributors to overall delay.

Sequential vs. Random Data Transfer

  • Transferring data sequentially is faster than randomly due to reduced seek times and latencies. Random I/O can yield less than 1 MB/s compared to higher bandwidth during sequential I/O operations.

Disk Scheduling Optimization

  • Operating systems optimize disk access through scheduling algorithms that prioritize serving requests in a manner that maximizes sequential access while minimizing delays.
  • Requests do not need to be served in first come, first serve order; they can be reshuffled for efficiency. This approach helps maintain performance by reducing unnecessary seeks.

Scheduling Algorithms: Shortest Seek Time First

  • The operating system often relies on a disk controller for scheduling since it lacks detailed knowledge about sector locations.
  • One basic algorithm is Shortest Seek Time First, which serves requests closest to the current position of the disk head but may lead to starvation for distant requests.

Elevator Algorithm as an Improvement

Disk Scheduling Algorithms and Data Integrity

Elevator Algorithm Overview

  • The elevator algorithm operates by sweeping from the outer track to the inner track and back, serving any pending requests along its path. This back-and-forth movement ensures that all tracks are accessed without getting stuck in one area.

Variants of the Elevator Algorithm

  • The C-SCAN (Circular Scan) variant moves in one direction only, either from outer to inner or vice versa, preventing middle tracks from receiving excessive service time compared to others.
  • The F-SCAN variant freezes incoming requests while scanning, ensuring fairness and avoiding starvation by not allowing new requests to bypass older ones.

Shortest Positioning Time First Algorithm

  • Unlike previous algorithms that focus solely on seek time, the Shortest Positioning Time First algorithm considers both seek time and rotational latency when deciding which request to serve next.
  • For example, if a disk head is at position 30 with options for requests at 8 and 16, it evaluates both seek time and rotational latency before making a decision.

Error Detection and Correction in Disk Storage

  • Modern disks store additional bits alongside data bits (e.g., checksums or parity bits) to detect corruption or correct errors due to random bit flips.

Handling Disk Failures

  • Despite error correction measures, users may still experience hard disk failures. Techniques like blacklisting bad sectors can help manage these issues.
Video description

Based on the book Operating Systems: Three Easy Pieces (http://pages.cs.wisc.edu/~remzi/OSTEP/) For more information please visit https://www.cse.iitb.ac.in/~mythili/os/