From owner-freebsd-bugs Mon Oct 12 12:33:06 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA21508 for freebsd-bugs-outgoing; Mon, 12 Oct 1998 12:33:06 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from implode.root.com (implode.root.com [198.145.90.17]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA21420 for ; Mon, 12 Oct 1998 12:32:52 -0700 (PDT) (envelope-from root@implode.root.com) Received: from implode.root.com (localhost [127.0.0.1]) by implode.root.com (8.8.5/8.8.5) with ESMTP id MAA02205; Mon, 12 Oct 1998 12:31:09 -0700 (PDT) Message-Id: <199810121931.MAA02205@implode.root.com> To: dag-erli@ifi.uio.no (Dag-Erling C. =?iso-8859-1?Q?Sm=F8rgrav?= ) cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bin/8275: w/top/etc randomly fail with 'Cannot allocate memory' In-reply-to: Your message of "Mon, 12 Oct 1998 11:40:01 PDT." <199810121840.LAA26956@freefall.freebsd.org> From: David Greenman Reply-To: dg@root.com Date: Mon, 12 Oct 1998 12:31:08 -0700 Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > If my reasoning is correct, the following (untested) patch should > solve this: > > Index: kvm_proc.c > =================================================================== > RCS file: /home/ncvs/src/lib/libkvm/kvm_proc.c,v > retrieving revision 1.21 > diff -u -r1.21 kvm_proc.c > --- kvm_proc.c 1998/09/16 04:17:46 1.21 > +++ kvm_proc.c 1998/10/12 18:33:58 > @@ -302,10 +302,15 @@ > _kvm_syserr(kd, kd->program, "kvm_getprocs"); > return (0); > } > - kd->procbase = (struct kinfo_proc *)_kvm_malloc(kd, size); > - if (kd->procbase == 0) > - return (0); > - st = sysctl(mib, op == KERN_PROC_ALL ? 3 : 4, kd->procbase, &size, NULL, 0); > + kd->procbase = 0; > + do { > + kd->procbase = (struct kinfo_proc *)_kvm_realloc(kd, > + size); > + if (kd->procbase == 0) > + return (0); > + st = sysctl(mib, op == KERN_PROC_ALL ? 3 : 4, > + kd->procbase, &size, NULL, 0); > + } while (st == -1 && errno == ENOMEM); It should pad "size" with a few processes worth (perhaps increase it by 10%...size += size / 10). -DG David Greenman Co-founder/Principal Architect, The FreeBSD Project To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message