Dynamic Memory Allocation Limit?
Pieter de Goeje
pieter at degoeje.nl
Wed Apr 30 02:45:05 UTC 2008
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
More information about the freebsd-questions
mailing list