Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use zero-copy for TCP send/recv with the default linux TCP/IP-stack?

Can we use zero-copy for TCP send/recv with the default linux TCP/IP-stack?

  • As known, we can re-map socket buffer from kernel-space to the user-space for RAW-sockets: https://www.kernel.org/doc/Documentation/networking/packet_mmap.txt

Example:

int packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); // raw-sockets

struct tpacket_req3 req;  
setsockopt(packet_socket, SOL_PACKET , PACKET_RX_RING , (void*)&req , sizeof(req));
mapped_buffer = (uint8_t*)mmap(NULL, req.tp_block_size * req.tp_block_nr,
    PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED, packet_socket, 0);
  • Also known, that payload doesn't change while lifting up using the TCP-stack: https://www.informatix-sol.com/docs/TCP_bypass.pdf

enter image description here

So can we map part of socket-buffer with received payload from kernel-space to user-space to avoid zero-copy?

like image 776
Alex Avatar asked Jul 11 '17 09:07

Alex


1 Answers

4.18 merged zero-copy receive support for the in-kernel TCP stack, see:

  • https://lwn.net/Articles/754681/
  • https://lwn.net/Articles/752188/
like image 100
Clemens Fruhwirth Avatar answered Sep 30 '22 04:09

Clemens Fruhwirth