From owner-svn-src-all@freebsd.org Tue Oct 4 20:26:19 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9D8F3AF5B42; Tue, 4 Oct 2016 20:26:19 +0000 (UTC) (envelope-from glebius@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 mx1.freebsd.org (Postfix) with ESMTPS id 6E19ABAD; Tue, 4 Oct 2016 20:26:19 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u94KQImb040728; Tue, 4 Oct 2016 20:26:18 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u94KQIpw040727; Tue, 4 Oct 2016 20:26:18 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201610042026.u94KQIpw040727@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 4 Oct 2016 20:26:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r306685 - stable/11/sys/kern X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2016 20:26:19 -0000 Author: glebius Date: Tue Oct 4 20:26:18 2016 New Revision: 306685 URL: https://svnweb.freebsd.org/changeset/base/306685 Log: Merge r306212: Fix regression from r297400, which truncates headers in case of low socket buffer and put a small optimization for low socket buffer case: - Do not hack uio_resid, and let m_uiotombuf() properly take care of it. This fixes truncation of headers at low buffer. - If headers ate all the space, jump right to the end of the cycle, to avoid doing single page I/O and allocating zero length mbuf. - Clear hdr_uio only if space is positive, which indicates that all uio was copied in. Modified: stable/11/sys/kern/kern_sendfile.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/kern/kern_sendfile.c ============================================================================== --- stable/11/sys/kern/kern_sendfile.c Tue Oct 4 19:35:14 2016 (r306684) +++ stable/11/sys/kern/kern_sendfile.c Tue Oct 4 20:26:18 2016 (r306685) @@ -656,10 +656,18 @@ retry_space: if (hdr_uio != NULL && hdr_uio->uio_resid > 0) { hdr_uio->uio_td = td; hdr_uio->uio_rw = UIO_WRITE; - hdr_uio->uio_resid = min(hdr_uio->uio_resid, space); - mh = m_uiotombuf(hdr_uio, M_WAITOK, 0, 0, 0); + mh = m_uiotombuf(hdr_uio, M_WAITOK, space, 0, 0); hdrlen = m_length(mh, &mhtail); space -= hdrlen; + /* + * If header consumed all the socket buffer space, + * don't waste CPU cycles and jump to the end. + */ + if (space == 0) { + sfio = NULL; + nios = 0; + goto prepend_header; + } hdr_uio = NULL; } @@ -806,6 +814,7 @@ retry_space: /* Prepend header, if any. */ if (hdrlen) { +prepend_header: mhtail->m_next = m; m = mh; mh = NULL;