git: 66b177e1b433 - main - vfs: reduce spurious zeroing in VOP_STAT

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Sat, 12 Mar 2022 12:14:32 UTC
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=66b177e1b4330f7b26bfb4d73bb4cc6581721cc9

commit 66b177e1b4330f7b26bfb4d73bb4cc6581721cc9
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-03-12 11:49:17 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-03-12 12:05:37 +0000

    vfs: reduce spurious zeroing in VOP_STAT
    
    clang fails to take advantage of the fact that majority of the struct
    gets written to in the routine and decides to bzero the entire thing.
    
    Explicitly zero padding and spare fields, relying on KMSAN to catch
    problems should anything pop up later which also needs explicit
    zeroing.
    
    fstat on tmpfs (ops/s):
    before: 8216636
    after:  8508033
---
 sys/sys/vnode.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index f595029bdd14..7bd483d2e17c 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -970,8 +970,11 @@ void	vop_rename_fail(struct vop_rename_args *ap);
 	int _error;								\
 	AUDIT_ARG_VNODE1(ap->a_vp);						\
 	_error = mac_vnode_check_stat(_ap->a_active_cred, _ap->a_file_cred, _ap->a_vp);\
-	if (__predict_true(_error == 0))					\
-		bzero(_ap->a_sb, sizeof(*_ap->a_sb));				\
+	if (__predict_true(_error == 0)) {					\
+		ap->a_sb->st_padding0 = 0;					\
+		ap->a_sb->st_padding1 = 0;					\
+		bzero(_ap->a_sb->st_spare, sizeof(_ap->a_sb->st_spare));	\
+	}									\
 	_error;									\
 })