October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Linux DMA API: How to Choose Between Coherent and Streaming Mappings

Coherent DMA suits shared control structures; streaming mappings suit transfer buffers with explicit direction and ownership changes. Learn the key API rules and pitfalls.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A dma_addr_t is an address for the device, not a CPU pointer and not necessarily a CPU physical address. The Linux DMA API can translate between device and memory address spaces, so drivers must use the address returned by DMA APIs and follow the mapping’s ownership rules.

Use coherent allocations for shared control structures that CPU and device access over time; use streaming mappings for transfer buffers whose ownership moves between them. The distinction affects allocation lifetime, cache visibility, synchronization, and error handling.

As an Amazon Associate I earn from qualifying purchases.

What a DMA address means

The DMA address is what the device uses to access memory. It may differ from the CPU physical address because an IOMMU or another platform mechanism can translate between address spaces. As the Linux DMA API reference puts it: “A CPU cannot reference a dma_addr_t directly because there may be translation between its physical address space and the DMA address space.” Keep the CPU’s virtual pointer and the device-facing dma_addr_t as separate values; never dereference the DMA address as if it were a CPU pointer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The choice between coherent and streaming mapping is primarily about how the buffer is used and who owns it at a given moment. Neither choice removes the need to respect device address limits or the device’s ordering requirements.

#1 Best Overall
Arduino® UNO™ Q 4GB [ABX00173]- Hybrid Board, Qualcomm Dragonwing QRB2210 microprocessor (MPU) & STM32U585 Microcontroller(MCU), AI Vision, Voice, IoT, Robotics, Linux Debian OS, Wi-Fi 5, USB-C
  • Dual-Brain Hybrid Power: Combines the Qualcomm Dragonwing QRB2210 MPU (Quad-core Arm Cortex-A53 @ 2.0 GHz CPU, Adreno GPU, AI acceleration) and the real-time, low-power STM32U585 MCU for advanced applications like object recognition, voice commands, and motion detection.
  • AI & Linux Capabilities: Unlocks AI-powered vision and sound solutions; runs Linux Debian OS for coding in Python and supports the Arduino ecosystem with libraries and Sketches; quick start with Arduino App Lab.
  • Advanced Features: Equipped with 4 GB LPDDR4 RAM, 32 GB eMMC built-in storage, ideal for single-board computer (SBC) mode, running multiple simultaneous high-level processes, more complex AI or ML models, extensive logs. Dual-band Wi-Fi 5 (2.4/5 GHz), Bluetooth 5.1, and high-speed headers for vision, audio, and display peripherals.
  • Seamless Expansion & Connectivity: Features the classic UNO form factor for shields compatibility, an 8x13 LED matrix, and a Qwiic connector for easy expansion with Modulino nodes; power and connect via the USB-C connector.
  • Intended Use & Development: The perfect platform for prototyping robotics or IoT projects, empowering innovators with a unified development experience to mix Arduino Sketches, Python scripts, and containerized AI models in a single interface.

Coherent allocations: shared control data

Coherent DMA allocations are suited to memory that the CPU and device access in parallel, such as a descriptor ring, mailbox structure, or firmware data held in main memory. Updates are visible without explicit software cache-flush calls. Drivers commonly allocate and free this memory during device setup and teardown with dma_alloc_coherent() and dma_free_coherent().

Coherent does not mean ordered

Visibility and ordering are different properties. CPU stores may be reordered even when memory is coherent. If the device protocol requires descriptor fields to become visible in a particular order—for example, fields must be written before an ownership or validity flag—use the memory barriers required by that protocol. Coherent allocation alone does not enforce that sequence.

Rank #2
Waveshare Luckfox Lyra RK3506G2 Linux Micro Development Board, Integrates Tripe-core ARM Cortex-A7 and ARM Cortex-M0 Processors, with Header
  • There are several options for this item, this option is with header. Please click the image 2 to check the package content.
  • Luckfox Lyra is a cost-effective Linux micro development board based on the Rockchip RK3506G2 to provide a simple and efficient development platform. Onboard multiple high-speed interfaces including MIPI DSl, RMll, USB, etc. to meet various application scenarios.
  • The low-speed interfaces utilize Rockchip Matrix l0 design which supports multiplexing 98 function siqnals on GPlO pins, and can freely combine PWM, UART, 12C, SPl, and l2S for quick development and debugging.
  • Tripe-core ARM Cortex-A7 32-bit core, with integrated VFP to support single- and double-precision floating-point operations. Built-in ARM Cortex-M0 MCU design, supports SMP and AMP configuration. Built-in 128MB DDRL3 for multi-core applications
  • The low-speed interfaces adopt Rockchip Matrix IO design, which allows rich function signals to share the limited chip pins, making peripheral circuit adaptation more flexible. Built-in audio and video codec, supports multiple audio inputs and outputs, providing high-quality audio playback and recording functions

Many small coherent regions

Coherent memory can be costly, and even a small allocation may consume page-scale resources. For many small, similarly sized coherent objects, consider a dma_pool rather than a collection of independent allocations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Streaming mappings: transfer buffers

Streaming mappings are for existing memory used in a device transfer, such as network or storage data. The usual lifecycle is to map the buffer, give the returned DMA address to the device, wait for the transfer to finish, and unmap it. Use dma_map_single() for suitable single-buffer memory, or the page and scatter/gather mapping variants when the memory layout calls for them.

Rank #3
EC Buying Luckfox Pico Mini B Linux AI Development Board RV1103 Micro Board Module Integrate ARM Cortex-A7/RISC-V MCU/NPU/ISP Processors 64MB DDR2 0.5TOPS Support int4 int8 int16 NPU with 128MB Flash
  • Single core ARM Cortex-A7 32-bit core, integrated with NEON and FPU
  • Built in Micro's self-developed 4th generation NPU, with high computational accuracy and support for mixed quantization of int4, int8, and int16. Among them, int8 has a computing power of 0.5 TOPS and int4 has a computing power of up to 1.0 TOPS
  • Built in self-developed 3rd generation ISP3.2, supports 4 million pixels, and supports various image enhancement and correction algorithms such as HDR, WDR, and multi-level denoisin
  • It has powerful encoding performance, supports intelligent encoding, adapts to save bit rates according to the scene, and saves more than 50% of the bit rate compared to conventional CBR mode, making the captured images high-definition, smaller in size, and doubling the storage space
  • The design with built-in RISC-V MCU supports low-power fast startup, 250ms fast capture, and simultaneous loading of AI model library, enabling facial recognition to be completed within 1 second

A mapping can also be kept for reuse, but then the driver must explicitly manage transitions between CPU and device ownership using the appropriate synchronization APIs. The mapping direction must match the actual data flow: DMA_TO_DEVICE is memory to device, DMA_FROM_DEVICE is device to memory, and DMA_BIDIRECTIONAL is for data that can flow both ways or whose direction is not known.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which mapping model fits?

Decision point Coherent allocation Streaming mapping
Typical lifetime Allocated during device setup; freed during teardown Mapped for a transfer and unmapped afterward, or retained and synchronized for reuse
Typical data Shared control structures, such as descriptor rings and mailbox structures Transfer buffers, such as network or storage data
Visibility and ownership CPU/device updates are visible without explicit software cache-flush calls; ordering still requires attention Direction and CPU/device ownership transitions must be handled through mapping and synchronization APIs
Common APIs dma_alloc_coherent(), dma_free_coherent(); dma_pool for many small regions dma_map_single(), dma_unmap_single(), page or scatter/gather variants, and sync calls when a mapping is reused

For example, a driver might keep its descriptor ring in coherent memory for the device’s lifetime, while mapping each packet or storage buffer as a streaming transfer. These are common patterns, not universal rules: the device protocol and actual ownership pattern determine the appropriate choice.

Implementation checks that prevent common DMA bugs

  1. Set the device’s DMA masks first. Before using DMA, configure the address width the hardware can actually handle, commonly with dma_set_mask_and_coherent(). Check its return value; if the requested mask is unsupported, do not proceed as though DMA is available. If streaming and coherent DMA have different address limits, configure separate masks as appropriate. See the Linux DMA API HOWTO.
  2. Check every streaming map for failure. A map can fail if the device or an intervening bus cannot address the buffer and the platform cannot provide a suitable IOMMU mapping or bounce buffer. Call dma_mapping_error() before passing the result to hardware, and handle failure as a normal error path.
  3. Match direction to data flow. Use DMA_TO_DEVICE when the device reads memory, DMA_FROM_DEVICE when it writes memory, and DMA_BIDIRECTIONAL when both directions may occur or are not known. The direction is part of the mapping contract, not merely a label.
  4. Synchronize reused streaming mappings at ownership changes. After the CPU’s final writes and before handing a buffer to the device, perform the required synchronization. Before the CPU reads data the device may have changed, synchronize for CPU access. Bidirectional use requires transitions both ways. If unmapping ends the mapping instead, unmap it with parameters matching the original map. dma_need_sync() can indicate whether explicit synchronization is needed on the platform.
  5. Use scatter/gather for discontiguous memory. dma_map_single() does not describe multiple discontiguous segments. Use the scatter/gather API for such buffers. Kernel virtual contiguity alone does not guarantee physical contiguity, and portable drivers cannot assume an IOMMU is present.
  6. Account for cache-line boundaries on non-coherent systems. Cache maintenance operates at cache-line granularity. If the driver cannot safely account for sharing at those boundaries, the API reference recommends page-bounded regions. Follow the constraints of the target platform.
  7. Consider mapping size on throughput-sensitive paths. The API provides dma_max_mapping_size() and dma_opt_mapping_size(). For high-rate, short-lived transfers, mapping overhead can be a meaningful part of the request lifetime; where splitting carries no significant penalty, the reference suggests limiting streaming mapping length to the optimal size. These are runtime, platform-specific values, not a universal size threshold.

Check the target kernel’s documentation

DMA API details can change across kernel versions and depend on platform behavior. The links here are to the current Linux kernel documentation; use the API reference and HOWTO corresponding to the kernel you are targeting when implementing or reviewing a driver.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.