Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Apr 2008 13:22:57 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        "Edward Ruggeri" <smallhand@crawblog.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Dynamic Memory Allocation Limit?
Message-ID:  <87k5ifljzy.fsf@kobe.laptop>
In-Reply-To: <919383240804291737k513360bcje6c4c85dc4621903@mail.gmail.com> (Edward Ruggeri's message of "Tue, 29 Apr 2008 20:37:12 -0400")
References:  <919383240804291737k513360bcje6c4c85dc4621903@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 29 Apr 2008 20:37:12 -0400, "Edward Ruggeri" <smallhand@crawblog.com> 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).
>
> 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?).

You are hitting the limit set as kern.maxdsiz (512 MB by default).

One possible 'optimization', which can bump the total count of numbers
you can represent in your sieve (at a small cost of extra complexity) is
to use a single *bit* for each number, and the macros from FreeBSD's
<bitstring.h>.  By using a bit-map for the numbers, you can represent
eight times as many numbers in a sieve of the same size.

Another option is to bump the value of kern.maxdsiz at boot time.  This
has been described many many times in the list archives, so a Google
search should quickly yield several hits.

> 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 ...

That's fine.  A question never asked is much worse than a question which
causes people to learn even more about FreeBSD :)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87k5ifljzy.fsf>