From owner-freebsd-questions@FreeBSD.ORG Wed Apr 30 02:45:05 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B43131065670 for ; Wed, 30 Apr 2008 02:45:05 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from mx.utwente.nl (unknown [IPv6:2001:610:1908:1000:204:23ff:feba:6042]) by mx1.freebsd.org (Postfix) with ESMTP id 377868FC24 for ; Wed, 30 Apr 2008 02:45:05 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from lux.student.utwente.nl (lux.student.utwente.nl [130.89.170.81]) by mx.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id m3U2isGI017355; Wed, 30 Apr 2008 04:44:55 +0200 From: Pieter de Goeje To: freebsd-questions@freebsd.org Date: Wed, 30 Apr 2008 04:44:54 +0200 User-Agent: KMail/1.9.7 References: <919383240804291737k513360bcje6c4c85dc4621903@mail.gmail.com> In-Reply-To: <919383240804291737k513360bcje6c4c85dc4621903@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804300444.54527.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact servicedesk@icts.utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Cc: Edward Ruggeri Subject: Re: Dynamic Memory Allocation Limit? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Apr 2008 02:45:05 -0000 On Wednesday 30 April 2008, Edward Ruggeri wrote: > I have recently been writing an implementation of the sieve of > Eratosthenes in C. To find all primes less than N, I dynamically > create an array of chars (relatively small datatype) of length N+1 (I > know I don't need to represent evens). When I wrote my version a long time ago, I made it possible to split the set of possible prime numbers in blocks of managable sizes to avoid this problem :) this ofcourse made the algorithm somewhat slower. (Also I stored the state of 8 odd numbers in one byte, reducing memory usage significantly) > > Everything works great up until around 600 million, at which case > memory allocation fails. At this point, I am asking for 600M chars, > which is about 572MB (I might be failing to take account of offset?). > > My system has about 2GB of memory. Top says: Mem: 159M Active, 1113M > Inact, 185M Wired, 56M Cache, 112M Buf, 481M Free. > > >From the man page, I am not completely clear what these values mean. > > However, I have read elsewhere that memory labeled as inactive should > be available for the heap Yes, it is. > > Is there a limit to how much memory may be allocated to a process? > Any other reasons someone might think of? Yes, there is the datasize limit. limits(1) will show you how much memory each process can allocate. To increase "datasize", set the tunable kern.maxdsiz (more info in tuning(7)). I guess the system is running FreeBSD/i386, because I think the default limit is about ~500MB on FreeBSD/i386. Note that it isn't possible to allow processes to use more than ~3GB of memory on FreeBSD/i386 because of that platform's constraints. More is possible on for example FreeBSD/amd64. > > I am using FreeBSD 6.3-prerelease, with SMP for a Athlon X2 4200+ (if > it makes a difference). Sorry if this is a RTFM question ... > > Sincerely, > > -- Ned Ruggeri Good luck, Pieter de Goeje