msg_zerocopy.rst: clarify the TCP shutdown scenario
Subsystems (3)
PATCH 1/1 msg_zerocopy.rst: clarify the TCP shutdown scenario
Hi folks,
Based on my understanding, retransmissions of zero copied buffers can happen after close(2), the patch below amends the docs to suggest how notifications should be handled in that case.
Explicitly mention that applications shouldn't be calling close(2) on a TCP socket without draining the error queue.
--- Documentation/networking/msg_zerocopy.rst | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/networking/msg_zerocopy.rst +4 -0
@@ -144,6 +144,10 @@ the socket. A socket that has an error queued would normally block other operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls. +For protocols like TCP, where retransmissions can occur after the +application is done with a given connection, applications should signal +the close to the peer via shutdown(2), and keep polling the error queue +until all transmissions have completed. Notification Batching ~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.36.1
Quoted 6 lines · Frederik Deweerdt
Hi folks,
Based on my understanding, retransmissions of zero copied buffers can happen after
close(2), the patch below amends the docs to suggest how notifications should be handled in that case.
Not just retransmissions. The first transmission similarly may be queued.
Quoted 12 lines
Explicitly mention that applications shouldn't be calling
close(2)on a TCP socket without draining the error queue.--- Documentation/networking/msg_zerocopy.rst | 4 ++++ 1 file changed, 4 insertions(+)Documentation/networking/msg_zerocopy.rst +0
-0
Documentation/networking/msg_zerocopy.rst the socket. A socket that has an error queued would normally block · line 150
Quoted 7 lines
Documentation/networking/msg_zerocopy.rst +4
-0@@ -144,6 +144,10 @@ the socket. A socket that has an error queued would normally block other operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls. +For protocols like TCP, where retransmissions can occur after the +application is done with a given connection, applications should signal +the close to the peer via shutdown(2), and keep polling the error queue +until all transmissions have completed.
A socket must not be closed until all completion notifications have been received.
Calling shutdown is an optional step. It may be sufficient to simply delay close.
Hi Willem,
Quoted 12 lines · Willem de Bruijn
Quoted 6 lines · Frederik Deweerdt
Hi folks,
Based on my understanding, retransmissions of zero copied buffers can happen after
close(2), the patch below amends the docs to suggest how notifications should be handled in that case.Not just retransmissions. The first transmission similarly may be queued.
Quoted 1 line
[...]
Quoted 12 lines
Review the socket. A socket that has an error queued would normally block · line 150
Quoted 8 lines
(quoted diff) +4
-0@@ -144,6 +144,10 @@ the socket. A socket that has an error queued would normally block other operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls. +For protocols like TCP, where retransmissions can occur after the +application is done with a given connection, applications should signal +the close to the peer via shutdown(2), and keep polling the error queue +until all transmissions have completed.A socket must not be closed until all completion notifications have been received.
Quoted 2 lines
Calling shutdown is an optional step. It may be sufficient to simply delay close.
Thank you for the feedback, that helps!
What do you think of the attached patch?
Frederik
commit 3218d973b68bc6d9f88d9e2374f3ada3df5ee7ff
Author: Frederik Deweerdt <[email protected]> Date: Tue May 31 18:23:54 2022 -0700
[doc] msg_zerocopy.rst: clarify the TCP shutdown scenario
Explicitly mention that applications shouldn't be calling close(2) on a TCP socket without draining the error queue.
Documentation/networking/msg_zerocopy.rst +5 -0
@@ -144,6 +144,11 @@ the socket. A socket that has an error queued would normally block other operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls. +For protocols like TCP, transmissions can occur after the application +has called close(2). In cases where it's undesirable to delay calling +close(2) until all notifications have been processed, the application +can use shutdown(2), and keep polling the error queue until all +transmissions have completed. Notification Batching ~~~~~~~~~~~~~~~~~~~~~
Quoted 29 lines · Frederik Deweerdt
Hi Willem,
Quoted 12 lines · Willem de Bruijn
Quoted 6 lines · Frederik Deweerdt
Hi folks,
Based on my understanding, retransmissions of zero copied buffers can happen after
close(2), the patch below amends the docs to suggest how notifications should be handled in that case.Not just retransmissions. The first transmission similarly may be queued.
Quoted 1 line
[...]
Quoted 12 lines
Review the socket. A socket that has an error queued would normally block · line 150
Quoted 8 lines
(quoted diff) +4
-0@@ -144,6 +144,10 @@ the socket. A socket that has an error queued would normally block other operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls. +For protocols like TCP, where retransmissions can occur after the +application is done with a given connection, applications should signal +the close to the peer via shutdown(2), and keep polling the error queue +until all transmissions have completed.A socket must not be closed until all completion notifications have been received.
Quoted 6 lines
Quoted 2 lines
Calling shutdown is an optional step. It may be sufficient to simply delay close.
Thank you for the feedback, that helps!
What do you think of the attached patch?
Please always share patches inline.
Documentation/networking/msg_zerocopy.rst the socket. A socket that has an error queued would normally block · line 151
Quoted 10 lines
+++
b/Documentation/networking/msg_zerocopy.rst(quoted diff) +0
-0@@ -144,6 +144,11 @@ the socket. A socket that has an error queued would normally blockother operations until the error is read. Zerocopy notifications have a zero error code, however, to not block send and recv calls.
Documentation/networking/msg_zerocopy.rst +5
-0+For protocols like TCP, transmissions can occur after the application +has called close(2). In cases where it's undesirable to delay calling +close(2) until all notifications have been processed, the application +can use shutdown(2), and keep polling the error queue until all +transmissions have completed.
Sorry to nitpick, but calling close(2) is still delayed. You meant where it's undesirable to delay closing the TCP connection?
Shutdown can be used then. But that is not unique to msg_zerocopy? I don't feel strongly either way. Perhaps it would be helpful to describe what makes it is undesirable to wait with calling close.
Btw, packets leaving the host after a socket is closed is not unique to the TCP protocol, but an effect of queuing, such as in the qdisc layer.
From: Frederik Deweerdt <[email protected]>
Quoted 7 lines
Sent: 02 June 2022 00:01
Quoted 6 lines
A socket must not be closed until all completion notifications have been received.
Calling shutdown is an optional step. It may be sufficient to simply delay close.
What happens if the process gets killed - eg by SIGSEGV?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 11 lines · David Laight
From: Frederik Deweerdt <[email protected]>
Quoted 7 lines
Sent: 02 June 2022 00:01
Quoted 6 lines
A socket must not be closed until all completion notifications have been received.
Calling shutdown is an optional step. It may be sufficient to simply delay close.
What happens if the process gets killed - eg by SIGSEGV?
The skb frags hold independent references on the pages. Once skbs are freed on transmit completion or socket purge the pages are released if there are no other page references.
Otherwise there is nothing zerocopy specific about closing TCP connections when a process crashes.
From: Willem de Bruijn
Quoted 13 lines
Sent: 03 June 2022 14:30
Quoted 10 lines · David Laight
From: Frederik Deweerdt <[email protected]>
Quoted 7 lines
Sent: 02 June 2022 00:01
Quoted 6 lines
A socket must not be closed until all completion notifications have been received.
Calling shutdown is an optional step. It may be sufficient to simply delay close.
Quoted 8 lines
Quoted 1 line
What happens if the process gets killed - eg by SIGSEGV?
The skb frags hold independent references on the pages. Once skbs are freed on transmit completion or socket purge the pages are released if there are no other page references.
Otherwise there is nothing zerocopy specific about closing TCP connections when a process crashes.
So the proposed text for the documentation is just wrong.
Something that says that retransmissions can re-read the pages after the socket is closed would be more relevant.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)