From owner-svn-src-head@freebsd.org Thu Feb 27 19:50:02 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 07C4624C53F; Thu, 27 Feb 2020 19:50:02 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48T3D925MWz4gC7; Thu, 27 Feb 2020 19:50:01 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E02C11DEC1; Thu, 27 Feb 2020 19:50:00 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01RJo0UW042312; Thu, 27 Feb 2020 19:50:00 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01RJnx1H042269; Thu, 27 Feb 2020 19:49:59 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <202002271949.01RJnx1H042269@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Thu, 27 Feb 2020 19:49:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358405 - head/contrib/tnftp/src X-SVN-Group: head X-SVN-Commit-Author: hrs X-SVN-Commit-Paths: head/contrib/tnftp/src X-SVN-Commit-Revision: 358405 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Feb 2020 19:50:02 -0000 Author: hrs Date: Thu Feb 27 19:49:59 2020 New Revision: 358405 URL: https://svnweb.freebsd.org/changeset/base/358405 Log: Fix poor performance of ftp(1) due to small SO_SNDBUF and SO_RCVBUF. ftp(1) from vendor/tnftp always tried the following for every TCP connection: 1. Get the current buffer length of SO_SNDBUF and SO_RCVBUF by getsockopt(2). 2. Invoke setsockopt(2) to set them to the same values after checking if they are in a range between 8 KiB to 8 MiB. This behavior broke dynamic buffer sizing enabled by default (net.inet.tcp.{recv,send}buf_auto sysctls) and led to a very poor transfer rate. The fetch(1) utility does not have this problem. This change prevents SO_SNDBUF and SO_RCVBUF from configuring when the buffer auto-sizing is enabled unless the buffer sizes are explicitly specified. PR: 240827 Spotted by: Yuichiro NAITO MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D23732 Modified: head/contrib/tnftp/src/cmds.c head/contrib/tnftp/src/ftp_var.h head/contrib/tnftp/src/main.c head/contrib/tnftp/src/util.c Modified: head/contrib/tnftp/src/cmds.c ============================================================================== --- head/contrib/tnftp/src/cmds.c Thu Feb 27 19:40:29 2020 (r358404) +++ head/contrib/tnftp/src/cmds.c Thu Feb 27 19:49:59 2020 (r358405) @@ -2653,10 +2653,14 @@ setxferbuf(int argc, char *argv[]) goto usage; } - if (dir & RATE_PUT) + if (dir & RATE_PUT) { sndbuf_size = size; - if (dir & RATE_GET) + auto_sndbuf = 0; + } + if (dir & RATE_GET) { rcvbuf_size = size; + auto_rcvbuf = 0; + } fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n", sndbuf_size, rcvbuf_size); code = 0; Modified: head/contrib/tnftp/src/ftp_var.h ============================================================================== --- head/contrib/tnftp/src/ftp_var.h Thu Feb 27 19:40:29 2020 (r358404) +++ head/contrib/tnftp/src/ftp_var.h Thu Feb 27 19:49:59 2020 (r358405) @@ -298,6 +298,8 @@ GLOBAL int options; /* used during socket creation */ GLOBAL int sndbuf_size; /* socket send buffer size */ GLOBAL int rcvbuf_size; /* socket receive buffer size */ +GLOBAL int auto_sndbuf; /* flag: if != 0 then use auto sndbuf size */ +GLOBAL int auto_rcvbuf; /* flag: if != 0 then use auto rcvbuf size */ GLOBAL int macnum; /* number of defined macros */ GLOBAL struct macel macros[16]; Modified: head/contrib/tnftp/src/main.c ============================================================================== --- head/contrib/tnftp/src/main.c Thu Feb 27 19:40:29 2020 (r358404) +++ head/contrib/tnftp/src/main.c Thu Feb 27 19:49:59 2020 (r358405) @@ -127,6 +127,9 @@ __RCSID(" NetBSD: main.c,v 1.117 2009/07/13 19:05:41 r #include #endif /* tnftp */ +#ifdef __FreeBSD__ +#include +#endif #define GLOBAL /* force GLOBAL decls in ftp_var.h to be declared */ #include "ftp_var.h" @@ -509,6 +512,13 @@ main(int volatile argc, char **volatile argv) (void)xsignal(SIGUSR1, crankrate); (void)xsignal(SIGUSR2, crankrate); (void)xsignal(SIGWINCH, setttywidth); + + auto_rcvbuf = ((sysctlbyname("net.inet.tcp.recvbuf_auto", + &auto_rcvbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) && + auto_rcvbuf == 1); + auto_sndbuf = ((sysctlbyname("net.inet.tcp.sendbuf_auto", + &auto_sndbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) && + auto_sndbuf == 1); if (argc > 0) { if (isupload) { Modified: head/contrib/tnftp/src/util.c ============================================================================== --- head/contrib/tnftp/src/util.c Thu Feb 27 19:40:29 2020 (r358404) +++ head/contrib/tnftp/src/util.c Thu Feb 27 19:49:59 2020 (r358405) @@ -1087,13 +1087,27 @@ setupsockbufsize(int sock) sndbuf_size); } +#ifdef __FreeBSD__ + DPRINTF("auto_rcvbuf = %d\n", auto_rcvbuf); + if (auto_sndbuf == 0) { +#endif if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *)&sndbuf_size, sizeof(sndbuf_size)) == -1) warn("Unable to set sndbuf size %d", sndbuf_size); +#ifdef __FreeBSD__ + } +#endif +#ifdef __FreeBSD__ + DPRINTF("auto_sndbuf = %d\n", auto_sndbuf); + if (auto_rcvbuf == 0) { +#endif if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void *)&rcvbuf_size, sizeof(rcvbuf_size)) == -1) warn("Unable to set rcvbuf size %d", rcvbuf_size); +#ifdef __FreeBSD__ + } +#endif } /*