From owner-p4-projects@FreeBSD.ORG Thu Jul 27 08:38:32 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EB0C916A4E5; Thu, 27 Jul 2006 08:38:31 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BCDB916A4DE for ; Thu, 27 Jul 2006 08:38:31 +0000 (UTC) (envelope-from cdjones@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6F65843D46 for ; Thu, 27 Jul 2006 08:38:31 +0000 (GMT) (envelope-from cdjones@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k6R8cVTK044538 for ; Thu, 27 Jul 2006 08:38:31 GMT (envelope-from cdjones@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6R8cV8j044535 for perforce@freebsd.org; Thu, 27 Jul 2006 08:38:31 GMT (envelope-from cdjones@FreeBSD.org) Date: Thu, 27 Jul 2006 08:38:31 GMT Message-Id: <200607270838.k6R8cV8j044535@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cdjones@FreeBSD.org using -f From: Chris Jones To: Perforce Change Reviews Cc: Subject: PERFORCE change 102535 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: Thu, 27 Jul 2006 08:38:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=102535 Change 102535 by cdjones@cdjones-impulse on 2006/07/27 08:37:54 Refactor to pass prison structures to _memory and _memory_limit. Affected files ... .. //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#13 edit .. //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#13 edit Differences ... ==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#13 (text+ko) ==== @@ -126,6 +126,11 @@ if (pr->pr_pager_flags & J_PAGER_TD_DIE) break; + if (prison_memory(pr) > prison_memory_limit(pr)) { + /* the logic from vm_daemon() really needs to go here. + TODO: refactor vm_daemon to optionally act on specific jails. */ + } + /* TODO --- make interval into a sysctl? */ tsleep(pr, 0, "-", hz); } @@ -458,7 +463,7 @@ /* Given credential, return memory usage in bytes. */ int -prison_memory(struct ucred *cred) +prison_memory(struct prison *pr) { struct proc *p; u_int mem_used = 0; @@ -466,7 +471,7 @@ /* TODO: cut this to search only procs in given jail. */ FOREACH_PROC_IN_SYSTEM(p) { if (!jailed(p->p_ucred) || - (cred->cr_prison != p->p_ucred->cr_prison)) { + (pr != p->p_ucred->cr_prison)) { continue; } @@ -479,17 +484,17 @@ /* Convert to bytes, cache (maybe unncessary?). */ mem_used *= PAGE_SIZE; - mtx_lock(&cred->cr_prison->pr_mtx); - cred->cr_prison->pr_mem_usage = mem_used; - mtx_unlock(&cred->cr_prison->pr_mtx); + mtx_lock(&pr->pr_mtx); + pr->pr_mem_usage = mem_used; + mtx_unlock(&pr->pr_mtx); return mem_used; } /* Given credential, return permitted memory usage in bytes. */ int -prison_memory_limit(struct ucred *cred) +prison_memory_limit(struct prison *pr) { - return cred->cr_prison->pr_mem_limit; + return pr->pr_mem_limit; } /* ==== //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#13 (text+ko) ==== @@ -143,8 +143,8 @@ void prison_hold(struct prison *pr); int prison_if(struct ucred *cred, struct sockaddr *sa); int prison_ip(struct ucred *cred, int flag, u_int32_t *ip); -int prison_memory(struct ucred *cred); -int prison_memory_limit(struct ucred *cred); +int prison_memory(struct prison *pr); +int prison_memory_limit(struct prison *pr); void prison_remote_ip(struct ucred *cred, int flags, u_int32_t *ip); #endif /* _KERNEL */