From owner-svn-src-head@FreeBSD.ORG Thu Mar 31 19:22:11 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C8EC1106566C; Thu, 31 Mar 2011 19:22:11 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B59818FC15; Thu, 31 Mar 2011 19:22:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2VJMBBd016500; Thu, 31 Mar 2011 19:22:11 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2VJMBVM016495; Thu, 31 Mar 2011 19:22:11 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201103311922.p2VJMBVM016495@svn.freebsd.org> From: Edward Tomasz Napierala Date: Thu, 31 Mar 2011 19:22:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220222 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2011 19:22:11 -0000 Author: trasz Date: Thu Mar 31 19:22:11 2011 New Revision: 220222 URL: http://svn.freebsd.org/changeset/base/220222 Log: Enable accounting for RACCT_NPROC and RACCT_NTHR. Sponsored by: The FreeBSD Foundation Reviewed by: kib (earlier version) Modified: head/sys/kern/init_main.c head/sys/kern/kern_exit.c head/sys/kern/kern_fork.c head/sys/kern/kern_thr.c Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Thu Mar 31 18:35:44 2011 (r220221) +++ head/sys/kern/init_main.c Thu Mar 31 19:22:11 2011 (r220222) @@ -557,6 +557,9 @@ proc0_init(void *dummy __unused) * Charge root for one process. */ (void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0); + PROC_LOCK(p); + racct_add_force(p, RACCT_NPROC, 1); + PROC_UNLOCK(p); } SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL); Modified: head/sys/kern/kern_exit.c ============================================================================== --- head/sys/kern/kern_exit.c Thu Mar 31 18:35:44 2011 (r220221) +++ head/sys/kern/kern_exit.c Thu Mar 31 19:22:11 2011 (r220222) @@ -177,6 +177,7 @@ exit1(struct thread *td, int rv) } KASSERT(p->p_numthreads == 1, ("exit1: proc %p exiting with %d threads", p, p->p_numthreads)); + racct_sub(p, RACCT_NTHR, 1); /* * Wakeup anyone in procfs' PIOCWAIT. They should have a hold * on our vmspace, so we should block below until they have @@ -745,6 +746,9 @@ proc_reap(struct thread *td, struct proc * Destroy resource accounting information associated with the process. */ racct_proc_exit(p); + PROC_LOCK(p->p_pptr); + racct_sub(p->p_pptr, RACCT_NPROC, 1); + PROC_UNLOCK(p->p_pptr); /* * Free credentials, arguments, and sigacts. @@ -905,7 +909,11 @@ proc_reparent(struct proc *child, struct if (child->p_pptr == parent) return; + PROC_LOCK(parent); + racct_add_force(parent, RACCT_NPROC, 1); + PROC_UNLOCK(parent); PROC_LOCK(child->p_pptr); + racct_sub(child->p_pptr, RACCT_NPROC, 1); sigqueue_take(child->p_ksi); PROC_UNLOCK(child->p_pptr); LIST_REMOVE(child, p_sibling); Modified: head/sys/kern/kern_fork.c ============================================================================== --- head/sys/kern/kern_fork.c Thu Mar 31 18:35:44 2011 (r220221) +++ head/sys/kern/kern_fork.c Thu Mar 31 19:22:11 2011 (r220222) @@ -734,6 +734,12 @@ fork1(struct thread *td, int flags, int return (fork_norfproc(td, flags)); } + PROC_LOCK(p1); + error = racct_add(p1, RACCT_NPROC, 1); + PROC_UNLOCK(p1); + if (error != 0) + return (EAGAIN); + mem_charged = 0; vm2 = NULL; if (pages == 0) @@ -817,6 +823,17 @@ fork1(struct thread *td, int flags, int } /* + * After fork, there is exactly one thread running. + */ + PROC_LOCK(newproc); + error = racct_set(newproc, RACCT_NTHR, 1); + PROC_UNLOCK(newproc); + if (error != 0) { + error = EAGAIN; + goto fail; + } + + /* * Increment the count of procs running with this uid. Don't allow * a nonprivileged user to exceed their current limit. * @@ -857,6 +874,9 @@ fail1: vmspace_free(vm2); uma_zfree(proc_zone, newproc); pause("fork", hz / 2); + PROC_LOCK(p1); + racct_sub(p1, RACCT_NPROC, 1); + PROC_UNLOCK(p1); return (error); } Modified: head/sys/kern/kern_thr.c ============================================================================== --- head/sys/kern/kern_thr.c Thu Mar 31 18:35:44 2011 (r220221) +++ head/sys/kern/kern_thr.c Thu Mar 31 19:22:11 2011 (r220222) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -184,10 +185,18 @@ create_thread(struct thread *td, mcontex } } + PROC_LOCK(td->td_proc); + error = racct_add(p, RACCT_NTHR, 1); + PROC_UNLOCK(td->td_proc); + if (error != 0) + return (EPROCLIM); + /* Initialize our td */ newtd = thread_alloc(0); - if (newtd == NULL) - return (ENOMEM); + if (newtd == NULL) { + error = ENOMEM; + goto fail; + } /* * Try the copyout as soon as we allocate the td so we don't @@ -203,7 +212,8 @@ create_thread(struct thread *td, mcontex (parent_tid != NULL && suword_lwpid(parent_tid, newtd->td_tid))) { thread_free(newtd); - return (EFAULT); + error = EFAULT; + goto fail; } bzero(&newtd->td_startzero, @@ -220,7 +230,7 @@ create_thread(struct thread *td, mcontex if (error != 0) { thread_free(newtd); crfree(td->td_ucred); - return (error); + goto fail; } } else { /* Set up our machine context. */ @@ -233,7 +243,7 @@ create_thread(struct thread *td, mcontex if (error != 0) { thread_free(newtd); crfree(td->td_ucred); - return (error); + goto fail; } } @@ -265,6 +275,12 @@ create_thread(struct thread *td, mcontex thread_unlock(newtd); return (0); + +fail: + PROC_LOCK(p); + racct_sub(p, RACCT_NTHR, 1); + PROC_UNLOCK(p); + return (error); } int @@ -294,7 +310,10 @@ thr_exit(struct thread *td, struct thr_e } rw_wlock(&tidhash_lock); + PROC_LOCK(p); + racct_sub(p, RACCT_NTHR, 1); + /* * Shutting down last thread in the proc. This will actually * call exit() in the trampoline when it returns.