Hardware implementations Techniques for creating zero-copy software include the use of direct memory access (DMA)-based copying and memory-mapping through a memory management unit (MMU). These features require specific hardware support and usually involve particular memory alignment requirements.
With zero-copy method, the data are not copied and come to the user-space directly from the network stack. Kernel Bypass. The kernel bypass is when you manage yourself, in the user-space, the network stack and hardware stuff.
To do zero-copy, you use zmq_msg_init_data() to create a message that refers to a block of data already allocated on the heap with malloc() , and then you pass that to zmq_msg_send() .
zero copy means that your program will not transfer the data from the kernel space to the user space and so on.
There's been some talk on linux-kernel recently about providing an API for something along these lines, but the sticking point is that you can't DMA from general userspace buffers to the network card, because:
On recent kernels, you could try using vmsplice
and splice
together to achieve what you want - vmsplice
the pages (with SPLICE_F_GIFT
) you want to send into a pipe, then splice
them (with SPLICE_F_MOVE
) from the pipe into the socket.
AFAIK you are using the most efficient calls available if you cant use sendfile(2). Various aspects of efficient high performance networking code is covered by The C10K problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With