From owner-freebsd-stable Tue Aug 21 13:51:38 2001 Delivered-To: freebsd-stable@freebsd.org Received: from earth.backplane.com (earth-nat-cw.backplane.com [208.161.114.67]) by hub.freebsd.org (Postfix) with ESMTP id E088E37B403 for ; Tue, 21 Aug 2001 13:51:31 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.11.4/8.11.2) id f7LKpTK66953; Tue, 21 Aug 2001 13:51:29 -0700 (PDT) (envelope-from dillon) Date: Tue, 21 Aug 2001 13:51:29 -0700 (PDT) From: Matt Dillon Message-Id: <200108212051.f7LKpTK66953@earth.backplane.com> To: Steve Shorter Cc: freebsd-stable@FreeBSD.ORG Subject: Re: VM exhaustion and kernel hangs References: <20010821115724.A2562@nomad.lets.net> <200108211820.f7LIKZf65278@earth.backplane.com> <20010821144406.A2733@nomad.lets.net> <200108211907.f7LJ7DK65902@earth.backplane.com> <20010821162641.B2788@nomad.lets.net> Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG : :On Tue, Aug 21, 2001 at 12:07:13PM -0700, Matt Dillon wrote: :> :> Also, just to throw this out... swap over NFS is not actually all that :> bad a thing to do, especially with FreeBSD-4.x and modern switched :> 100BaseTX ethernet links. : : That is a consideration. : : Thanks for your help in this matter. : :I am still interested in making a patch based on diffs from :4.3-STABLE and 4.3-SECURITY. Would this be easy to do or have there been a :lot of kernel changes that affect this issue. Is it good enough to look :at killproc() and vm_pagout.c or is there more to it than that. : : thanx - steve Sure. If you are comfortable building from a mod'd source tree, here is the relevant log and diff set. It should be very easy to patch in. -Matt dillon 2001/06/13 00:26:59 PDT Modified files: (Branch: RELENG_4) sys/vm vm_map.c vm_map.h vm_pageout.c Log: MFC the two out-of-swap fixes (kill the correct process and start blasting away at processes a little earlier, before the machine begins to lockup) Revision Changes Path 1.187.2.9 +36 -1 src/sys/vm/vm_map.c 1.54.2.2 +2 -1 src/sys/vm/vm_map.h 1.151.2.8 +9 -4 src/sys/vm/vm_pageout.c Index: vm_map.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_map.c,v retrieving revision 1.187.2.8 retrieving revision 1.187.2.9 diff -u -r1.187.2.8 -r1.187.2.9 --- vm_map.c 2001/03/14 07:05:05 1.187.2.8 +++ vm_map.c 2001/06/13 07:26:58 1.187.2.9 @@ -61,7 +61,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $FreeBSD: src/sys/vm/vm_map.c,v 1.187.2.8 2001/03/14 07:05:05 dillon Exp $ + * $FreeBSD: src/sys/vm/vm_map.c,v 1.187.2.9 2001/06/13 07:26:58 dillon Exp $ */ /* @@ -218,6 +218,41 @@ zfree(vmspace_zone, vm); } } + +/* + * vmspace_swap_count() - count the approximate swap useage in pages for a + * vmspace. + * + * Swap useage is determined by taking the proportional swap used by + * VM objects backing the VM map. To make up for fractional losses, + * if the VM object has any swap use at all the associated map entries + * count for at least 1 swap page. + */ +int +vmspace_swap_count(struct vmspace *vmspace) +{ + vm_map_t map = &vmspace->vm_map; + vm_map_entry_t cur; + int count = 0; + + for (cur = map->header.next; cur != &map->header; cur = cur->next) { + vm_object_t object; + + if ((cur->eflags & MAP_ENTRY_IS_SUB_MAP) == 0 && + (object = cur->object.vm_object) != NULL && + object->type == OBJT_SWAP + ) { + int n = (cur->end - cur->start) / PAGE_SIZE; + + if (object->un_pager.swp.swp_bcount) { + count += object->un_pager.swp.swp_bcount * + SWAP_META_PAGES * n / object->size + 1; + } + } + } + return(count); +} + /* * vm_map_create: Index: vm_map.h =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_map.h,v retrieving revision 1.54.2.1 retrieving revision 1.54.2.2 diff -u -r1.54.2.1 -r1.54.2.2 --- vm_map.h 2001/03/14 07:05:06 1.54.2.1 +++ vm_map.h 2001/06/13 07:26:58 1.54.2.2 @@ -61,7 +61,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $FreeBSD: src/sys/vm/vm_map.h,v 1.54.2.1 2001/03/14 07:05:06 dillon Exp $ + * $FreeBSD: src/sys/vm/vm_map.h,v 1.54.2.2 2001/06/13 07:26:58 dillon Exp $ */ /* @@ -375,6 +375,7 @@ void vm_freeze_copyopts __P((vm_object_t, vm_pindex_t, vm_pindex_t)); int vm_map_stack __P((vm_map_t, vm_offset_t, vm_size_t, vm_prot_t, vm_prot_t, int)); int vm_map_growstack __P((struct proc *p, vm_offset_t addr)); +int vmspace_swap_count __P((struct vmspace *vmspace)); #endif #endif /* _VM_MAP_ */ Index: vm_pageout.c =================================================================== RCS file: /home/ncvs/src/sys/vm/vm_pageout.c,v retrieving revision 1.151.2.7 retrieving revision 1.151.2.8 diff -u -r1.151.2.7 -r1.151.2.8 --- vm_pageout.c 2000/12/30 01:51:12 1.151.2.7 +++ vm_pageout.c 2001/06/13 07:26:58 1.151.2.8 @@ -65,7 +65,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $FreeBSD: src/sys/vm/vm_pageout.c,v 1.151.2.7 2000/12/30 01:51:12 dillon Exp $ + * $FreeBSD: src/sys/vm/vm_pageout.c,v 1.151.2.8 2001/06/13 07:26:58 dillon Exp $ */ /* @@ -1094,10 +1094,14 @@ } /* - * make sure that we have swap space -- if we are low on memory and - * swap -- then kill the biggest process. + * If we are out of swap and were not able to reach our paging + * target, kill the largest process. */ + if ((vm_swap_size < 64 && vm_page_count_min()) || + (swap_pager_full && vm_paging_target() > 0)) { +#if 0 if ((vm_swap_size < 64 || swap_pager_full) && vm_page_count_min()) { +#endif bigproc = NULL; bigsize = 0; for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) { @@ -1119,7 +1123,8 @@ /* * get the process size */ - size = vmspace_resident_count(p->p_vmspace); + size = vmspace_resident_count(p->p_vmspace) + + vmspace_swap_count(p->p_vmspace); /* * if the this process is bigger than the biggest one * remember it. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message