What Is Direct Memory Access (DMA) and How Does It Work? [MiniTool Wiki]
You can adopt the RDMA technology to enable computers in a network to exchange data in the main memory without involving the processor, cache or operating system of either computer. But you can also use the DMA feature to directly send data from an attached device to the memory on the computer’s motherboard. This post from MiniTool is mainly talking about DMA.
The Definition of Direct Memory Access
First of all, what is Direct Memory Access? Direct Memory Access can be abbreviated to DMA, which is a feature of computer systems. It allows input/output (I/O) devices to access the main system memory (random-access memory), independent of the central processing unit (CPU), which speeds up memory operations.
Without Direct Memory Access, when the CPU uses programmed inputs/outputs, it is usually fully occupied during the entire read or write operation, so it cannot perform other tasks. With DMA, the CPU first initiates the transfer, then performs other operations while the transfer is in progress, and finally receives an interrupt from the DMA controller (DMAC) when the operation is complete.
Direct Memory Access is useful whenever the CPU cannot keep up with the data transfer rate, or when the CPU needs to perform work while waiting for relatively slow I/O data transfers.
Multiple hardware systems adopt Direct Memory Access, such as disk drive controllers, graphics cards, network cards, and sound cards. DMA is also used for on-chip data transfer in multi-core processors. Compared to computers without Direct Memory Access channels, computers with DMA channels can transfer data between devices with much less CPU overhead.
Direct Memory Access can also be used for “memory to memory” to copy or move data in memory. It can transfer expensive memory operations (such as large copies or scatter-gather operations) from the CPU to a dedicated DMA engine. DMA is important in network-on-chip and memory computing architectures.
How Does Direct Memory Access Work?
Then how does Direct Memory Access work? Standard Direct Memory Access (also called third-party DMA) adopts a DMA controller. The DMA controller can produce memory addresses and launch memory read or write cycles. It covers multiple hardware registers that can be read and written by the CPU.
These registers consist of a memory address register, a byte count register, and one or more control registers. Depending on the features provided by the Direct Memory Access controller, these control registers can appoint some combination of source, destination, transfer direction (read from or write to I/O device), size of the transfer unit, and/or the number of bytes to transfer in one burst.
To perform input, output, or memory-to-memory operations, the host processor initializes the DMA controller with the number of words to transfer and the memory address to use. Then the CPU commands the peripheral device to begin data transfer.
Then the Direct Memory Access controller offers addresses and read/write control lines to the system memory. Each time a byte of data is prepared to be transferred between the peripheral device and the memory, the DMA controller increments its internal address register until a complete data block is transferred.
Modes of Operation
Direct Memory Access works differently in different modes of operation.
Burst Mode
In burst mode, the full data block is transmitted in a continuous sequence. Once the CPU allows the DMA controller to access to the system bus, the DMA controller will transfer all bytes of data in the data block before releasing control of the system buses back to the CPU, but it will cause the CPU to be inactive for a considerable long time. This mode is also called “Block Transfer Mode”.
Cycle Stealing Mode
The cycle stealing mode is used in a system where the CPU cannot be disabled for the length of time required for the burst transfer mode. In the cycle stealing mode, the DMA controller obtains the access to the system bus by using the BR (Bus Request) and BG (Bus Grant) signals, which are the same as the burst mode. These two signals control the interface between the CPU and the DMA controller.
On the one hand, in the cycle stealing mode, the data block transmission speed is not as fast as in the burst mode, but on the other hand, the CPU idle time is not as long as in the burst mode.
Transparent Mode
The transparent mode takes the longest time to transfer data blocks, but it is also the most efficient mode in terms of overall system performance. In transparent mode, the Direct Memory Access controller transfers data only when the CPU performs operations that do not use the system buses.
The main advantage of transparent mode is that the CPU never stops executing its programs, and Direct Memory Access transfers are free in terms of time, while the disadvantage is that the hardware needs to determine when the CPU is not using the system buses, which can be complicated. This is also called “hidden DMA data transfer mode”.