From nobody Fri Mar 15 00:36:58 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 4Twlgb0cb7z5DwHk; Fri, 15 Mar 2024 00:36:59 +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 4Twlgb0541z42lw; Fri, 15 Mar 2024 00:36:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710463019; 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=Nqfeskq4URHlxAsYFr+IThMzMMtt8adOj7ZVZ9SNWU8=; b=ymw0W7pXb7WKAh/MN/AiYV2vNhCFJHy+96M4OxDoXsLqPt0o62E8ZwiU66xWmjvw1x7+/V 6PhI4mdpUwurCAhu4fPxJInafoO9Ip/7Z781ZEBJ7KOxM3PyVYoGhln4Yu7418LG+/bsRA 0lB4UFiIWsh2TIfvvJLZz0YCAAoNyFcCPis0ozK3016S/he4BkiE2eVzqN3TQKIxacoORa AyUKnD+0Ib4ou3M3AyVWOFf6ns0WGouYoB6ufacqxVZo18t5ipsbMDp3/ZQMed8TN12yrV PRvaX9qmmb2juFry2goBIZr1WM2oHF6MDbyUwNFE/aGfySYksadjWiKEVGZFSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710463019; a=rsa-sha256; cv=none; b=mXRdnkSIP1wOzce+IXboOvpbNZQoYYwmJn5tAKyNuljoGuEYtcvgiiSoikKyjtzlqY/mj2 t6b7gw7O6g7fTPd/SojnoO092nSxovQsg4i3dpYCm4g7gyrVR8wnG4ds6wqGJrqfnMtmpy f4UA6LksABNhOqrZdpWnJiFm4XYtpBvmY64IeJh5j0e8S2z7zqa27toN7jxlaWDxeNwv1Q xl8EibHoDsTcCSJWnimSBDPbDtSeAp2t4a5P9JTc7g3UFdqyjJOrTOp8VOj8inpjftIKgv r8YOtCiqgGPumHdAqWFCGvy0D1BbRI0HcF0Uoy+Thygi2vQG1TdwBTNBQOaCKg== 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=1710463019; 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=Nqfeskq4URHlxAsYFr+IThMzMMtt8adOj7ZVZ9SNWU8=; b=c3oO6ssojfLSyqNu3PDPlsYvAdTlWYfteyiWsjUAAMhRFcgmNhU92Tn7tuxEhl07WJyIYc MKWci24w4HfJGCsdrk5uO59XQ1nUXFjBooIQgphSVFYPmj08OFM3XSLf2sM2hf8CwyegY1 kHGxVQutArbVhMu1YZu1VvtzMdLfhLXIGk9XeNoiNBVuH6P34Cd4DbqJ0KElvWmppGZYWN fgNQC1bneGWL3DEVSc2MY/Omq+YazDjBCQYivoDMvPayxrsmLfuznUkNgdnoBAFJKWuz8S QP+kLgpOoAZWF8avKjEUAcMcM/856ag6xpP2Fd+1QMFz53Z7ixS7ZFEmMByMSg== 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 4TwlgZ6hGJzpvw; Fri, 15 Mar 2024 00:36:58 +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 42F0awod044198; Fri, 15 Mar 2024 00:36:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42F0awkj044196; Fri, 15 Mar 2024 00:36:58 GMT (envelope-from git) Date: Fri, 15 Mar 2024 00:36:58 GMT Message-Id: <202403150036.42F0awkj044196@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: 89f1dcb3eb46 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 89f1dcb3eb468e4cbaebd1ccde9a643d85f1282e Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=89f1dcb3eb468e4cbaebd1ccde9a643d85f1282e commit 89f1dcb3eb468e4cbaebd1ccde9a643d85f1282e Author: Rick Macklem AuthorDate: 2024-03-15 00:35:32 +0000 Commit: Rick Macklem CommitDate: 2024-03-15 00:35:32 +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. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D44509 --- 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 fd78b692b088..d79707555ac1 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -3334,14 +3334,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; @@ -3357,11 +3358,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) @@ -3395,9 +3411,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); @@ -3415,7 +3431,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 @@ -3486,7 +3502,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; } @@ -3549,6 +3565,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;