From owner-svn-src-all@freebsd.org Sun Aug 18 18:40:13 2019 Return-Path: Delivered-To: svn-src-all@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 71895CE400; Sun, 18 Aug 2019 18:40:13 +0000 (UTC) (envelope-from mjg@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) server-signature RSA-PSS (4096 bits) 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 46BQpj26rgz3LX0; Sun, 18 Aug 2019 18:40:13 +0000 (UTC) (envelope-from mjg@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2A53A641D; Sun, 18 Aug 2019 18:40:13 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7IIeDD4055890; Sun, 18 Aug 2019 18:40:13 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7IIeCAL055888; Sun, 18 Aug 2019 18:40:12 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201908181840.x7IIeCAL055888@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 18 Aug 2019 18:40:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351193 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 351193 X-SVN-Commit-Repository: base 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.29 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: Sun, 18 Aug 2019 18:40:13 -0000 Author: mjg Date: Sun Aug 18 18:40:12 2019 New Revision: 351193 URL: https://svnweb.freebsd.org/changeset/base/351193 Log: vfs: stop always overwriting ->mnt_stat in VFS_STATFS The struct is already populated on each mount (and remount). Fields are either constant or not used by filesystem in the first place. Some infrequently used functions use it to avoid having to allocate a new buffer and are left alone. The current code results in an avoidable copying single-threaded and significant cache line bouncing multithreaded While here deduplicate initial filling of the struct. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21317 Modified: head/sys/kern/vfs_mount.c head/sys/kern/vfs_syscalls.c Modified: head/sys/kern/vfs_mount.c ============================================================================== --- head/sys/kern/vfs_mount.c Sun Aug 18 17:12:06 2019 (r351192) +++ head/sys/kern/vfs_mount.c Sun Aug 18 18:40:12 2019 (r351193) @@ -1831,12 +1831,15 @@ vfs_copyopt(struct vfsoptlist *opts, const char *name, int __vfs_statfs(struct mount *mp, struct statfs *sbp) { - int error; - error = mp->mnt_op->vfs_statfs(mp, &mp->mnt_stat); - if (sbp != &mp->mnt_stat) - *sbp = mp->mnt_stat; - return (error); + /* + * Set these in case the underlying filesystem fails to do so. + */ + sbp->f_version = STATFS_VERSION; + sbp->f_namemax = NAME_MAX; + sbp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; + + return (mp->mnt_op->vfs_statfs(mp, sbp)); } void Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Sun Aug 18 17:12:06 2019 (r351192) +++ head/sys/kern/vfs_syscalls.c Sun Aug 18 18:40:12 2019 (r351193) @@ -248,7 +248,6 @@ statfs_scale_blocks(struct statfs *sf, long max_size) static int kern_do_statfs(struct thread *td, struct mount *mp, struct statfs *buf) { - struct statfs *sp; int error; if (mp == NULL) @@ -262,17 +261,9 @@ kern_do_statfs(struct thread *td, struct mount *mp, st if (error != 0) goto out; #endif - /* - * Set these in case the underlying filesystem fails to do so. - */ - sp = &mp->mnt_stat; - sp->f_version = STATFS_VERSION; - sp->f_namemax = NAME_MAX; - sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; - error = VFS_STATFS(mp, sp); + error = VFS_STATFS(mp, buf); if (error != 0) goto out; - *buf = *sp; if (priv_check(td, PRIV_VFS_GENERATION)) { buf->f_fsid.val[0] = buf->f_fsid.val[1] = 0; prison_enforce_statfs(td->td_ucred, mp, buf); @@ -476,13 +467,6 @@ restart: if (sfsp != NULL && count < maxcount) { sp = &mp->mnt_stat; /* - * Set these in case the underlying filesystem - * fails to do so. - */ - sp->f_version = STATFS_VERSION; - sp->f_namemax = NAME_MAX; - sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; - /* * If MNT_NOWAIT is specified, do not refresh * the fsstat cache. */ @@ -4545,7 +4529,6 @@ sys_fhstatfs(struct thread *td, struct fhstatfs_args * int kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf) { - struct statfs *sp; struct mount *mp; struct vnode *vp; int error; @@ -4569,16 +4552,7 @@ kern_fhstatfs(struct thread *td, fhandle_t fh, struct if (error != 0) goto out; #endif - /* - * Set these in case the underlying filesystem fails to do so. - */ - sp = &mp->mnt_stat; - sp->f_version = STATFS_VERSION; - sp->f_namemax = NAME_MAX; - sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; - error = VFS_STATFS(mp, sp); - if (error == 0) - *buf = *sp; + error = VFS_STATFS(mp, buf); out: vfs_unbusy(mp); return (error);