Linux online course

Direct Memory Access (DMA) in Linux

Learn how DMA transfers data between peripherals and RAM, why it reduces CPU overhead, and how to inspect legacy DMA channels with /proc/dma.

Direct Memory Access (DMA) is a hardware-assisted method for transferring data between a peripheral device and system memory. With DMA, a device or DMA controller can move data to or from RAM without requiring the CPU to copy every byte.

This lesson explains the difference between DMA and CPU-managed I/O, the lifecycle of a DMA transfer, legacy DMA channels on x86 systems, and the limits of /proc/dma on modern computers.

What DMA Means

DMA is short for Direct Memory Access. It allows hardware to transfer data directly between a peripheral and RAM with limited CPU intervention.

For example, when a storage controller reads data, the controller can place that data into a region of RAM. When a network card receives a packet, it can write the packet into a memory buffer prepared by its driver. The CPU starts and coordinates the operation, but it does not need to execute a separate copy operation for every byte.

I/O means input/output: communication between the computer and a device. Traditional device communication may use an I/O port, which the CPU reads or writes directly. DMA instead lets hardware perform a larger memory transfer after software has configured the operation.

CPU-Managed I/O Versus DMA

In CPU-managed, or programmed, I/O, the processor repeatedly interacts with the device and moves data itself. A large transfer can require many processor instructions and frequent device accesses.

With DMA, software prepares the transfer and hardware performs the data movement. The CPU can continue other work while the transfer is in progress, then respond when the device reports completion.

CharacteristicCPU-managed I/ODMA
Who moves dataThe CPU reads from or writes to the device and copies the data.A DMA-capable device or DMA controller moves data between the device and RAM.
CPU involvement during transferUsually high; the CPU handles repeated transfer operations.Usually limited after setup; the CPU can perform other work.
Typical performance impactMore CPU overhead, especially for large or frequent transfers.Lower CPU overhead and potentially better overall throughput.
Typical use contextSimple operations, small transfers, or devices without DMA support.Storage, networking, audio, graphics, and other high-volume I/O.

Why Linux and Hardware Use DMA

Devices often transfer blocks of data rather than one value at a time. If the CPU had to manage every part of a large transfer, useful processor time would be spent on routine copying and device polling.

DMA reduces this overhead. The CPU can:

  • Allocate or select a memory buffer.
  • Tell the device where the buffer is located.
  • Specify the transfer direction, length, and other device-specific settings.
  • Start the operation and schedule other work.
  • Handle a completion notification or error later.

Reducing CPU work does not make the device itself infinitely faster. It means the processor is less occupied with transfer mechanics, which can improve system responsiveness and leave more CPU capacity for applications, filesystem work, or other devices.

The DMA Transfer Lifecycle

  1. Software prepares the operation. A Linux device driver obtains a suitable memory buffer and configures the device. The configuration includes the memory location, transfer length, direction, and device-specific control information.
  2. The CPU or driver starts the transfer. The processor writes setup information to the device or to a DMA controller.
  3. The DMA-capable hardware transfers data. Depending on the direction, the peripheral writes data to RAM or reads data from RAM. A separate DMA controller may coordinate the transfer, or the peripheral may contain its own DMA engine.
  4. The CPU performs other work. It does not need to copy every byte while the hardware transfer proceeds.
  5. Completion is reported. The device commonly raises an interrupt, a hardware notification to the CPU. The driver then checks the result, handles errors, and makes the buffer available for the next step.

In simplified form, the path is:

CPU/driver: configure buffer, direction, and length
                 |
                 v
Peripheral <--- DMA-capable hardware ---> RAM
                 |
                 v
CPU: receive completion interrupt and process the result

Legacy DMA Channels on x86 Systems

A DMA channel is a numbered hardware resource used to identify or coordinate a DMA transfer path. Older x86-compatible computers commonly provided legacy DMA hardware associated with the ISA bus. A channel could be assigned to a device or controller for a particular kind of DMA activity.

These channels are different from modern device-specific DMA engines. Legacy hardware had a relatively small, visible set of numbered channels, so conflicts could occur if two incompatible devices were configured to use the same channel.

Linux can expose assignments for these legacy resources through procfs, the virtual filesystem that provides kernel and system information in files under /proc.

Viewing DMA Assignments with /proc/dma

Run the following command to display legacy DMA channel assignments exposed by the kernel:

cat /proc/dma

To check that the file is readable before displaying it, use:

test -r /proc/dma && cat /proc/dma

A sample listing might look like this:

2: device-a
4: device-b

The number at the beginning of each line is the DMA channel. The text after the separator identifies the device, driver, or component that has registered or reserved that channel.

Output fieldMeaningExample interpretation
Channel numberThe legacy numbered DMA resource.2 identifies channel 2.
Assigned device or driver nameThe component registered as using or reserving the channel.device-a is associated with channel 2.
Legacy statusThe entry represents information about legacy DMA assignments, not every DMA operation in the system.The listing should not be treated as a complete inventory of modern PCIe DMA.

Listed channels are currently registered or reserved legacy assignments. Do not assume that an unlisted channel is safe for arbitrary manual use; the output is only one part of the system's hardware resource information.

Legacy and Modern DMA Models

ModelTypical hardwareHow resources are identifiedVisibility in /proc/dma
Legacy ISA-style DMAOlder ISA-compatible peripherals and controllers.Numbered DMA channels and other legacy hardware resources.May appear as channel assignments when the kernel and platform expose them.
PCI/PCIe bus-master DMAModern storage, network, graphics, and other PCI or PCIe devices.Device-specific DMA engines, bus-master transactions, driver-managed buffers, and platform address translation.Usually not represented by the legacy numbered list.

Bus mastering is the ability of a device, especially a PCI or PCIe device, to initiate memory transactions directly. Many contemporary devices use bus-master DMA rather than the old, shared numbered channels.

Modern Linux drivers also work with memory mapping and, where present, an IOMMU. An IOMMU is a hardware memory-management unit that can translate and restrict the addresses a device may use for DMA. The driver, kernel DMA APIs, device controller, and platform firmware may all contribute to how a modern transfer is configured.

DMA Resource Conflicts

A legacy DMA channel must not be assigned to incompatible devices at the same time. A similar rule applies to other hardware resources, such as address ranges. If two devices use the same resource without compatible coordination, their transfers can interfere.

Possible consequences include:

  • A device that fails to start or stops responding.
  • Transfers that fail or produce incorrect data.
  • Memory corruption if data is written to an unintended location.
  • System instability, hangs, or intermittent errors.

Manual resource assignment is mainly a concern for older hardware, ISA-style devices, and legacy configurations. Modern PCI and PCIe systems normally obtain resource information through platform firmware and configure devices through their drivers rather than asking an administrator to select a legacy DMA channel manually.

Troubleshooting /proc/dma

The file is empty

An empty result can be normal. The system may have no registered legacy DMA channels, while modern devices continue to use PCIe bus-master DMA or another platform-specific mechanism.

test -r /proc/dma && cat /proc/dma

Do not conclude that DMA is disabled merely because no lines are printed. If a particular device is failing, investigate its driver, device-specific diagnostic information, and relevant system logs.

The file does not exist or cannot be read

Kernel configuration, architecture, or platform support may prevent legacy DMA information from being exposed through this procfs entry. Treat /proc/dma as a legacy diagnostic interface, not as a universal DMA status file.

A legacy device fails after a manual change

The device may have been assigned a DMA channel or address range already reserved by another component. Review the hardware documentation and ensure that legacy resource assignments do not overlap. Avoid changing resources casually on a working system.

Expecting all DMA activity in the listing

/proc/dma does not list all DMA activity from storage, networking, graphics, PCI, PCIe, or platform-specific devices. Modern DMA is usually visible through the relevant driver and device-management tools rather than as a legacy channel number.

Exam-Relevant Notes

  • DMA stands for Direct Memory Access.
  • DMA lets hardware transfer data between a peripheral and RAM with limited CPU intervention.
  • The CPU normally configures and starts the transfer, then handles completion, often through an interrupt.
  • DMA reduces CPU overhead during large or frequent I/O transfers; it does not eliminate the need for a device driver.
  • /proc/dma primarily reports legacy DMA channel assignments.
  • An empty /proc/dma does not prove that a system does not use DMA.
  • Modern PCI and PCIe devices commonly use bus-master DMA, device-specific engines, driver-managed memory mappings, and sometimes an IOMMU.
  • Conflicting legacy resource assignments can cause device failures, corruption, or instability.

Summary

DMA is a hardware-assisted I/O technique that allows a peripheral or DMA controller to move data directly to or from RAM. The CPU configures the operation and receives the completion result, but it does not have to copy each byte. This reduces processor overhead and can improve overall system performance.

Linux's /proc/dma command-line view is useful for checking legacy numbered DMA channels:

cat /proc/dma

Its output is intentionally narrow. Modern computers may show no entries even while their storage, network, or other devices actively use DMA through PCIe bus mastering and driver-specific mechanisms.