Fundamentals 15 min read

Understanding DMA and Zero‑Copy Techniques in Linux

This article explains how DMA offloads memory‑to‑device data transfers, reduces the four data copies and context switches of traditional I/O, and introduces zero‑copy methods such as sendfile, mmap and Direct I/O, illustrating their mechanisms, advantages, limitations, and real‑world use cases like Kafka and MySQL.

Top Architect
Top Architect
Top Architect
Understanding DMA and Zero‑Copy Techniques in Linux

Many applications perform a file read and a socket send, which under traditional I/O involve four data copies and four context switches, leading to poor performance.

DMA (Direct Memory Access) introduces a dedicated controller that moves data between memory and I/O devices without CPU involvement, reducing the number of copies and context switches.

The concept of zero‑copy means the CPU does not fully copy data between buffers; instead, mechanisms like DMA, page cache sharing, and file descriptor passing are used to avoid unnecessary copying.

Key zero‑copy techniques include:

sendfile – combines DMA and file descriptor passing to replace read/write with a single system call, cutting context switches from four to two.

mmap – maps kernel pages into user space, allowing direct access without copying.

Direct I/O – bypasses page cache, letting user‑space buffers interact directly with disks or NICs via DMA.

Each technique has trade‑offs: sendfile cannot be used when data must be processed; Direct I/O requires page pinning and may be slower for small reads; mmap relies on kernel support.

Typical use cases:

Kafka uses mmap for persisting logs and sendfile for delivering messages to consumers, benefiting from reduced copies and shared page cache.

MySQL employs similar zero‑copy strategies, though its implementation is more complex.

In summary, DMA and zero‑copy technologies significantly improve I/O performance by minimizing CPU‑bound data movement, and Linux provides multiple strategies—sendfile, mmap, splice, and Direct I/O—to achieve this across different scenarios.

LinuxDMAI/O optimizationMMAPsendfileZero CopyDirect I/O
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.