Richard Waller

Zero-Copy Dreams

The kernel is slow. Not because it’s poorly written—modern kernels are marvels of engineering—but because every transition from userspace to kernelspace has overhead. System calls, context switches, memory copies: they all add latency.

When building Prism, we bypassed the kernel entirely. DPDK gives us direct access to network hardware, allowing packet processing entirely in userspace. No system calls, no context switches, no unnecessary copies.

The Cost of Copies

Consider a traditional network stack. A packet arrives at the NIC, is copied into kernel memory, processed by the kernel’s TCP stack, then copied again into userspace. Each copy takes time. For high-throughput applications, these copies become a bottleneck.

But copies aren’t just about performance—they’re about correctness. Every copy is an opportunity for bugs: buffer overflows, race conditions, data corruption. The more copies, the more surface area for errors.

Prism’s zero-copy architecture eliminates these copies. Packets are processed in-place, using direct memory access. The NIC writes directly into our buffers, we process them, send them out—all without copying.

Lock-Free Data Structures

But zero-copy isn’t enough. Traditional synchronization—mutexes, locks—introduces contention. In a high-throughput system, lock contention becomes a bottleneck.

Prism uses lock-free data structures extensively. The connection table is a lock-free hash table. Packet queues are lock-free ring buffers. Even the statistics counters are lock-free.

Lock-free programming is hard. You must reason about memory ordering, handle ABA problems, ensure progress guarantees. But the performance gains are worth it. We can process millions of packets per second with minimal contention.

The Abstraction Problem

The challenge with zero-copy and lock-free code is abstraction. Traditional abstractions—sockets, file descriptors, mutexes—assume kernel mediation. When you bypass the kernel, you lose these abstractions.

We had to build our own:

  • Connection management (no kernel TCP state)
  • Memory management (no kernel page cache)
  • Error handling (no kernel error codes)
  • Debugging tools (no kernel tracing)

Each abstraction is a trade-off. More abstraction means easier programming but potentially lower performance. Less abstraction means better performance but more complexity.

The Reality Check

Zero-copy isn’t always worth it. For most applications, the kernel’s network stack is fast enough. The abstractions it provides—process isolation, security, compatibility—are valuable.

But for specialized applications—high-frequency trading, real-time analytics, network function virtualization—the performance gains justify the complexity. Prism isn’t a replacement for the kernel stack—it’s a tool for when you need every microsecond.

The Future

As hardware becomes more powerful and specialized—DPUs, SmartNICs, programmable switches—the boundary between kernel and userspace will continue to blur. Kernel bypass will become more common, not less.

The challenge is making these techniques accessible. Right now, building a userspace network stack requires deep expertise. But as tools improve—better DPDK bindings, higher-level abstractions, better debugging—this will change.

Conclusion

Zero-copy and lock-free programming aren’t just optimization techniques—they’re a different way of thinking about systems. Instead of accepting kernel overhead, we eliminate it. Instead of using locks, we design data structures that don’t need them.

This approach isn’t for everyone. But for systems where performance matters, it’s the only way to achieve the latency and throughput required. Prism proves it’s possible—now the challenge is making it easier.

References



Links to this page

Change Log