OS Notes
Understanding DMA — how data transfers bypass the CPU, DMA controller operation, modes of DMA transfer, and why DMA is essential for high-speed I/O devices.
Introduction
Without DMA, every byte of data transferred between a device and memory would pass through the CPU — the CPU reads from the device register, stores to memory, reads the next byte, stores again, millions of times. For a large file transfer, the CPU would spend all its time shuttling bytes instead of doing useful computation. DMA solves this by providing a separate hardware unit that handles data transfers directly between devices and memory, freeing the CPU for other work.
Think of it this way: without DMA, the CEO (CPU) personally carries every package between the mailroom (device) and the office (memory). With DMA, the CEO hires a delivery person (DMA controller) to handle packages, and just signs off when they are done.
How DMA Works
DMA Transfer Steps
DMA Controller Architecture
| Address Reg | Memory Address Reg | |||
|---|---|---|---|---|
| (device side) | (where in RAM) | |||
| Count Reg | Control/Status Reg | |||
| (bytes left) | (direction, mode) |
DMA Transfer Modes
Burst Mode
DMA takes control of the bus and transfers the entire block at once. CPU cannot use the bus until the transfer completes. Fast for the DMA, but blocks CPU memory access temporarily.
Cycle Stealing
DMA transfers one word at a time, then releases the bus. CPU and DMA alternate bus access. Slower overall but CPU is never blocked for long.
Transparent Mode
DMA transfers data only when the CPU is not using the bus (during instruction decode phases). No performance impact on CPU but transfer is slow.
When DMA is Used
DMA is essential for high-bandwidth devices:
- Disk I/O: Reading/writing files (megabytes per transfer)
- Network: Receiving/sending packets (gigabits per second)
- Graphics: Transferring frame buffers (millions of pixels)
- Audio: Streaming audio data to sound card
- USB bulk transfers: Large file copies
For low-bandwidth devices (keyboard, mouse), programmed I/O or simple interrupts suffice — the data rate is so low that DMA setup overhead is not justified.
DMA vs Programmed I/O Performance
| Example | Transfer 1 MB from disk to memory |
| - CPU programs DMA | ~10 instructions = 10 ns |
| - DMA handles 1 MB transfer | ~1 ms (bus speed limited) |
| - CPU interrupt handling at end | ~1 μs |
| - CPU busy time | ~1.01 μs (vs 2.1 ms without DMA) |
Real-World Analogy
DMA is like hiring a moving company. Without DMA (programmed I/O), you personally carry every box between the truck and your apartment — exhausting and you cannot do anything else. With DMA, you tell the movers "put everything from the truck into the living room" and go about your day. They interrupt you (ring the doorbell) only when finished. The moving company (DMA controller) uses the elevator (bus) independently, though sometimes you need to wait briefly if they are using it (cycle stealing).
Key Takeaways
- DMA transfers data between devices and memory without CPU involvement
- The CPU only sets up the transfer and handles the completion interrupt
- For a 1 MB transfer, DMA frees the CPU for 99.9% of the time vs programmed I/O
- Three modes: burst (fastest, blocks CPU briefly), cycle stealing (interleaved), transparent (no impact)
- Essential for high-bandwidth devices: disks, networks, graphics, audio
- Modern systems use bus-mastering DMA where the device itself contains DMA capability
- DMA is why your computer can download files while you continue working smoothly
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for DMA - Direct Memory Access.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, input, output, dma, direct
Related Operating Systems Topics