VRB – Virtual Ring Buffer
vrb.sourceforge.net
vrb.sourceforge.net
[0]: http://www.codeproject.com/Articles/3479/The-Bip-Buffer-The-...
[1]: https://github.com/wrl/wwrl/blob/master/src/bip_buffer.c
* (Maximum) item size must be known in advance, and
* Buffer items must be smaller than half the buffer size, and
* If items are not suitably sized, buffer fragmentation may result
There are also some cases where the padded size requirement may exceed available non-wrapped space with bip vs VRB or similar. Anyway, most OS support mmap(2) today :).The chief use-case for my bip buffer implementation is using a shared memory segment for inter-process communication, and adding mmap() for address mirroring on top of that just seems like a can of worms I'm not particularly interested in opening.
The basic premise is to mmap() the same physical memory twice in a row (in virtual address space). Then you can always point to a contiguous chunk of memory to reference a given object in your queue.
Something like the memory trick used in this virtual ring buffer but far more powerful.
well, as others have pointed out, dpdk / netmap are a couple of choices available for bypassing the kernel network stack completely, and get stuff directly into userland. once things are there, you can do all protocol specific parsing etc.
this essentially implies that what you 'see' in memory are mmap'ped ring buffers, not the so called PDU's that you are looking for. the number of protocol-stacks available in userland is, however, to the best of my knowledge, quite limited.
for example, there are couple of folks exploring the option of exporting linux-kernel's networking stack as a library under the N.U.S.E (networking in user space) project. details available here: http://people.netfilter.org/pablo/netdev0.1/papers/Library-O... (https://github.com/libos-nuse/net-next-nuse),
if you have a very specific application in mind that you want to tackle e.g. let's say acting as a transparent proxy, forwarding l2 etc. then things are kind of doable. implementing a generic very high performance stacks (where 2-3 cache-misses will wipe out your timing budgets) is kind of hard, imho...
You can't really do this with TCP though, without changing the hardware. Most modern network adapters support only a scatter/gather list mechanism for receiving/sending packets, but this doesn't work for receiving TCP payloads into contiguous locations, since TCP's data model is a byte stream.
With UDP and SCTP you can do full zero-copy just fine.
A bigger problem is that on the send side you can't reuse the a 0 copy buffer until the remote ack has arrived for that tcp segment which complicates the interface between the application and the tcp stack.
Sometimes you have to do a bit more work to achieve the zero-copy behaviour, but it's available is many cases.
You (necessarily) lose zero-copy when the dataflow isn't one-input-one-output.