Zero Copy - Use your memory wisely
Zero copy can save you some memory space, basically que avoid data transfer, buffers, etc…
We tend to think in layers, this is not something bad, but sometimes… Yes it is. Principally when we are working with data transfer, thinking in layers just add more latency and memory usage. How to avoid this? Create a hole in your application layers, this is something bad, but sometimes… No!
A good example is the sendfile()
syscall in linux kernel.
Using this, we don’t need to pass the data through **the **user-space, the data comes directly from the file to the network.
In real life software, we see this a lot in Kafka!
When a producer sends messages to a Kafka broker, the broker writes these messages
to disk (Kafka is designed to store large volumes of data efficiently on disk, don’t be afraid).
When a consumer requests messages, instead of loading the data from disk into Kafka’s user space memory and then copying it again to the network buffers, Kafka transfers data directly from the disk to the network socket.
Keep in mind this concept when you’re working with data transfer, and you will be happy.
Thanks, bye!
References
https://lwn.net/Articles/726917/