From owner-p4-projects@FreeBSD.ORG Mon Jun 29 17:10:50 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4F1E71065672; Mon, 29 Jun 2009 17:10:50 +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 0F15D106566C for ; Mon, 29 Jun 2009 17:10:50 +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 F05008FC1E for ; Mon, 29 Jun 2009 17:10:49 +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 n5THAnC2055613 for ; Mon, 29 Jun 2009 17:10:49 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5THAnf0055611 for perforce@freebsd.org; Mon, 29 Jun 2009 17:10:49 GMT (envelope-from trasz@freebsd.org) Date: Mon, 29 Jun 2009 17:10:49 GMT Message-Id: <200906291710.n5THAnf0055611@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 165412 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: Mon, 29 Jun 2009 17:10:51 -0000 http://perforce.freebsd.org/chv.cgi?CH=165412 Change 165412 by trasz@trasz_victim on 2009/06/29 17:10:19 Kinda sorta working file descriptors accounting. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#8 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#18 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#13 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#3 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_descrip.c#8 (text+ko) ==== @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -279,7 +280,6 @@ td->td_retval[0] = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); PROC_UNLOCK(p); - /* XXX: Use HRL? */ return (0); } @@ -722,7 +722,6 @@ return (flags & DUP_FCNTL ? EINVAL : EBADF); PROC_LOCK(p); maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - /* XXX: Add HRL accounting. */ PROC_UNLOCK(p); if (new >= maxfd) return (flags & DUP_FCNTL ? EINVAL : EMFILE); @@ -748,6 +747,12 @@ * out for a race. */ if (flags & DUP_FIXED) { + error = hrl_alloc_proc(p, HRL_RESOURCE_OPENFILES, 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) @@ -770,6 +775,7 @@ if (fdp->fd_ofiles[new] == NULL) fdunused(fdp, new); FILEDESC_XUNLOCK(fdp); + hrl_free_proc(p, HRL_RESOURCE_OPENFILES, 1); fdrop(fp, td); return (EBADF); } @@ -814,6 +820,7 @@ */ if (delfp != NULL) { knote_fdclose(td, new); + hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1); if (delfp->f_type == DTYPE_MQUEUE) mq_fdclose(td, new, delfp); FILEDESC_XUNLOCK(fdp); @@ -1112,6 +1119,7 @@ * added, and deleteing a knote for the new fd. */ knote_fdclose(td, fd); + hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1); if (fp->f_type == DTYPE_MQUEUE) mq_fdclose(td, fd, fp); FILEDESC_XUNLOCK(fdp); @@ -1395,17 +1403,16 @@ { struct proc *p = td->td_proc; struct filedesc *fdp = p->p_fd; - int fd = -1, maxfd; + int fd = -1, error; FILEDESC_XLOCK_ASSERT(fdp); if (fdp->fd_freefile > minfd) minfd = fdp->fd_freefile; - PROC_LOCK(p); - maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - /* XXX: Add HRL accounting. */ - PROC_UNLOCK(p); + error = hrl_alloc_proc(p, HRL_RESOURCE_OPENFILES, 1); + if (error) + return (EMFILE); /* * Search the bitmap for a free descriptor. If none is found, try @@ -1415,11 +1422,9 @@ */ for (;;) { fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); - if (fd >= maxfd) - return (EMFILE); if (fd < fdp->fd_nfiles) break; - fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); + fdgrowtable(fdp, fdp->fd_nfiles * 2); } /* @@ -1452,7 +1457,6 @@ PROC_LOCK(p); lim = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); - /* XXX: Add HRL accounting. */ PROC_UNLOCK(p); if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0) return (1); @@ -1697,6 +1701,8 @@ if (fdp == NULL) return; + hrl_allocated_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 0); + /* Check for special need to clear POSIX style locks */ fdtol = td->td_proc->p_fdtol; if (fdtol != NULL) { @@ -1873,6 +1879,7 @@ struct file *fp; knote_fdclose(td, i); + hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1); /* * NULL-out descriptor prior to close to avoid * a race while close blocks. @@ -1937,6 +1944,7 @@ struct file *fp; knote_fdclose(td, i); + hrl_free_proc(td->td_proc, HRL_RESOURCE_OPENFILES, 1); /* * NULL-out descriptor prior to close to avoid * a race while close blocks. ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#18 (text+ko) ==== @@ -186,22 +186,17 @@ { int i; + /* + * XXX: Free these two some other way. + */ + hrl_allocated_proc(p, HRL_RESOURCE_FILESIZE, 0); + hrl_allocated_proc(p, HRL_RESOURCE_COREDUMPSIZE, 0); + mtx_lock(&hrl_lock); for (i = 0; i < HRL_RESOURCE_MAX; i++) { - if (p->p_accounting.ha_resources[i] != 0) { -#if 0 + if (p->p_accounting.ha_resources[i] != 0) KASSERT(p->p_accounting.ha_resources == 0, ("dead process still holding resources")); - printf("hrl_proc_exiting: %s = %lld\n", - hrl_resource_name(i), - p->p_accounting.ha_resources[i]); -#else - if (p->p_accounting.ha_resources[i] > 0) - hrl_free_proc(p, i, p->p_accounting.ha_resources[i]); - else - p->p_accounting.ha_resources[i] = 0; - } -#endif } mtx_unlock(&hrl_lock); } @@ -257,8 +252,6 @@ KASSERT(amount > 0, ("hrl_alloc_proc: invalid amount for %s: %lld", hrl_resource_name(resource), amount)); - if (amount <= 0) - panic("bleh."); mtx_lock(&hrl_lock); p->p_accounting.ha_resources[resource] += amount; @@ -290,7 +283,11 @@ mtx_unlock(&hrl_lock); /* - * XXX: When denying, return proper errno - EFSIZ, ENOMEM etc. + * XXX: When denying, return proper errno - EFSIZ, ENOMEM, EMFILE etc. + */ + + /* + * Check maxfilesperproc. */ return (0); @@ -311,10 +308,8 @@ struct ucred *cred; struct prison *pr; - KASSERT(amount > 0, ("hrl_allocated_proc: invalid amount for %s: %lld", + KASSERT(amount >= 0, ("hrl_allocated_proc: invalid amount for %s: %lld", hrl_resource_name(resource), amount)); - if (amount <= 0) - panic("bleh."); mtx_lock(&hrl_lock); diff = amount - p->p_accounting.ha_resources[resource]; @@ -361,8 +356,6 @@ KASSERT(amount > 0, ("hrl_free_proc: invalid amount for %s: %lld", hrl_resource_name(resource), amount)); - if (amount <= 0) - panic("bleh."); mtx_lock(&hrl_lock); p->p_accounting.ha_resources[resource] -= amount; ==== //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#13 (text+ko) ==== ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#3 (text+ko) ==== @@ -67,6 +67,7 @@ #include #include +#include #include #include #include @@ -410,6 +411,11 @@ pmap_activate(td); vmspace_dofree(vm); } + hrl_allocated_proc(p, HRL_RESOURCE_DATASIZE, 0); + hrl_allocated_proc(p, HRL_RESOURCE_STACKSIZE, 0); + hrl_allocated_proc(p, HRL_RESOURCE_MEMORYUSE, 0); + hrl_allocated_proc(p, HRL_RESOURCE_MEMORYLOCKED, 0); + hrl_allocated_proc(p, HRL_RESOURCE_VMEMORYUSE, 0); } /* Acquire reference to vmspace owned by another process. */