Date: Mon, 21 Aug 2006 08:35:12 GMT From: Chris Jones <cdjones@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 104663 for review Message-ID: <200608210835.k7L8ZC2R043848@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608210835.k7L8ZC2R043848>