Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Linux MSG_ZEROCOPY support for nts #107

Merged
merged 14 commits into from
Jan 25, 2024

Conversation

smtrfnv
Copy link
Contributor

@smtrfnv smtrfnv commented Jan 3, 2024

This PR extends support of Linux send data copy avoidance mechanism to NTS.
Also, this PR includes (thanks to @mattrm456 ) refactoring of datagram/stream socket send path implementation (ntcr & ntcp) (relative PR: smtrfnv#5)

Brief description:

  • Now the user can set so called zeroCopyThreshold (meaning a minimum amount of data available to be sent using copy avoidance mechanism) in ntsa::InterfaceConfig or in ntca::StreamSocketOptions and ntca::DatagramSocketOptions
  • Socket implementations will automatcally retry to send data without zero-copy semantics, if previous send() with MSG_ZEROCOPY flag fails due to ENOBUFS error.
  • Whenever kernel reports that it cannot really avoid copy (either because it cannot in general or e.g. it cannot lock pages in memory) zero-copy semantics will be disabled for the socket.
  • Due to the fact above, if anyone wants to get maximum of the feature they are advised to ensure that ulimit -l is something big.

mattrm456 and others added 2 commits January 25, 2024 17:24
… zero-copy completion intervals (#5)

* Standardize and document configurability of zero-copy threshold across socket and interface configuration and propagate default configuration

* Standardize the function naming for the mechanics of processing timestamp and zero-copy notifications

* Revisions to zero-copy implementation

* Support enabling and disabling timestamping and zero-copy during the operation of a socket

* Move responsibility of retrying zero-copy due to ENOBUFS to ntsu::SocketUtil

* Delegate ntcr::DatagramSocket::send without a callback to the callback overload

* Revise ntcq::ZeroCopyQueue interface and restructure send paths for ntcr::DatagramSocket and ntcr::StreamSocket

* Zero copy set intersection

* Zero copy set intersection

* ntcq::ZeroCopyQueue test sanity checks

* ntcq::ZeroCopyQueue test sanity checks

* ntcq::ZeroCopyQueue test sanity checks

* ntcq::ZeroCopyQueue test sanity checks

* Revisions to zero-copy implementation

* 32-bit wraparound conversion

* Test 32-bit wraparound

* Introduce ntsa::ZeroCopyType

* Update test drivers to respect ntsa::ZeroCopyType

* Only set SO_ZEROCOPY on IPv4 and IPv6 sockets, automatically disable zero-copy when we learn a copy is only deferred and not avoided

* When testing default value of zero-copy socket option respect that ntsu::SocketUtil::create automatically sets it for IPv4 and IPv6 sockets

* When explicitly sending to an endpoint for a connected datagram socket, verify the two endpoints match but don't explicitely set the target endpoint when calling ::sendmsg

* Fix improper assert in ntcr::StreamSocket when writing to a non-empty write queue

* Ensure the send deadline timer is closed whenever a write queue entry is popped from the write queue, especially at shutdown

* When flushing reactors after the last waiter is deregistered, on loop while functors are still enqueued; pending timers are never guaranteed to fire and may cause infinite loops

* Check zero copy queue if the associated send callback is ready after framing a zero copied send group

* Fix defensive check when explicitly sending to an endpoint different that the endpoint to a datagram socket is connected

* Do not set SO_ZEROCOPY by default in nts, but do set it by default in ntc

* Only retry sendmsg without MSG_ZEROCOPY if it failed with ENOBUFS and MSG_ZEROCOPY was specified in the first place

* Default ntci::{Stream,Datagram}Socket::setZeroCopyThreshold returns e_NOT_IMPLEMENTED

* Review comments

* Assert wait list is not empty in ntcq::ZeroCopyQueue::frame()
@smtrfnv smtrfnv changed the title DRAFT: msg zerocopy ntc Implement Linux MSG_ZEROCOPY support for nts Jan 25, 2024
@smtrfnv smtrfnv marked this pull request as ready for review January 25, 2024 16:02
Copy link
Contributor

@mattrm456 mattrm456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge.

@mattrm456 mattrm456 merged commit eaef18d into bloomberg:main Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants