Direct memory access (DMA) is a technology that is used by computers to increase speed and efficiency by allowing input-output devices to access RAM directly without involving the CPU. Before the use of DMA, computers used to fully involve the processor in the whole process of sending and receiving data from input and output devices. It started with programmed input/output and then interrupt and then later DMA.
When using programmed input/output, the processor sends the request to the input/output module to transfer data and then keeps checking if the transfer is done. This keeps the CPU busy checking whether the transfer is done. This reduces the overall performance of the computer.
When the system uses interrupt the CPU initiates the process of data transfer by sending the instruction to the I/O module then it moves to execute other processes. Once the transfer is done the I/O module sends an interrupt to the processor to inform it that the process of data transfer is over. The CPU acknowledges and continues from where it left by using the transferred data.
How direct memory access (DMA) works
DMA is an improvement from the programmed I/O and interrupts techniques of transferring data from the main memory to the I/O module.
DMA is mostly used with devices that require faster and more bulky data transfer. It is mostly implemented on storage disk drives, graphic card controllers, sound cards, network cards, and intra-chip transfer in multi-core computers.
When the input/output device wants to transfer data to or from the RAM, the processor initiates the process by sending the details of the operation to the DMA controller of what to be moved to and from where. After the instruction, the CPU goes on to execute other different processes.
The controller takes over and initiates the process of data transfer by sending the signal to the device controller (disk controller). The data is transferred from the disk to the RAM address until it is complete.
Once the data transfer is completed the disk controller sends an acknowledgment to the DMA controller that the transfer is complete. After the acknowledgment, the DMA controller sends an interrupt to the processor to signal that the task assigned of transferring data is done. The CPU acknowledges and continues from where it left off.
This is a control unit circuity that can transfer data between the RAM and the I/O device without the involvement of the CPU. Any system that implements the DMA must have this hardware control unit for operations
All these operations of DMA are carried out by the DMA controller which does all the work.
Advantages of direct memory access (DMA)
- They improve the overall performance of the whole system. The processor will have more time to execute other processes.
- They reduce CPU overhead when data is being transferred. Most of the overhead work is left to the DMA controller.
- CPU and DMA work concurrently. DMA will be transferring data while the CPU is executing.
- Increase the speed of data transfer from the main memory to the I/O module
Disadvantages of DMA
- It is expensive to implement both hardware and software.
- The DMA controller and the device controller must be able to communicate with each other.
- Cache coherence problem. This is a problem that occurs when the DMA changes the content of the RAM that is already cached by the processor. This means the RAM and cache data are different.
- DMA can be exploited to breach security and access data within the computer’s RAM.