Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Feb 2023 09:52:05 +0800
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        Gleb Smirnoff <glebius@freebsd.org>
Cc:        Rick Macklem <rmacklem@freebsd.org>, bz@freebsd.org, jamie@freebsd.org, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: ef6fcc5e2b07 - main - nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
Message-ID:  <6AE3CB33-555F-444B-8263-70FDCA550798@FreeBSD.org>
In-Reply-To: <Y/Uz5B6ywWjaa1TB@FreeBSD.org>
References:  <202302202112.31KLCfQB080359@gitrepo.freebsd.org> <Y/Uz5B6ywWjaa1TB@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

> On Feb 22, 2023, at 5:13 AM, Gleb Smirnoff <glebius@freebsd.org> =
wrote:
>=20
> On Mon, Feb 20, 2023 at 09:12:41PM +0000, Rick Macklem wrote:
> R>     nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
> R>    =20
> R>     Commit ed03776ca7f4 enabled the vnet front end macros.
> R>     As such, for kernels built with the VIMAGE option will malloc
> R>     data and initialize locks on a per-vnet basis, typically
> R>     via a VNET_SYSINIT().
> R>    =20
> R>     This patch adds VNET_SYSUNINIT() macros to do the frees
> R>     of the per-vnet malloc'd data and destroys of per-vnet
> R>     locks.  It also removes the mtx_lock/mtx_unlock calls
> R>     from nfsrvd_cleancache(), since they are not needed.
>=20
> In the netinet/netinet6/TCP/UDP we came to a style where we avoid
> using IS_DEFAULT_VNET(). Instead doing global and per-vnet init
> in the same function:
>=20
> static globalfoo;
> VNET_DEFINE_STATIC(foobar);
>=20
> static void
> foo_vnet_init()
> {
> 	initialize(V_foobar);
> 	if (IS_DEFAULT_VNET(curvnet))
> 		initialize(globalfoo);
> 	=09
> }
> VNET_SYSINIT(foo_vnet_init, ....)
>=20
> We can do a separate init of global state and separate of per-VNET:
>=20
> static globalfoo;
> static void
> foo_init()
> {
> 	initialize(globalfoo);
> }
> SYSINIT(foo_init, ....)
>=20
> VNET_DEFINE_STATIC(foobar);
> static void
> foo_vnet_init()
> {
>        initialize(V_foobar);
> }
>=20
> This allows to:
>=20
> * guarantee that global state is initialized earlier than per-vnet
> * separate all global vars from all vnet vars, and keep them together, =
easier to maintain
> * makes it easier to write VNET_SYSUNINIT() that is complement to =
VNET_SYSINIT()
> * makes it easier to write SYSUNINIT(), if module is unloadable
> * sometimes global SYSINIT cab be avoided, if a static initializer is =
enough
>=20
> What do you guys think?
>=20
> --=20
> Gleb Smirnoff


+1 for that.

Also be aware the init order of VNET_SYSINIT, when VIMAGE is not =
enabled.

Best regards,
Zhenlei




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6AE3CB33-555F-444B-8263-70FDCA550798>