Libtorrent - Features - Network Buffers

Network Buffers

On CPUs with small L2 caches, copying memory can be expensive operations. It is important to keep copying to a minimum on such machines. This mostly applies to embedded systems.

In order to minimize the number of times received data is copied, the receive buffer for payload data is received directly into a page aligned disk buffer. If the connection is encrypted, the buffer is decrypted in-place. The buffer is then moved into the disk cache without being copied. Once all the blocks for a piece have been received, or the cache needs to be flushed, all the blocks are passed directly to writev to flush them in a single syscall. This means a single copy into user space memory, and a single copy back into kernel memory.

When seeding and uploading in general, unnecessary copying is avoided by caching blocks in aligned buffers, that are copied once into the peer's send buffer. The peer's send buffer is not guaranteed to be aligned, even though it is most of the time. The send buffer is then encrypted with the peer specific key and chained onto the iovec for sending. This means there is one user space copy in order to allow unaligned peer requests and peer-specific encryption.

Read more about this topic:  Libtorrent, Features

Famous quotes containing the word network:

    Parents need all the help they can get. The strongest as well as the most fragile family requires a vital network of social supports.
    Bernice Weissbourd (20th century)