diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_znode_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_znode_os.c --- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_znode_os.c +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_znode_os.c @@ -67,8 +67,12 @@ #include "zfs_comutil.h" /* Used by fstat(1). */ +#ifdef SYSCTL_SIZEOF +SYSCTL_SIZEOF(znode, znode_t); +#else SYSCTL_INT(_debug_sizeof, OID_AUTO, znode, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, sizeof (znode_t), "sizeof(znode_t)"); +#endif /* * Define ZNODE_STATS to turn on statistic gathering. By default, it is only diff --git a/sys/fs/devfs/devfs_devs.c b/sys/fs/devfs/devfs_devs.c --- a/sys/fs/devfs/devfs_devs.c +++ b/sys/fs/devfs/devfs_devs.c @@ -121,11 +121,8 @@ CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_ANYBODY|CTLFLAG_MPSAFE, NULL, 0, sysctl_devname, "", "devname(3) handler"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, cdev, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct cdev), "sizeof(struct cdev)"); - -SYSCTL_INT(_debug_sizeof, OID_AUTO, cdev_priv, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct cdev_priv), "sizeof(struct cdev_priv)"); +SYSCTL_SIZEOF_STRUCT(cdev); +SYSCTL_SIZEOF_STRUCT(cdev_priv); struct cdev * devfs_alloc(int flags) diff --git a/sys/geom/geom_kern.c b/sys/geom/geom_kern.c --- a/sys/geom/geom_kern.c +++ b/sys/geom/geom_kern.c @@ -229,13 +229,8 @@ &g_collectstats, 0, "Control statistics collection on GEOM providers and consumers"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, g_class, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct g_class), "sizeof(struct g_class)"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, g_geom, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct g_geom), "sizeof(struct g_geom)"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, g_provider, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct g_provider), "sizeof(struct g_provider)"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, g_consumer, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct g_consumer), "sizeof(struct g_consumer)"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, g_bioq, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct g_bioq), "sizeof(struct g_bioq)"); +SYSCTL_SIZEOF_STRUCT(g_class); +SYSCTL_SIZEOF_STRUCT(g_geom); +SYSCTL_SIZEOF_STRUCT(g_provider); +SYSCTL_SIZEOF_STRUCT(g_consumer); +SYSCTL_SIZEOF_STRUCT(g_bioq); diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c --- a/sys/kern/kern_mib.c +++ b/sys/kern/kern_mib.c @@ -730,11 +730,9 @@ localbase, sizeof(localbase), "Prefix used to install and locate add-on packages"); #include -SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct vnode), "sizeof(struct vnode)"); +SYSCTL_SIZEOF_STRUCT(vnode); -SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct proc), "sizeof(struct proc)"); +SYSCTL_SIZEOF_STRUCT(proc); static int sysctl_kern_pid_max(SYSCTL_HANDLER_ARGS) @@ -770,19 +768,15 @@ #include #include -SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct bio), "sizeof(struct bio)"); -SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct buf), "sizeof(struct buf)"); +SYSCTL_SIZEOF_STRUCT(bio); +SYSCTL_SIZEOF_STRUCT(buf); #include -SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); +SYSCTL_SIZEOF_STRUCT(kinfo_proc); /* Used by kernel debuggers. */ const int pcb_size = sizeof(struct pcb); -SYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)"); +SYSCTL_SIZEOF_STRUCT(pcb); /* XXX compatibility, remove for 6.0 */ #include diff --git a/sys/kern/subr_devstat.c b/sys/kern/subr_devstat.c --- a/sys/kern/subr_devstat.c +++ b/sys/kern/subr_devstat.c @@ -599,5 +599,4 @@ } } -SYSCTL_INT(_debug_sizeof, OID_AUTO, devstat, CTLFLAG_RD, - SYSCTL_NULL_INT_PTR, sizeof(struct devstat), "sizeof(struct devstat)"); +SYSCTL_SIZEOF_STRUCT(devstat); diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -627,8 +627,7 @@ #endif /* Export size information to userland */ -SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, - sizeof(struct namecache), "sizeof(struct namecache)"); +SYSCTL_SIZEOF_STRUCT(namecache); /* * The new name cache statistics diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -36,6 +36,7 @@ #define _SYS_SYSCTL_H_ #ifdef _KERNEL +#include #include #include #endif @@ -932,6 +933,26 @@ CTLFLAG_RD | CTLFLAG_CAPRD | CTLTYPE_INT | CTLFLAG_MPSAFE, \ NULL, 1, sysctl_handle_int, "I", desc, "feature"); +/* + * Adding new leaves to the 'debug.sizeof' MIB tree for ad-hoc reasons is + * discouraged, and in particular for reporting to developers the size of some + * kernel structures, which can be obtained by the following alternative means: + * 1. In GDB, load a full kernel image and use 'print(sizeof(struct XXX))'. + * Alternatively, use 'ptype/o struct XXX' to additionally get the offsets + * and size of all structure's fields. + * 2. If the structure is allocated from UMA, then 'vmstat -z' reports its size + * (the mapping between structure types and zones is usually + * straightforward). + */ +/* Generates a read-only sysctl reporting the size of an object/structure. */ +#define SYSCTL_SIZEOF(name, expr) \ + SYSCTL_INT(_debug_sizeof, OID_AUTO, name, CTLFLAG_RD, \ + SYSCTL_NULL_INT_PTR, sizeof(expr), \ + "sizeof(" __STRING(expr) ")"); +/* Same, specialized for structures. */ +#define SYSCTL_SIZEOF_STRUCT(struct_name) \ + SYSCTL_SIZEOF(struct_name, struct struct_name) + #endif /* _KERNEL */ /*