git: 2443068d4860 - main - vfs: shrink struct vnode to 448 bytes on LP64

Mateusz Guzik mjg at FreeBSD.org
Sun Feb 21 21:10:33 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=2443068d486020ed9a4250e0d3b28168c40f741a

commit 2443068d486020ed9a4250e0d3b28168c40f741a
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-02-21 19:48:49 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-02-21 21:07:14 +0000

    vfs: shrink struct vnode to 448 bytes on LP64
    
    ... by moving v_hash into a 4 byte hole.
    
    Combined with several previous size reductions this makes the size small
    enough to fit 9 vnodes per page as opposed to 8.
    
    Add a compilation time assert so that this is not unknowingly worsened.
    
    Note the structure still remains bigger than it should be.
---
 sys/sys/vnode.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index d71f3bfcb817..0e46bea14b64 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -109,6 +109,7 @@ struct vnode {
 	short	v_irflag;			/* i frequently read flags */
 	seqc_t	v_seqc;				/* i modification count */
 	uint32_t v_nchash;			/* u namecache hash */
+	u_int	v_hash;
 	struct	vop_vector *v_op;		/* u vnode operations vector */
 	void	*v_data;			/* u private data for fs */
 
@@ -172,9 +173,19 @@ struct vnode {
 	int	v_writecount;			/* I ref count of writers or
 						   (negative) text users */
 	int	v_seqc_users;			/* i modifications pending */
-	u_int	v_hash;
 };
 
+#ifndef DEBUG_LOCKS
+#ifdef _LP64
+/*
+ * Not crossing 448 bytes fits 9 vnodes per page. If you have to add fields
+ * to the structure and there is nothing which can be done to prevent growth
+ * then so be it. But don't grow it without a good reason.
+ */
+_Static_assert(sizeof(struct vnode) <= 448, "vnode size crosses 448 bytes");
+#endif
+#endif
+
 #endif /* defined(_KERNEL) || defined(_KVM_VNODE) */
 
 #define	bo2vnode(bo)	__containerof((bo), struct vnode, v_bufobj)


More information about the dev-commits-src-main mailing list