From nobody Fri Mar 29 01:16:39 2024 X-Original-To: dev-commits-src-all@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 4V5Mtv2yG1z5GTsd; Fri, 29 Mar 2024 01:16:39 +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 4V5Mtv2RGDz43y0; Fri, 29 Mar 2024 01:16:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711674999; 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=PLjKcypjMYUby12hrEC0yBB7ltD7Apl1lElnp3ThxXE=; b=EMkUvx/kNSz3pd6ipDNlBRMQzY9ork6GxGNXzcMqsnZ1mK+clYpGAyayUPfkWjl/jt9VV4 vpfHVr58T4aOsaQrWCf+QEIC3Fq9jL8ZBfIQo2pfDdbscPPJ3YySQesRStcafRK0jp0gWC 0V4Gkict90lEhZr1TwJriOKMqdTwW94cdvpiUAgENJVAusvq31BItVM0VQas20apRAlH6t j3psIW5672R1Ln3refI41P63Mr+/ip5UlnJ5PqC0dpr/3zcqoWXgyjbBwmch0ymhs8NATB +K+WLzTKzoEmYVoz73+GtXASLEf53XUjGhy3JZWrca1mIEH+zCs5kOseUeYA2A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711674999; a=rsa-sha256; cv=none; b=qwCLtwb1LwelW7UcR/IOFHD/9nGdkgtwMxTigqv575Ml/GTauFid8A+cb4FFdchXSuHpZb KwTid3rLuLW1LpQ3aeuepOxxJV5tGKuEh85dkUPkRE+R6iR7THMqQIfkAZm98Vg8l4wWz9 tMSctB7XpXFu1scORZWn2oajv22L5ZGx8iaQJjb8Tfby6bO9ld8MRU0CeDSQTa7DjBvtaI F42z3PkIR/673/803aOdJVMhAu0heqj1qALkf8boYS3ZvlbVSIcqP+glAoX5U47LyRKkC+ YFxHKlPoqUGtWCwnbeIQ63A9axQe2dpn5rd9bh2v8vntVS3Ee368I1IRoAjMQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711674999; 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=PLjKcypjMYUby12hrEC0yBB7ltD7Apl1lElnp3ThxXE=; b=hK03kdaaneLG9ozCkUG4ODhn4y5Fx3Kt3/rPoH1hnYgAiiZ6jurJwkCRLEVm5jPZyxj6xX Opc03YgRM4xTrcPPN9MyO9OaFmhzsI+yk9z8ydRfPEgqc5BNese0u1/WD56ZtOBt92E4ty BTbTfy3PV0tkuitOhN59OU9YvOGVwrfi6+otz8zNgbJG5AxhhPgpBsVnGKz0gWkPb4Pbmd JxBeKhUcntRJJ2yLlZ2xPKHFS/6vFIIW2SayT/t1T2N9vGotHlmNNWd1ouaYdgOvS1EYEb fKx/polpS3K36SOHDvf8D6Cg7fJ5DumsX8Fllbq/EYccmpXapNaz+5K3p5x9tA== 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 4V5Mtv1jXjzr5V; Fri, 29 Mar 2024 01:16:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42T1Gdo6050637; Fri, 29 Mar 2024 01:16:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42T1Gdul050634; Fri, 29 Mar 2024 01:16:39 GMT (envelope-from git) Date: Fri, 29 Mar 2024 01:16:39 GMT Message-Id: <202403290116.42T1Gdul050634@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: df2b8b494412 - stable/14 - vfs_vnops.c: Use va_bytes >= va_size hint to avoid SEEK_DATA/SEEKHOLE List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/14 X-Git-Reftype: branch X-Git-Commit: df2b8b494412259050254e04cb4d2e13ab815783 Auto-Submitted: auto-generated The branch stable/14 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=df2b8b494412259050254e04cb4d2e13ab815783 commit df2b8b494412259050254e04cb4d2e13ab815783 Author: Rick Macklem AuthorDate: 2024-03-15 00:35:32 +0000 Commit: Rick Macklem CommitDate: 2024-03-29 01:15:09 +0000 vfs_vnops.c: Use va_bytes >= va_size hint to avoid SEEK_DATA/SEEKHOLE vn_generic_copy_file_range() tries to maintain holes in file ranges being copied, using SEEK_DATA/SEEK_HOLE where possible, Unfortunately SEEK_DATA/SEEK_HOLE operations can take a long time under certain circumstances. Although it is not currently possible to know if a file has unallocated data regions, the case where va_bytes >= va_size is a strong hint that there are no unallocated data regions. This hint does not work well for file systems doing compression, but since it is only a hint, it is still useful. For the case of va_bytes >= va_size, avoid doing SEEK_DATA/SEEK_HOLE. (cherry picked from commit 89f1dcb3eb468e4cbaebd1ccde9a643d85f1282e) --- sys/kern/vfs_vnops.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index a16e137755b1..51386d0e9581 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -3336,14 +3336,15 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, struct vnode *outvp, off_t *outoffp, size_t *lenp, unsigned int flags, struct ucred *incred, struct ucred *outcred, struct thread *fsize_td) { + struct vattr inva; struct mount *mp; off_t startoff, endoff, xfer, xfer2; u_long blksize; int error, interrupted; - bool cantseek, readzeros, eof, lastblock, holetoeof; + bool cantseek, readzeros, eof, lastblock, holetoeof, sparse; ssize_t aresid, r = 0; size_t copylen, len, savlen; - off_t insize, outsize; + off_t outsize; char *dat; long holein, holeout; struct timespec curts, endts; @@ -3359,11 +3360,26 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, goto out; if (VOP_PATHCONF(invp, _PC_MIN_HOLE_SIZE, &holein) != 0) holein = 0; - error = vn_getsize_locked(invp, &insize, incred); + error = VOP_GETATTR(invp, &inva, incred); + if (error == 0 && inva.va_size > OFF_MAX) + error = EFBIG; VOP_UNLOCK(invp); if (error != 0) goto out; + /* + * Use va_bytes >= va_size as a hint that the file does not have + * sufficient holes to justify the overhead of doing FIOSEEKHOLE. + * This hint does not work well for file systems doing compression + * and may fail when allocations for extended attributes increases + * the value of va_bytes to >= va_size. + */ + sparse = true; + if (holein != 0 && inva.va_bytes >= inva.va_size) { + holein = 0; + sparse = false; + } + mp = NULL; error = vn_start_write(outvp, &mp, V_WAIT); if (error == 0) @@ -3397,9 +3413,9 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, error = vn_getsize_locked(outvp, &outsize, outcred); if (error == 0 && outsize > *outoffp && *outoffp <= OFF_MAX - len && outsize <= *outoffp + len && - *inoffp < insize && - *outoffp <= OFF_MAX - (insize - *inoffp) && - outsize <= *outoffp + (insize - *inoffp)) { + *inoffp < inva.va_size && + *outoffp <= OFF_MAX - (inva.va_size - *inoffp) && + outsize <= *outoffp + (inva.va_size - *inoffp)) { #ifdef MAC error = mac_vnode_check_write(curthread->td_ucred, outcred, outvp); @@ -3417,7 +3433,7 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, if (error != 0) goto out; - if (holein == 0 && holeout > 0) { + if (sparse && holein == 0 && holeout > 0) { /* * For this special case, the input data will be scanned * for blocks of all 0 bytes. For these blocks, the @@ -3488,7 +3504,7 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, error = VOP_IOCTL(invp, FIOSEEKDATA, &startoff, 0, incred, curthread); if (error == ENXIO) { - startoff = endoff = insize; + startoff = endoff = inva.va_size; eof = holetoeof = true; error = 0; } @@ -3551,6 +3567,8 @@ vn_generic_copy_file_range(struct vnode *invp, off_t *inoffp, cantseek = false; } else { cantseek = true; + if (!sparse) + cantseek = false; startoff = *inoffp; copylen = len; error = 0;