From owner-p4-projects@FreeBSD.ORG Tue Jul 7 17:37:47 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EFCCF1065673; Tue, 7 Jul 2009 17:37:46 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE32B1065670 for ; Tue, 7 Jul 2009 17:37:46 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 816998FC14 for ; Tue, 7 Jul 2009 17:37:46 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n67HbkHL088223 for ; Tue, 7 Jul 2009 17:37:46 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n67Hbkqt088221 for perforce@freebsd.org; Tue, 7 Jul 2009 17:37:46 GMT (envelope-from trasz@freebsd.org) Date: Tue, 7 Jul 2009 17:37:46 GMT Message-Id: <200907071737.n67Hbkqt088221@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Cc: Subject: PERFORCE change 165761 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jul 2009 17:37:47 -0000 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.