Question

I found Netty documentation says they have "Transparent Zero Copy" feature in their build-in ByteBuffer. But after the reading, I notice it doesn't mention any kernel space and user space switching, only something about reuse the buffer.

So I wonder is Netty's "Zero Copy" feature different from OS level "Zero Copy"(Which means reduce the copy from user space memory to kernel space memory) ?

Was it helpful?

Solution

According to Wikipedia:

Zero-Copy describes computer operations in which the CPU does not perform the task of copying data from one memory area to another.

OS-level zero copy involves avoiding copying memory blocks from one location to another (typically from user space to kernel space) before sending data to the hardware driver (network card or disk drive) or vice versa.

Netty zero copy is talking about optimizing data manipulation on Java level (user-space only). Their ChannelBuffer allows to read contents of multiple byte buffers without actually copying their content.

In other words, while Netty works only in user space, it is still valid to call their approach "zero copy". However, if OS does not use or support true zero copy, it is possible that when data created by Netty-powered program will be sent over the network, data would still be copied from user space to kernel space, and thus true zero-copy would not be achieved.

OTHER TIPS

Netty also support the use of a FileRegion which allows to transfer FileChannel content without copy it to the userspace.

Zero-Copy has two means in the netty's world.

First,if your platform support zero-memory-copy,you can write a DefaultFileRegion to the Channel, ChannelHandlerContrext, or ChannelPipeline.

Second, CompositeByteBuf is a virtual buffer which shows multiple buffers as a single merged buffer. So you can composite some byteBufs to one CompositeByteBuf, and it doesn't need copy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top