Backend Development 8 min read

Zero‑Copy Mechanisms in Operating Systems and Java

This article explains how zero‑copy techniques such as mmap, sendfile, and splice reduce CPU involvement in data transfer by avoiding memory copies between kernel and user spaces, and shows how Java NIO and Netty implement these mechanisms for high‑performance backend I/O.

Top Architect
Top Architect
Top Architect
Zero‑Copy Mechanisms in Operating Systems and Java

Zero‑copy is a technique that avoids copying data between memory regions, thereby reducing CPU load and improving performance.

In a typical file download, the operating system copies data from disk to a kernel buffer via DMA, then copies from the kernel buffer to user space using the CPU, copies from user space to a socket buffer (CPU), and finally sends the data from the socket buffer to the NIC via DMA, resulting in multiple copies and context switches.

Using mmap shares kernel memory with user space, eliminating the copy from kernel to user space; however, a copy from the kernel buffer to the socket buffer is still required.

The sendfile system call transfers data entirely within kernel space, reducing CPU copies to a single copy and eliminating user‑kernel context switches, thus offering better performance than mmap .

The splice function creates a pipe between a file descriptor and a socket descriptor, allowing data to be transferred without any CPU copy or user‑kernel switches, achieving true CPU zero‑copy.

In Java, the NIO package provides zero‑copy via FileChannel.transferTo and transferFrom , which internally invoke the OS sendfile function. Netty, a high‑performance network framework, also implements zero‑copy using direct memory, FileChannel.transferTo , CompositeByteBuf , and slice to avoid unnecessary copies.

Overall, OS zero‑copy reduces CPU involvement for data movement; mmap, sendfile, and splice progressively eliminate copies, with sendfile and splice achieving true CPU zero‑copy, while Java NIO and Netty leverage these mechanisms for efficient backend I/O.

backendMMAPsendfileZero CopyosJava NIOsplice
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.