From owner-p4-projects@FreeBSD.ORG Mon Aug 21 08:35:13 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 C055A16A4E5; Mon, 21 Aug 2006 08:35:13 +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 7A13B16A4E0 for ; Mon, 21 Aug 2006 08:35:13 +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 1D58A43D53 for ; Mon, 21 Aug 2006 08:35:13 +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 k7L8ZCeS043851 for ; Mon, 21 Aug 2006 08:35:12 GMT (envelope-from cdjones@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k7L8ZC2R043848 for perforce@freebsd.org; Mon, 21 Aug 2006 08:35:12 GMT (envelope-from cdjones@FreeBSD.org) Date: Mon, 21 Aug 2006 08:35:12 GMT Message-Id: <200608210835.k7L8ZC2R043848@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 104663 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, 21 Aug 2006 08:35:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=104663 Change 104663 by cdjones@cdjones-impulse on 2006/08/21 08:35:04 Mission accomplished: pager thread now stops when it's appropriate. Affected files ... .. //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#24 edit .. //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#20 edit Differences ... ==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#24 (text+ko) ==== @@ -156,17 +156,21 @@ break; if (jail_limit_memory && pr->pr_mem_limit) { - /* TODO: consider whether it might be better to start + /* + * TODO: consider whether it might be better to start * pushing back when we approach the limit, rather than * when we hit it. + * */ - limit = (long) prison_memory_limit(pr); - usage = (long) prison_memory(pr); + limit = prison_memory_limit(pr); + usage = prison_memory(pr); - /* The logic from vm_daemon() really needs to go here. - * Problem: we want to push things below their rlimits. + /* + * The logic from vm_daemon() really needs to go here. + * Problem: we want to push things below their rlimits, + * and vm_daemon doesn't do that. It'd be better to + * refactor vm_daemon to fit, but this'll do for now. * - * TODO: refactor vm_daemon to optionally act on specific jails? */ printf("jpager/%d: memory %ld / %ld bytes\n", @@ -213,20 +217,23 @@ */ /* TODO: this arbitrarily reduces each process's space by - * 5% (until it's completely swapped out) while + * 6.25% (until it's completely swapped out) while * we're under memory pressure. A better way would be * to either hit large processes first, or to hit the * least-active processes first, or go proportionally, * or .... */ - newsize = cursize = (long) vmspace_resident_count(p->p_vmspace); - newsize -= newsize / 20; + newsize = cursize = vmspace_resident_count(p->p_vmspace); + newsize -= newsize / 16; if (cursize < 0) newsize = 0; PROC_UNLOCK(p); printf("jpager/%d: squeezing process %d from %ld to %ld\n", pr_id, p->p_pid, cursize, newsize); vm_pageout_map_deactivate_pages(&p->p_vmspace->vm_map, newsize); + printf("jpager/%d: squeezed process %d from %ld to %ld (wanted %ld)\n", + pr_id, p->p_pid, cursize, + vmspace_resident_count(p->p_vmspace), newsize); } /* end LIST_FOREACH procs */ sx_sunlock(&allproc_lock); } @@ -552,32 +559,31 @@ } /* Given credential, return memory usage in bytes. */ -vm_pindex_t +long prison_memory(struct prison *pr) { struct proc *p; - u_int mem_used = 0; + long mem_used = 0; - /* TODO: cut this to search only procs in given jail. */ + /* + * TODO: this is a really bad way of doing the + * search, as we end up going across all processes + * for each jail. It'd be more efficient to just do + * this once in a period and update the relevant jail. + * + */ FOREACH_PROC_IN_SYSTEM(p) { if (!jailed(p->p_ucred) || - (pr != p->p_ucred->cr_prison)) { + (pr != p->p_ucred->cr_prison)) continue; - } - - /* Get memory usage (see vm/vm_map.h). */ - /* TODO maybe use vm_swrss? */ - mem_used += (p->p_vmspace)->vm_tsize; /* text size (pages) */ - mem_used += (p->p_vmspace)->vm_dsize; /* data size (pages) */ - mem_used += (p->p_vmspace)->vm_ssize; /* stack size (pages) */ + mem_used += vmspace_resident_count(p->p_vmspace); } - - mem_used *= PAGE_SIZE; + mem_used *= PAGE_SIZE; return mem_used; } /* Given credential, return permitted memory usage in bytes. */ -vm_pindex_t +long prison_memory_limit(struct prison *pr) { vm_pindex_t memlimit; ==== //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#20 (text+ko) ==== @@ -134,8 +134,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); -vm_pindex_t prison_memory(struct prison *pr); -vm_pindex_t prison_memory_limit(struct prison *pr); +long prison_memory(struct prison *pr); +long prison_memory_limit(struct prison *pr); void prison_remote_ip(struct ucred *cred, int flags, u_int32_t *ip); #endif /* _KERNEL */