From owner-dev-commits-src-main@freebsd.org Sun Jan 3 01:02:19 2021 Return-Path: Delivered-To: dev-commits-src-main@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 44FE04BECD9; Sun, 3 Jan 2021 01:02:19 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4D7gTR12VTz3jkk; Sun, 3 Jan 2021 01:02:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0C6C11EF3F; Sun, 3 Jan 2021 01:02:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10312Ije061763; Sun, 3 Jan 2021 01:02:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10312IAC061762; Sun, 3 Jan 2021 01:02:18 GMT (envelope-from git) Date: Sun, 3 Jan 2021 01:02:18 GMT Message-Id: <202101030102.10312IAC061762@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: c98a764c681f - main - cp(1): fix performance issue for large non-sparse file copies MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c98a764c681f8b70812a9f13a6e61c96aa1a69d2 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jan 2021 01:02:19 -0000 The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=c98a764c681f8b70812a9f13a6e61c96aa1a69d2 commit c98a764c681f8b70812a9f13a6e61c96aa1a69d2 Author: Rick Macklem AuthorDate: 2021-01-03 00:58:43 +0000 Commit: Rick Macklem CommitDate: 2021-01-03 00:58:43 +0000 cp(1): fix performance issue for large non-sparse file copies PR252358 reported a serious performance problem when copying a large non-sparse file on a UFS file system. This problem seems to have been caused by a large number of SEEK_HOLE operations, with one done for each copy_file_range(2) call. This patch modifies cp(1) to use a large (SSIZE_MAX) len argument, reducing the number of system calls and resolving the performance issue. While here, convert the type of the "rcount" from "int" to "ssize_t" so that it is consistent with that returned by both read(2) and copy_file_range(2). PR: 252358 Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D27937 --- bin/cp/utils.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 1a3b5502145a..7742b0d0a516 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -74,11 +74,10 @@ __FBSDID("$FreeBSD$"); */ #define BUFSIZE_SMALL (MAXPHYS) -static int +static ssize_t copy_fallback(int from_fd, int to_fd, char *buf, size_t bufsize) { - int rcount; - ssize_t wresid, wcount = 0; + ssize_t rcount, wresid, wcount = 0; char *bufp; rcount = read(from_fd, buf, bufsize); @@ -100,10 +99,10 @@ copy_file(const FTSENT *entp, int dne) static char *buf = NULL; static size_t bufsize; struct stat *fs; - ssize_t wcount; + ssize_t rcount, wcount; size_t wresid; off_t wtotal; - int ch, checkch, from_fd, rcount, rval, to_fd; + int ch, checkch, from_fd, rval, to_fd; char *bufp; #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED char *p; @@ -236,7 +235,7 @@ copy_file(const FTSENT *entp, int dne) do { if (use_copy_file_range) { rcount = copy_file_range(from_fd, NULL, - to_fd, NULL, bufsize, 0); + to_fd, NULL, SSIZE_MAX, 0); if (rcount < 0 && errno == EINVAL) { /* Prob a non-seekable FD */ use_copy_file_range = 0;