From antoine@mna75-2-82-67-196-50.fbx.proxad.net  Sat May 28 13:47:03 2005
Return-Path: <antoine@mna75-2-82-67-196-50.fbx.proxad.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 6B2CF16A43B
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 28 May 2005 13:47:03 +0000 (GMT)
	(envelope-from antoine@mna75-2-82-67-196-50.fbx.proxad.net)
Received: from barton.dreadbsd.org (madhouse.dreadbsd.org [82.67.196.50])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E371A43D1D
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 28 May 2005 13:47:00 +0000 (GMT)
	(envelope-from antoine@mna75-2-82-67-196-50.fbx.proxad.net)
Received: from barton.dreadbsd.org (localhost [127.0.0.1])
	by barton.dreadbsd.org (8.13.3/8.13.1) with ESMTP id j4SDkuLU004934
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 28 May 2005 15:46:58 +0200 (CEST)
	(envelope-from antoine@mna75-2-82-67-196-50.fbx.proxad.net)
Received: (from antoine@localhost)
	by barton.dreadbsd.org (8.13.3/8.13.1/Submit) id j4SDkt5F004933;
	Sat, 28 May 2005 15:46:55 +0200 (CEST)
	(envelope-from antoine)
Message-Id: <200505281346.j4SDkt5F004933@barton.dreadbsd.org>
Date: Sat, 28 May 2005 15:46:55 +0200 (CEST)
From: Antoine Brodin <antoine.brodin@laposte.net>
Reply-To: Antoine Brodin <antoine.brodin@laposte.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Devices with SI_CHEAPCLONE flag don't seem to go away when they're no longer used in -current
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         81588
>Category:       kern
>Synopsis:       [kernel] [patch] Devices with SI_CHEAPCLONE flag don't seem to go away when they're no longer used in -current
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 28 13:50:01 GMT 2005
>Closed-Date:    
>Last-Modified:  Sat Sep 24 17:44:27 UTC 2011
>Originator:     Antoine Brodin
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
none
>Environment:
System: FreeBSD barton.dreadbsd.org 6.0-CURRENT FreeBSD 6.0-CURRENT #7: Sat May 28 14:52:05 CEST 2005 root@barton.dreadbsd.org:/usr/obj/usr/src/sys/BARTON i386
>Description:
On freebsd 5, when you use a lot of bpf(4), and you stop using them, and
then you run something like /etc/periodic/weekly/310.locate , the bpf(4)
go away.
On -current, this doesn't seem to work anymore.
>How-To-Repeat:
Use something like this:
#!/usr/bin/env perl
my $i;
my $s;
for ($i = 0; $i < 1000; $i++) {
	$s = "/dev/bpf".$i;
	system "ls $s";
}

and then run /etc/periodic/weekly/310.locate , the devices don't go away.
>Fix:
I don't have a fix, but revision 1.172 of kern/kern_conf.c looks suspect,
especially the lines:
%%%
+	if (dev->si_usecount == 0 &&
+	    (dev->si_flags & SI_CHEAPCLONE) && (dev->si_flags & SI_NAMED))
 	if (dev->si_devsw == NULL && dev->si_refcount == 0) {
 		LIST_REMOVE(dev, si_list);
 		flag = 1;
%%%
The indentation suggests that a line is missing...
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Sun May 29 15:29:57 GMT 2005 
Responsible-Changed-Why:  
This sounds like it's in phk's areas of interest. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=81588 

From: Antoine Brodin <antoine.brodin@laposte.net>
To: bug-followup@FreeBSD.org, antoine.brodin@laposte.net
Cc:  
Subject: Re: kern/81588: Devices with SI_CHEAPCLONE flag don't seem to go
 away when they're no longer used in -current
Date: Sat, 25 Jun 2005 16:06:44 +0200

 This is a multi-part message in MIME format.
 
 --Multipart=_Sat__25_Jun_2005_16_06_44_+0200_2gGkAVApWCADZa4H
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 
 The attached patch seems to do the trick.
 However I don't unterstand all the code so it probably needs a good
 review.
 
 --Multipart=_Sat__25_Jun_2005_16_06_44_+0200_2gGkAVApWCADZa4H
 Content-Type: text/plain;
  name="patch.txt"
 Content-Disposition: attachment;
  filename="patch.txt"
 Content-Transfer-Encoding: 7bit
 
 Index: kern/kern_conf.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/kern/kern_conf.c,v
 retrieving revision 1.186
 diff -u -p -r1.186 kern_conf.c
 --- kern/kern_conf.c	31 Mar 2005 10:29:57 -0000	1.186
 +++ kern/kern_conf.c	25 Jun 2005 12:08:26 -0000
 @@ -97,7 +97,8 @@ dev_rel(struct cdev *dev)
  	    ("dev_rel(%s) gave negative count", devtoname(dev)));
  	if (dev->si_usecount == 0 &&
  	    (dev->si_flags & SI_CHEAPCLONE) && (dev->si_flags & SI_NAMED))
 -	if (dev->si_devsw == NULL && dev->si_refcount == 0) {
 +		destroy_devl(dev);
 +	else if (dev->si_devsw == NULL && dev->si_refcount == 0) {
  		LIST_REMOVE(dev, si_list);
  		flag = 1;
  	}
 Index: fs/devfs/devfs_vnops.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/fs/devfs/devfs_vnops.c,v
 retrieving revision 1.114
 diff -u -p -r1.114 devfs_vnops.c
 --- fs/devfs/devfs_vnops.c	31 May 2005 14:50:49 -0000	1.114
 +++ fs/devfs/devfs_vnops.c	25 Jun 2005 13:48:02 -0000
 @@ -712,7 +712,9 @@ devfs_lookupx(ap)
  	devfs_populate(dmp);
  
  	dde = devfs_itode(dmp, cdev->si_inode);
 -	dev_rel(cdev);
 +	dev_lock();
 +	cdev->si_refcount--;
 +	dev_unlock();
  
  	if (dde == NULL || *dde == NULL || *dde == DE_DELETED)
  		goto notfound;
 
 --Multipart=_Sat__25_Jun_2005_16_06_44_+0200_2gGkAVApWCADZa4H--
Responsible-Changed-From-To: phk->freebsd-bugs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sat Sep 24 17:44:27 UTC 2011 
Responsible-Changed-Why:  
return to the pool (approved by phk) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81588 
>Unformatted:
