Date: Thu, 26 Aug 2010 20:34:48 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 182937 for review Message-ID: <201008262034.o7QKYmvj065786@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008262034.o7QKYmvj065786>