There are two ways to move data between a device and memory. In programmed I/O (PIO), the CPU itself reads or writes every word through registers. In direct memory access (DMA), a DMA controller moves the data on its own, and the CPU only sets up the transfer and is notified when it is done. DMA frees the CPU and handles large transfers much faster, but it needs more setup and care.
Aspect
Programmed I/O (PIO)
DMA
Who moves the data
The CPU, word by word, with load and store instructions
A DMA controller or the device itself, directly to or from memory
CPU load
High: the CPU is busy during the whole transfer
Low: the CPU sets up the transfer and does other work
Throughput for large transfers
Limited by the CPU speed
High
Setup overhead
None
Needs an address, a length or descriptors, and completion handling
Small transfers
Often faster, because there is no setup
The setup cost can outweigh the benefit
Complexity
Simple
More complex: descriptor rings, buffer alignment, cache coherency and IOMMU settings
Memory bus use
Through the CPU
The DMA engine competes with the CPU for memory bandwidth
Typical uses
Small control registers, simple sensors, legacy PIO modes
Figures are typical orders of magnitude and vary by process generation and product.
When to use which
PIO
When transfers are tiny or rare, and simplicity matters more than CPU time.
DMA
When transfers are large or continuous and you do not want the CPU tied up: storage, networking, streaming data.
Watch out
With DMA, make sure the CPU cache and memory agree before the device reads or after it writes (flush or invalidate the cache, or use coherent memory).
FAQ
Why does DMA reduce the CPU load?
A DMA controller moves the data itself, so the CPU only sets up the transfer and is notified when it is done.
Is DMA always faster?
No. For tiny transfers the setup cost can outweigh the benefit, and programmed I/O can be faster.
What is a DMA descriptor ring?
A ring of descriptors in memory, each describing a buffer. The device and the driver pass buffers back and forth through it, as in network cards and NVMe drives.
Why does cache coherency matter with DMA?
The device reads and writes memory directly, so the CPU cache may hold stale data. Software must flush or invalidate the cache, or use coherent memory.
AThe CPU transfers data by writing it byte by byte into device registers
BThe CPU only writes addresses and lengths into descriptors and notifies the device, which reads them and carries out the transfers itself
CDescriptors exist only inside the device and are invisible to the CPU
Show answer and explanation
Answer: B. The CPU only writes addresses and lengths into descriptors and notifies the device, which reads them and carries out the transfers itself
A descriptor ring is a table in main memory, used in a circular way, where each entry says which address to transfer and how many bytes. The CPU fills free descriptors and tells the device once, through a register, how far it has written. The device reads the descriptors by DMA, transfers the data and either marks finished descriptors as complete or writes completions to a separate completion ring (such as an NVMe completion queue). CPU and device can advance many transfers without waiting for each other.
CThe CPU need not read each result in an interrupt; DMA stores them in memory, reducing CPU load
Show answer and explanation
Answer: C. The CPU need not read each result in an interrupt; DMA stores them in memory, reducing CPU load
If the CPU reads each conversion in an interrupt, at tens of thousands of samples per second the overhead of entering and leaving interrupts alone can consume a large share of its time. With DMA, each completed conversion is written in turn into an array in memory, and the CPU is notified only when the array is full. Combined with a timer that triggers conversions, precisely spaced sampling continues without the CPU.
A mechanism that transfers data directly between peripherals and memory without going through the CPU, so the CPU can do other work during large transfers.
A CPU mechanism that temporarily suspends the current task to handle a request, for example from an external device, and then returns to the original task.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.