zero copy socket splicing
play

Zero-Copy Socket Splicing Alexander Bluhm bluhm@openbsd.org - PowerPoint PPT Presentation

Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Zero-Copy Socket Splicing Alexander Bluhm bluhm@openbsd.org Sunday, 29. September 2013 Motivation Kernel MBuf Packet Processing Socket


  1. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Zero-Copy Socket Splicing Alexander Bluhm bluhm@openbsd.org Sunday, 29. September 2013

  2. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  3. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  4. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Application Level Gateway Relay Application User Land Socket Splicing Kernel TCP/UDP Packet Filter Network IP Data Link Physical

  5. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Persistent HTTP Filtering content length content length Body Body Header Header copy copy copy copy copy filter filter

  6. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications HTTP Socket Splicing splice length splice length Header Header filter filter User Land Kernel Body Body splice splice

  7. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  8. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications MBuf Data mbuf size 256 m hdr m data m len 42 m dat size 236 ether header ip header size 42 udp header

  9. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications MBuf Data Chaining mbuf size 256 mbuf size 256 m hdr m hdr m next m next NULL m data m data 42 100 m len m len m pkthdr m dat size 236 len 142 m pktdat payload size 196 ether header size 100 ip header size 42 udp header

  10. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications MBuf Packet Chaining mbuf mbuf mbuf m hdr m hdr m hdr m next m next m next m nextpkt m nextpkt m nextpkt m pkthdr mbuf mbuf m hdr m hdr m next m next m nextpkt m nextpkt m pkthdr

  11. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications MBuf Cluster size 2048 ether header mbuf size 256 ip header m hdr udp header m data payload m len 1400 size 1400 m pkthdr m ext ext buf ext size 2048

  12. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications MBuf Cluster Copy ether header mbuf ip header m data udp header ext buf payload mbuf m data ext buf

  13. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  14. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Packet Input read() User Land Kernel soreceive() socket receive buffer, m next tcp input() inetsw[] internet protocol switch ip input() ip interface receive queue, m nextpkt ether input() network driver interrupt handler

  15. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Packet Output write() User Land Kernel sosend() socket send buffer, m next tcp output() ip output() ether output() interface send queue, m nextpkt if start() network driver start routine

  16. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Data Copy Relay read() write() copyout() copyin() uiomove() uiomove() soreceive() sosend() so rcv so snd tcp input() tcp output()

  17. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Process Wakeup read() select() write() file descriptor struct socket soreceive() sosend() so rcv so snd sowwakeup() ACK sorwakeup() tcp input() tcp output()

  18. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  19. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Socket Splicing setsockopt(SO SPLICE) sosplice() somove() so rcv so snd sowwakeup() ACK sorwakeup() tcp input() tcp input() tcp output()

  20. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications UDP Sockets soreceive() sosend() somove() so rcv udp input() udp output()

  21. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Layer Relaying read() write() soreceive() sosend() Socket Splicing so rcv so snd tcp input() tcp output() Forwarding ip input() ip output() ipintrq if snd

  22. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  23. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Simple API Begin splicing from source to drain setsockopt(source fd, SO SPLICE, drain fd) Stop splicing setsockopt(source fd, SO SPLICE, -1) Get spliced data length getsockopt(source fd, SO SPLICE, &length)

  24. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Extended API struct splice { int sp_fd; /* drain */ off_t sp_max; /* maximum */ struct timeval sp_idle; /* timeout */ }; setsockopt(source fd, SO SPLICE, &splice)

  25. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Properties Splicing is unidirectional Invoke it twice for bidirectional splicing Process can turn it on and off Works for TCP and UDP Can mix IPv4 and IPv6 sockets

  26. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Unsplice Dissolve socket splicing manually read(2) or select(2) from the source EOF source socket shutdown EPIPE drain socket error EFBIG maximum data length ETIMEDOUT idle timeout

  27. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  28. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Struct Socket struct socket { ... struct socket *so_splice; struct socket *so_spliceback; off_t so_splicelen; off_t so_splicemax; struct timeval so_idletv; struct timeout so_idleto; ... };

  29. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications sosplice(9) Protocol must match Sockets must be connected Double link sockets Move existing data

  30. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications somove(9) Check for errors Check for space Handle maximum Handle out of band data Move socket buffer data

  31. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications sounsplice() Manual unsplice Cannot receive Cannot send Maximum Timeout Socket closed

  32. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications sorwakeup() sowwakeup() Called from tcp input() Source calls sorwakeup() Drain calls sowwakeup() Both invoke somove(9)

  33. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Agenda Motivation 1 Kernel MBuf 2 Packet Processing 3 Socket Splicing 4 Interface 5 Implementation 6 Applications 7

  34. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Relayd Plain TCP connections HTTP connections Filter persistent HTTP HTTP Chunking

  35. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Tests /usr/src/regress/sys/kern/sosplice/ 15 API tests 18 UDP tests 76 TCP tests perf/relay.c simple example BSD::Socket::Splice Perl API 28 relayd tests

  36. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Performance Factor 1 or 2 for TCP Factor 6 or 8 for UDP

  37. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Documentation Manpage setsockopt(2) SO SPLICE Manpage sosplice(9) somove(9)

  38. Motivation Kernel MBuf Packet Processing Socket Splicing Interface Implementation Applications Questions ?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend