Fundamentals 15 min read

Understanding DMA and Zero‑Copy Techniques in Linux I/O

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 mechanisms such as sendfile, mmap and Direct I/O, with practical examples like Kafka and MySQL.

Architect
Architect
Architect
Understanding DMA and Zero‑Copy Techniques in Linux I/O

When an application processes a client request, it typically performs a File.read(file, buf, len); followed by a Socket.send(socket, buf, len); , causing four data copies and four context switches between user space, kernel space, disk, and network interfaces.

DMA (Direct Memory Access) introduces a dedicated controller that moves data between memory and I/O devices without CPU involvement, turning the four copies into two and halving the context switches.

Zero‑copy is a design principle where the CPU does not copy data between buffers; instead, it only initiates the transfer. Implementations include:

sendfile : Uses DMA and passes file descriptors to avoid copying data from page cache to socket buffers, reducing system calls from two (read + write) to one.

mmap : Maps kernel page cache directly into user space, allowing the application to read/write without extra copies.

Direct I/O : Bypasses page cache entirely, transferring data directly between user buffers and disk/network via DMA; it requires page pinning and careful metadata handling.

Advantages of zero‑copy include lower CPU usage and higher throughput for large data transfers, while disadvantages involve increased complexity, the need for page pinning, and potential performance penalties for small or infrequent I/O.

Typical use cases:

Kafka : Persists messages using mmap and serves them with sendfile , benefiting from page cache sharing among consumers.

MySQL : Employs Direct I/O in self‑caching scenarios to avoid kernel buffering.

Overall, DMA enables the CPU to act only as a controller while the data movement is handled by hardware, and Linux provides multiple zero‑copy strategies to optimize I/O performance.

LinuxDMAI/O optimizationMMAPsendfileZero CopyDirect I/O
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.