Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Oct 2005 19:00:18 +0400
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        Vladimir Sharun <sharun@ukr.net>
Cc:        freebsd-stable@FreeBSD.org, csjp@FreeBSD.org, Pete French <petefrench@ticketswitch.com>, Kris Kennaway <kris@obsecurity.org>
Subject:   Re: kmem_malloc(4096): kmem_map too small: 536870912 total allocated
Message-ID:  <20051025150018.GO41520@cell.sick.ru>
In-Reply-To: <20051023074342.GA97095@dun.ukr.net>
References:  <20051023074342.GA97095@dun.ukr.net>

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

--oj4kGyHlBMXGt3Le
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline

  Vladimir,

  please confirm that the attached patch fix your problem. The patch is relative
to src/sys tree.

  Kris, Christian, please review it. Thanks.

-- 
Totus tuus, Glebius.
GLEBIUS-RIPN GLEB-RIPE

--oj4kGyHlBMXGt3Le
Content-Type: text/plain; charset=koi8-r
Content-Disposition: attachment; filename="lockf.leak.patch"

Index: nfsclient/nfs_lock.c
===================================================================
RCS file: /home/ncvs/src/sys/nfsclient/nfs_lock.c,v
retrieving revision 1.40
diff -u -r1.40 nfs_lock.c
--- nfsclient/nfs_lock.c	6 Dec 2004 08:31:32 -0000	1.40
+++ nfsclient/nfs_lock.c	25 Oct 2005 14:51:11 -0000
@@ -62,9 +62,13 @@
 #include <nfsclient/nfs_lock.h>
 #include <nfsclient/nlminfo.h>
 
+extern void (*nlminfo_release_p)(struct proc *p);
+
 MALLOC_DEFINE(M_NFSLOCK, "NFS lock", "NFS lock request");
+MALLOC_DEFINE(M_NLMINFO, "nlminfo", "NFS lock process structure");
 
 static int nfslockdans(struct thread *td, struct lockd_ans *ansp);
+static void nlminfo_release(struct proc *p);
 /*
  * --------------------------------------------------------------------
  * A miniature device driver which the userland uses to talk to us.
@@ -194,6 +198,7 @@
 			printf("nfslock: pseudo-device\n");
 		mtx_init(&nfslock_mtx, "nfslock", NULL, MTX_DEF);
 		TAILQ_INIT(&nfslock_list);
+		nlminfo_release_p = nlminfo_release;
 		nfslock_dev = make_dev(&nfslock_cdevsw, 0,
 		    UID_ROOT, GID_KMEM, 0600, _PATH_NFSLCKDEV);
 		return (0);
@@ -259,7 +264,7 @@
 	 */
 	if (p->p_nlminfo == NULL) {
 		MALLOC(p->p_nlminfo, struct nlminfo *,
-			sizeof(struct nlminfo), M_LOCKF, M_WAITOK | M_ZERO);
+			sizeof(struct nlminfo), M_NLMINFO, M_WAITOK | M_ZERO);
 		p->p_nlminfo->pid_start = p->p_stats->p_start;
 		timevaladd(&p->p_nlminfo->pid_start, &boottime);
 	}
@@ -381,3 +386,12 @@
 	return (0);
 }
 
+/*
+ * Free nlminfo attached to process.
+ */
+void        
+nlminfo_release(struct proc *p)
+{  
+        free(p->p_nlminfo, M_NLMINFO);
+        p->p_nlminfo = NULL;
+}
Index: nfsclient/nlminfo.h
===================================================================
RCS file: /home/ncvs/src/sys/nfsclient/nlminfo.h,v
retrieving revision 1.2
diff -u -r1.2 nlminfo.h
--- nfsclient/nlminfo.h	18 Sep 2001 23:31:53 -0000	1.2
+++ nfsclient/nlminfo.h	25 Oct 2005 14:40:30 -0000
@@ -40,5 +40,3 @@
 	int		getlk_pid;
         struct  timeval pid_start;      /* process starting time */
 };
-
-extern void nlminfo_release(struct proc *p);
Index: kern/kern_exit.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.268
diff -u -r1.268 kern_exit.c
--- kern/kern_exit.c	23 Oct 2005 12:19:08 -0000	1.268
+++ kern/kern_exit.c	25 Oct 2005 14:45:35 -0000
@@ -82,6 +82,9 @@
 /* Required to be non-static for SysVR4 emulator */
 MALLOC_DEFINE(M_ZOMBIE, "zombie", "zombie proc status");
 
+/* Hook for NFS teardown procedure. */
+void (*nlminfo_release_p)(struct proc *p);
+
 /*
  * exit --
  *	Death of process.
@@ -234,6 +237,12 @@
 	funsetownlst(&p->p_sigiolst);
 
 	/*
+	 * If this process has an nlminfo data area (for lockd), release it
+	 */
+	if (nlminfo_release_p != NULL && p->p_nlminfo != NULL)
+		(*nlminfo_release_p)(p);
+
+	/*
 	 * Close open files and release open-file table.
 	 * This may block!
 	 */
Index: sys/lockf.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/lockf.h,v
retrieving revision 1.18
diff -u -r1.18 lockf.h
--- sys/lockf.h	25 Jan 2005 10:15:25 -0000	1.18
+++ sys/lockf.h	25 Oct 2005 14:51:28 -0000
@@ -40,10 +40,6 @@
 
 struct vop_advlock_args;
 
-#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_LOCKF);
-#endif
-
 /*
  * The lockf structure is a kernel structure which contains the information
  * associated with a byte range lock.  The lockf structures are linked into

--oj4kGyHlBMXGt3Le--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051025150018.GO41520>