Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EF81C169C4 for ; Tue, 29 Jan 2019 07:14:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 096D12147A for ; Tue, 29 Jan 2019 07:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725779AbfA2HOY convert rfc822-to-8bit (ORCPT ); Tue, 29 Jan 2019 02:14:24 -0500 Received: from vsmx009.vodafonemail.xion.oxcs.net ([153.92.174.87]:29804 "EHLO vsmx009.vodafonemail.xion.oxcs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbfA2HOY (ORCPT ); Tue, 29 Jan 2019 02:14:24 -0500 Received: from vsmx001.vodafonemail.xion.oxcs.net (unknown [192.168.75.191]) by mta-5-out.mta.xion.oxcs.net (Postfix) with ESMTP id 1A5C7C0561; Tue, 29 Jan 2019 07:14:23 +0000 (UTC) Received: from nextcloud.mskoehrer.de (unknown [85.13.129.61]) by mta-5-out.mta.xion.oxcs.net (Postfix) with ESMTPA id C2B7D30029B; Tue, 29 Jan 2019 07:14:16 +0000 (UTC) MIME-Version: 1.0 Date: Tue, 29 Jan 2019 07:14:16 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT X-Mailer: RainLoop/1.12.1 From: mathias_koehrer@arcor.de Message-ID: <20d6526cb017d70b247eba0b92f23fb1@arcor.de> Subject: Re: TCP/IPv4 sending using MSG_ZEROCOPY and closing the socket To: "Willem de Bruijn" Cc: "Network Development" , "Willem de Bruijn" In-Reply-To: References: X-VADE-STATUS: LEGIT Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org >> Hi all, >> >> I have one question on the behavior of TCP/IPv4 sending using the MSG_ZEROCOPY flag, >> the kernel version is 4.19.18. >> >> What happens if I close the sending socket immediately after performing a socket >> send() or sendmsg() call (called with the MSG_ZEROCOPY flag)? >> I.e. in this situation not all messages have been sent yet, however - as the >> socket is closed - it is no longer possible to retrieve the completion >> notification via the error channel. >> >> Is it fine for the user space program to free all outstanding messages after the >> socket close() has returned? >> Or is there anything else that has to be considered? > > If closing the socket while user memory is still in transmission, it > will not be possible to safely reuse the memory, as the process has no > way of discovering when the kernel has finished transmission. > > Depending on type of memory, there may be workarounds to avoid > unbound virtual memory growth, such as unmapping the virtual > address range in the case of mmap()ed data. > > But in general, the right approach is to wait for all completions > before closing a socket. > > If this takes a long time, say due to the TCP stack hold on to data for > retransmission in the case a peer does not properly close its side, > disconnect (connect() AF_UNSPEC) can be used to purge the > queues and trigger notifications. Again, this is a last resort and > usually not needed. Hi Willem! Thank you for the clarification. Do you think you could add this to the documentation of MSG_ZEROCOPY? I think this could be really helpful for all users of the zerocopy feature. Thanks a lot Mathias