From owner-freebsd-hackers@FreeBSD.ORG Sun May 11 21:48:44 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EB0BB106564A; Sun, 11 May 2008 21:48:43 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com (relay02.kiev.sovam.com [62.64.120.197]) by mx1.freebsd.org (Postfix) with ESMTP id 7BD658FC1C; Sun, 11 May 2008 21:48:43 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from [212.82.216.226] (helo=skuns.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1JvJPN-000ABO-Qo; Mon, 12 May 2008 00:48:42 +0300 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by skuns.kiev.zoral.com.ua (8.14.2/8.14.2) with ESMTP id m4BLmawl083445 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 12 May 2008 00:48:36 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2) with ESMTP id m4BLmXo3036722; Mon, 12 May 2008 00:48:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2/Submit) id m4BLmXEr036721; Mon, 12 May 2008 00:48:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 12 May 2008 00:48:33 +0300 From: Kostik Belousov To: Andriy Gapon Message-ID: <20080511214833.GB18958@deviant.kiev.zoral.com.ua> References: <480E4269.2090604@icyb.net.ua> <480FBAB9.1000904@icyb.net.ua> <48103F36.6060707@icyb.net.ua> <200804240811.26183.jhb@freebsd.org> <4810FD1E.70602@icyb.net.ua> <20080425095009.GD18958@deviant.kiev.zoral.com.ua> <4811E6BC.4060306@icyb.net.ua> <20080425143646.GF18958@deviant.kiev.zoral.com.ua> <48275C0C.2040601@icyb.net.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="GURrebd5m7w1Nnt/" Content-Disposition: inline In-Reply-To: <48275C0C.2040601@icyb.net.ua> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.91.2, clamav-milter version 0.91.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.4 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on skuns.kiev.zoral.com.ua X-Scanner-Signature: 88d0fd334128e7d5bb9b9ebe4fef9048 X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Info: Profiles 2798 [May 08 2008] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {received from trusted relay: not dialup} X-SpamTest-Method: none X-SpamTest-Method: Local Lists X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Cc: freebsd-hackers@freebsd.org Subject: Re: devctl (alike?) for devfs X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 May 2008 21:48:44 -0000 --GURrebd5m7w1Nnt/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 11, 2008 at 11:50:20PM +0300, Andriy Gapon wrote: >=20 > Kostik, John, Warner, >=20 > thank you for your guidance and suggestions. > I am currently testing the patch attached and I am using a kernel with=20 > WITNESS and INVARIANTS enabled. > Scope of my testing is plugging/unplugging of UMASS devices. > I get CREATE notifications all right. > I do not get any panics/complaints from the kernel, good. > Unfortunately I do not get any DESTROY notifications either. >=20 > Could you please look through the patch? Is there any control flow path= =20 > that I missed or something even more obvious? > I hope that we do not have any cdev leaks. >=20 > I am testing the patch with RELENG_7 as of May 6. No, we do not have a leak, but we have somewhat non-obvious behaviour. The cdev structure is freed only after the last reference to cdev is gone. Typical holder of the reference is the devfs vnode. In the normal usage, the vnode is present until both the device is destroyed _and_ devfs_populate_loop() run is performed. This function actually reclaim the vnodes for destroyed devices, that causes last reference to cdev to be dropped and memory freed. The populate loop is called syncronously from the upper levels. The easiest method to trigger it is to do ls /dev, since it is called from the devfs_lookupx(). >=20 > --=20 > Andriy Gapon > diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c > index 1db25f8..0245253 100644 > --- a/sys/kern/kern_conf.c > +++ b/sys/kern/kern_conf.c > @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > #include > #include > @@ -99,6 +100,9 @@ dev_unlock_and_free(void) > mtx_unlock(&devmtx); > =20 > while ((cdp =3D TAILQ_FIRST(&cdp_free)) !=3D NULL) { > + if (!cold) > + devctl_notify("DEVFS", cdp->cdp_c.si_name, "DESTROY", NULL); > + > TAILQ_REMOVE(&cdp_free, cdp, cdp_list); > devfs_free(&cdp->cdp_c); > } > @@ -172,8 +176,12 @@ dev_rel(struct cdev *dev) > flag =3D 1; > } > dev_unlock(); > - if (flag) > + if (flag) { > + if (!cold) > + devctl_notify("DEVFS", dev->si_name, "DESTROY", NULL); > + > devfs_free(dev); > + } > } > =20 > struct cdevsw * > @@ -706,6 +714,10 @@ make_dev_credv(int flags, struct cdevsw *devsw, int = minornr, > devfs_create(dev); > clean_unrhdrl(devfs_inos); > dev_unlock_and_free(); > + > + if (!cold) > + devctl_notify("DEVFS", dev->si_name, "CREATE", NULL); > + > return (dev); > } > =20 > @@ -794,6 +806,10 @@ make_dev_alias(struct cdev *pdev, const char *fmt, .= ..) > clean_unrhdrl(devfs_inos); > dev_unlock(); > dev_depends(pdev, dev); > + > + if (!cold) > + devctl_notify("DEVFS", dev->si_name, "CREATE", NULL); > + > return (dev); > } > =20 --GURrebd5m7w1Nnt/ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkgnabAACgkQC3+MBN1Mb4ihSgCfRQjZSXKDLinsfMuGXTEx+kbZ JcgAoN3qatcTfVTT3ABTzjXn3TUm9Ijs =FBo+ -----END PGP SIGNATURE----- --GURrebd5m7w1Nnt/--