Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Jul 2009 17:37:46 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 165761 for review
Message-ID:  <200907071737.n67Hbkqt088221@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=165761

Change 165761 by trasz@trasz_victim on 2009/07/07 17:36:57

	Revert the file descriptor accounting.  There is no way it could work
	that way, as file descriptor tables might be shared between processes.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#11 edit

Differences ...

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#11 (text+ko) ====

@@ -747,12 +747,6 @@
 	 * out for a race.
 	 */
 	if (flags & DUP_FIXED) {
-		error = hrl_alloc_proc(p, HRL_RESOURCE_FILEDESCRIPTORS, 1);
-		if (error) {
-			FILEDESC_XUNLOCK(fdp);
-			fdrop(fp, td);
-			return (error);
-		}
 		if (new >= fdp->fd_nfiles)
 			fdgrowtable(fdp, new + 1);
 		if (fdp->fd_ofiles[new] == NULL)
@@ -775,7 +769,6 @@
 		if (fdp->fd_ofiles[new] == NULL)
 			fdunused(fdp, new);
 		FILEDESC_XUNLOCK(fdp);
-		hrl_free_proc(p, HRL_RESOURCE_FILEDESCRIPTORS, 1);
 		fdrop(fp, td);
 		return (EBADF);
 	}
@@ -820,7 +813,6 @@
 	 */
 	if (delfp != NULL) {
 		knote_fdclose(td, new);
-		hrl_free_proc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, 1);
 		if (delfp->f_type == DTYPE_MQUEUE)
 			mq_fdclose(td, new, delfp);
 		FILEDESC_XUNLOCK(fdp);
@@ -1119,7 +1111,6 @@
 	 * added, and deleteing a knote for the new fd.
 	 */
 	knote_fdclose(td, fd);
-	hrl_free_proc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, 1);
 	if (fp->f_type == DTYPE_MQUEUE)
 		mq_fdclose(td, fd, fp);
 	FILEDESC_XUNLOCK(fdp);
@@ -1403,16 +1394,16 @@
 {
 	struct proc *p = td->td_proc;
 	struct filedesc *fdp = p->p_fd;
-	int fd = -1, error;
+	int fd = -1, maxfd;
 
 	FILEDESC_XLOCK_ASSERT(fdp);
 
 	if (fdp->fd_freefile > minfd)
 		minfd = fdp->fd_freefile;	   
 
-	error = hrl_alloc_proc(p, HRL_RESOURCE_FILEDESCRIPTORS, 1);
-	if (error)
-		return (EMFILE);
+	PROC_LOCK(p);
+	maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
+	PROC_UNLOCK(p);
 
 	/*
 	 * Search the bitmap for a free descriptor.  If none is found, try
@@ -1422,9 +1413,11 @@
 	 */
 	for (;;) {
 		fd = fd_first_free(fdp, minfd, fdp->fd_nfiles);
+		if (fd >= maxfd)
+			return (EMFILE);
 		if (fd < fdp->fd_nfiles)
 			break;
-		fdgrowtable(fdp, fdp->fd_nfiles * 2);
+		fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd));
 	}
 
 	/*
@@ -1701,8 +1694,6 @@
 	if (fdp == NULL)
 		return;
 
-	hrl_allocated_proc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, 0);
-
 	/* Check for special need to clear POSIX style locks */
 	fdtol = td->td_proc->p_fdtol;
 	if (fdtol != NULL) {
@@ -1879,7 +1870,6 @@
 			struct file *fp;
 
 			knote_fdclose(td, i);
-			hrl_free_proc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, 1);
 			/*
 			 * NULL-out descriptor prior to close to avoid
 			 * a race while close blocks.
@@ -1944,7 +1934,6 @@
 			struct file *fp;
 
 			knote_fdclose(td, i);
-			hrl_free_proc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, 1);
 			/*
 			 * NULL-out descriptor prior to close to avoid
 			 * a race while close blocks.



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