Storage Devices
Lecture Notes for CS 140
Winter 2012
John Ousterhout
- Readings for this topic from Operating System Concepts:
Sections 12.1-12.2.
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 data as it passes 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, buffer)
write(startSector, sectorCount, buffer)
- In the old days the track and surface structure of the disk was
visible to software:
read(track, sector, surface, sectorCount, buffer)
- 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.
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 general purposes:
- Parameters provided by CPU to device (e.g. number
of 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.
- On some machines special instructions are used to access
device registers and initiate I/O, rather than reading
and writing special memory locations.
- 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 might not be able to
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 into memory.
- When transfer complete, device issues an interrupt
to the system.
- Today DMA is the norm for I/O devices (controller
hardware is cheap).
Flash Memory
- Solid state (semiconductor) storage, replacing disks in many
applications (e.g. phones and other devices). Primary advantages:
- Nonvolatile (unlike DRAM): values persist even if
device is powered off
- No moving parts (less likely to break)
- Faster access than disk
- More shock-resistant than disk
- 5-10x more expensive than disk
- Two styles, NAND and NOR; NAND is most popular today:
- Each device is divided into blocks, which are
subdivided into pages.
- Typical block sizes: 16-256 KBytes
- Typical page sizes: 512-4096 bytes
- Total capacity: up to 16 GBytes/chip
- Unit of reading and writing is pages
- Two significant quirks:
- Before rewriting a page, its entire block must be
erased; this is a separate operation.
This makes random-access updates expensive.
- Wear-out: once a block has been erased about 100,000
times it no longer stores information reliably
- The ideal way to use flash memory:
- Write entire blocks: don't update individual pages in
existing blocks (too slow, wears out blocks too fast).
- Wear leveling: manage device so all blocks get
erased at roughly the same rate. Must avoid hotspots.
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.