What is "zero copy" or "zero buffer" concept?
"Zero copy" (also called "zero buffer") is a design technique that eliminates the CPU-driven copying of data from one memory buffer to another as data moves between a producer and a consumer. In a naive design, data is copied multiple times — for example, a NIC writes a packet into a driver buffer, the kernel copies it into a socket buffer, and the application copies it again into its own buffer. Each copy burns CPU cycles, consumes memory bandwidth, pollutes caches, and adds latency.
The zero-copy approach removes those intermediate copies by either:
- Letting DMA move the data directly into (or out of) the final destination buffer (e.g., a NIC DMAs received frames straight into an application-visible buffer, or a peripheral DMAs straight from a transmit buffer the application filled).
- Passing ownership of a buffer by pointer/reference between stages instead of copying its contents. The producer hands the consumer a descriptor (pointer + length, or a handle to a buffer in a shared pool), and ownership/lifetime is tracked rather than the bytes being duplicated.
Benefits: lower CPU utilization, lower latency, reduced memory-bandwidth pressure, and fewer cache evictions, which is especially valuable in high-throughput networking, storage, and streaming-media pipelines.
Costs/concerns: the design becomes more complex. You need careful buffer-ownership and lifetime management (who frees it and when), often a pool of pre-allocated, alignment- and DMA-suitable buffers, cache coherency handling (cache flush/invalidate around DMA on non-coherent systems), and synchronization so the producer doesn't overwrite a buffer the consumer is still using. Examples include sendfile()/splice() on Linux, scatter-gather DMA, mmap'd I/O, and ring-buffer descriptor schemes in NIC and DMA drivers.
