From nobody Fri Dec 02 21:05:57 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NP5856fWQz4jJy3; Fri, 2 Dec 2022 21:05:57 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NP5856BcMz4LLq; Fri, 2 Dec 2022 21:05:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670015157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dd0XToyslDqJjszOraJVHgX7uYulfpWYa4HfZK1lC/g=; b=g3tixeKzuKTfPBW7uDRIoS8P9I2FhRB10aqzyXVzQ9B6blpSEe72eKgaAoC0qLcFN7l6sI R067cKS4dqxOhw3FQ0sl3vvtlDtWah964srPA/rDhietbjXrjiNSNaEPDaZZk4DOs1GEoB nTA4EkqbgU/pvtLYycySH+I/zh1ZmNAimyFd0nFq7NpOGHmHtX7pgl6/67puZTsBZeL7NE UcxtqRez2oAGpI9rfhBDgRhdTO9Rg9+KP9LQnyNU+zE3J7Pv41wUvg/JoB9ASU03laMXer IfZB/mddhLru6Sf7Olf3iKEDckks10u46hDHNAgDL9GWybySu1IcxhA6zxg5Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670015157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dd0XToyslDqJjszOraJVHgX7uYulfpWYa4HfZK1lC/g=; b=k+PrTRPiaAmPCzo333DiMkNqMji4KnZ30jEySk0d2v6+alFyjQp7rCC6cKq5Ktvl+6+DZK hUpDiS4yyny7Zkj/bCCHriI+pYhO+vSfafiYVC3YZexU0iAhYfb7GAVwqD04a64QPlDpSm h2hXVuCalgNQNleOBV3ajnAwhXIWMANw0XMWUrTS6/ktdtewfUBB6Pj0P/pvMP63Fw7OYh YAFQNUEHyLjPKuzlZr2rs8nlP/iAnWmKhE6yjplQzP/R3LgAZfsxtPBI6PqDCdMLWCMHgB AEUIBtFkBCrn+q53epE+RQlEhm5JNSO4qW2Hl8IAaPZm+U1N6Wz+DgsyunILkw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670015157; a=rsa-sha256; cv=none; b=nZNOk+tGLnu62+I1mrxREVkqn0YhJyOlZB+wOx26tjdy4p58JTefGxOVEoQfwflKa8oIwG zUNirzquoKGSfI6uyFCCkWFCMeGP90cwTnl8cGRnwFgK1VLtrEjH2R7Sp0j/QXKZCZ3+h5 4IDRE1eiXZGoge60XXMSPIwDdvukMQhcXawVatSB7iD5Lro+qUHF64q4BfOGVec6J5daEv i30HwY4MR7oaq71jSRbRW1AWmaACQW+9UnhBdopO5WfW7fGKvw7CAyiWR1JxQGE2kE50G/ Yx0f9qWlSUIq5gxJPReUy1hFlMuK96uVp+uf+7eeTfrOvwX1AJlZwfMxqexGgQ== 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 4NP5855DJWzVCT; Fri, 2 Dec 2022 21:05:57 +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 2B2L5vYW091228; Fri, 2 Dec 2022 21:05:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B2L5vn3091227; Fri, 2 Dec 2022 21:05:57 GMT (envelope-from git) Date: Fri, 2 Dec 2022 21:05:57 GMT Message-Id: <202212022105.2B2L5vn3091227@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 7a074c844994 - stable/13 - vfs_vnops.c: Fix blksize for ZFS List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 7a074c8449943eb9fd156987cdb3a36a4de0dd8d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=7a074c8449943eb9fd156987cdb3a36a4de0dd8d commit 7a074c8449943eb9fd156987cdb3a36a4de0dd8d Author: Rick Macklem AuthorDate: 2022-11-17 01:37:22 +0000 Commit: Rick Macklem CommitDate: 2022-12-02 21:04:46 +0000 vfs_vnops.c: Fix blksize for ZFS Since ZFS reports _PC_MIN_HOLE_SIZE as 512 (although it appears that an unwritten region must be at least f_iosize to remain unallocated), vn_generic_copy_file_range() uses 4096 for the copy blksize for ZFS, reulting in slow copies. For most other file systems, _PC_MIN_HOLE_SIZE and f_iosize are the same value, so this patch modifies the code to use f_iosize for most cases. It also documents in comments why the blksize is being set a certain way, so that the code does not appear to be doing "magic math". (cherry picked from commit 4ee16246f97825e893e0a4a4499d1bbe5bc07b6a) --- sys/kern/vfs_vnops.c | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index b71d37820b0c..a54d2c463dc7 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -3241,7 +3241,7 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, int error, interrupted; bool cantseek, readzeros, eof, lastblock, holetoeof; ssize_t aresid, r = 0; - size_t copylen, len, rem, savlen; + size_t copylen, len, savlen; char *dat; long holein, holeout; struct timespec curts, endts; @@ -3313,31 +3313,38 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, if (error != 0) goto out; - /* - * Set the blksize to the larger of the hole sizes for invp and outvp. - * If hole sizes aren't available, set the blksize to the larger - * f_iosize of invp and outvp. - * This code expects the hole sizes and f_iosizes to be powers of 2. - * This value is clipped at 4Kbytes and 1Mbyte. - */ - blksize = MAX(holein, holeout); - - /* Clip len to end at an exact multiple of hole size. */ - if (blksize > 1) { - rem = *inoffp % blksize; - if (rem > 0) - rem = blksize - rem; - if (len > rem && len - rem > blksize) - len = savlen = rounddown(len - rem, blksize) + rem; - } - - if (blksize <= 1) + if (holein == 0 && holeout > 0) { + /* + * For this special case, the input data will be scanned + * for blocks of all 0 bytes. For these blocks, the + * write can be skipped for the output file to create + * an unallocated region. + * Therefore, use the appropriate size for the output file. + */ + blksize = holeout; + if (blksize <= 512) { + /* + * Use f_iosize, since ZFS reports a _PC_MIN_HOLE_SIZE + * of 512, although it actually only creates + * unallocated regions for blocks >= f_iosize. + */ + blksize = outvp->v_mount->mnt_stat.f_iosize; + } + } else { + /* + * Use the larger of the two f_iosize values. If they are + * not the same size, one will normally be an exact multiple of + * the other, since they are both likely to be a power of 2. + */ blksize = MAX(invp->v_mount->mnt_stat.f_iosize, outvp->v_mount->mnt_stat.f_iosize); + } + + /* Clip to sane limits. */ if (blksize < 4096) blksize = 4096; - else if (blksize > 1024 * 1024) - blksize = 1024 * 1024; + else if (blksize > maxphys) + blksize = maxphys; dat = malloc(blksize, M_TEMP, M_WAITOK); /*