From owner-p4-projects@FreeBSD.ORG Thu Aug 26 20:34:49 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 69AA51065694; Thu, 26 Aug 2010 20:34:49 +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 2C652106566B for ; Thu, 26 Aug 2010 20:34:49 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id F399B8FC12 for ; Thu, 26 Aug 2010 20:34:48 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id o7QKYmJv065789 for ; Thu, 26 Aug 2010 20:34:48 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id o7QKYmvj065786 for perforce@freebsd.org; Thu, 26 Aug 2010 20:34:48 GMT (envelope-from trasz@freebsd.org) Date: Thu, 26 Aug 2010 20:34:48 GMT Message-Id: <201008262034.o7QKYmvj065786@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 182937 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2010 20:34:49 -0000 http://p4web.freebsd.org/@@182937?ac=10 Change 182937 by trasz@trasz_victim on 2010/08/26 20:33:44 File descriptor accounting. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#16 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#16 (text+ko) ==== @@ -274,11 +274,19 @@ getdtablesize(struct thread *td, struct getdtablesize_args *uap) { struct proc *p = td->td_proc; +#ifdef CONTAINERS + uint64_t lim; +#endif PROC_LOCK(p); td->td_retval[0] = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); PROC_UNLOCK(p); +#ifdef CONTAINERS + lim = rusage_get_limit(td->td_proc, RUSAGE_NOFILE); + if (lim < td->td_retval[0]) + td->td_retval[0] = lim; +#endif return (0); } @@ -791,8 +799,25 @@ * out for a race. */ if (flags & DUP_FIXED) { - if (new >= fdp->fd_nfiles) + if (new >= fdp->fd_nfiles) { +#ifdef CONTAINERS + /* + * The resource limits are here instead of e.g. fdalloc(), + * because the file descriptor table may be shared between + * processes, so we can't really use rusage_add()/rusage_sub(). + * Instead of e.g. counting the number of actually allocated + * descriptors, just put the limit on the size of the file + * descriptor table. Entries are small, and we'll need a limit + * for vnodes and sockets anyway. + */ + if (rusage_set(p, RUSAGE_NOFILE, new + 1)) { + FILEDESC_XUNLOCK(fdp); + fdrop(fp, td); + return (EMFILE); + } +#endif fdgrowtable(fdp, new + 1); + } if (fdp->fd_ofiles[new] == NULL) fdused(fdp, new); } else { @@ -1461,6 +1486,10 @@ return (EMFILE); if (fd < fdp->fd_nfiles) break; +#ifdef CONTAINERS + if (rusage_set(p, RUSAGE_NOFILE, min(fdp->fd_nfiles * 2, maxfd))) + return (EMFILE); +#endif fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); } @@ -1492,6 +1521,11 @@ FILEDESC_LOCK_ASSERT(fdp); + /* + * XXX: This is only called from uipc_usrreq.c:unp_externalize(); + * call rusage_add() from there instead of dealing with containers + * here. + */ PROC_LOCK(p); lim = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); PROC_UNLOCK(p); @@ -1738,6 +1772,9 @@ if (fdp == NULL) return; +#ifdef CONTAINERS + rusage_set(td->td_proc, RUSAGE_NOFILE, 0); +#endif /* Check for special need to clear POSIX style locks */ fdtol = td->td_proc->p_fdtol; if (fdtol != NULL) {