Storage Devices
Lecture Notes for CS 140
Spring 2014
John Ousterhout
- Readings for this topic from Operating Systems: Principles and Practice:
Section 12.1.
Magnetic Disk (Hard Drive)
- Basic geometry:
- 1-5 platters, magnetically coated on each surface
- Platters spin at 5000-15000 RPM
- Actuator arm positions heads, which can
read and write data on the magnetic surfaces.
- Overall size of disk package: 1-8 inches.
- Organization of disk data:
- Circular tracks corresponding to a particular
position of the actuator arm.
- Typical density today: 200,000 tracks per radial inch.
- Tracks divided into 512-byte sectors. Typical
tracks contain a few thousand sectors.
- Typical total drive capacities: 100GB-2TB
- 100GB ~ 50M double-spaced pages of text.
- Disk technology is one of the most rapidly advancing
technologies: capacities increasing faster
than Moore's Law.
- Reading and writing:
- Seek: move actuator arm to position heads over
desired track. Typical seek time: 2-10ms.
- Select a particular head.
- Rotational latency: wait for desired sector
to pass under the head. One-half disk rotation on
average (4ms @ 7500RPM)
- Transfer: read or write one or more sectors as they pass under the head.
Typical transfer rates: 100-150 MBytes/sec.
- Latency refers to the sum of seek time plus rotational
latency; typically 5-10ms.
- API for disks:
read(startSector, sectorCount, physAddr)
write(startSector, sectorCount, physAddr)
- In the old days the track and surface structure of the disk was
visible to software:
read(track, sector, surface, sectorCount, physAddr)
- Nowadays the track structure is hidden inside the disk:
- Inner tracks have fewer sectors than outer tracks
- If some sectors are bad, disk software automatically
remaps them to spare sectors.
Reel-to-Reel Magnetic Tape
- Old technology, popular in the 1960s and 1970s.
- Magnetic tape:
- 9 tracks across tape (one byte plus parity),
- 1/2" wide by 2400 feet long
- Variable-length records (20-30000 bytes); read or
write blocks, but cannot write in middle
- Recording density up to 6250 bytes/inch (180 MBytes
max for a tape)
- Tape moves at 20-200 inches/sec. (up to a few Mbytes/sec.)
- Interesting physical design, such as vacuum columns
to buffer tape during fast start and stop.
Communicating with I/O Devices
- Device registers:
- Each device appears in the physical address space
of the machine as a few words, called device registers.
- The operating system reads and writes device registers
to control the device.
- Bits in device registers serve 3 purposes:
- Parameters provided by CPU to device (e.g. number
of first sector to read)
- Status bits provided by device to CPU (e.g. "operation
complete" or "error occurred").
- Control bits set by CPU (e.g. "start disk read") to
initiate operations.
- Device registers don't behave like ordinary memory
locations:
- "Start operation" bit may always read as 0.
- Bits may change without being written by CPU
(e.g. "operation complete" bit).
- Programmed I/O: all communication with I/O device
occurs through the device registers.
- CPU writes device registers to start operation
(e.g., read)
- CPU polls ready bit in device register
- When operation is finished, device sets ready
- CPU reads data from one or more device registers,
writes data to memory.
- Problems with this approach:
- CPU wastes time waiting for data to become ready;
can only keep one device busy at a time.
- Expensive for CPU to mediate all data transfers;
with some fast devices CPU can't keep up with device.
- Interrupts: allow CPU to do other work while devices
are operating.
- CPU starts I/O operation, then works on other things.
- When device needs attention (operation completes) it
interrupts the CPU:
- A forced procedure call to a particular address in
the kernel.
- Operating system figures out which device interrupted,
services that device.
- Operating system returns from the interrupt back to
whatever it was working on.
- Interrupts make the operating system much more efficient;
for example, can keep many devices busy at the same time,
while also running user code.
- Direct Memory Access (DMA):
- Device can copy data to and from memory, without
help from the CPU.
- CPU loads buffer address into a device register
before starting operation (e.g., where to copy data
read from disk).
- Device moves data directly to/from memory.
- When transfer complete, device issues an interrupt
to the system.
- Today DMA is the norm for I/O devices (controller
hardware is cheap).