Jason Martin on Sat, 27 Jan 2007 02:46:38 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: GMP build on OSX


--- Vincent Lefevre <vincent@vinc17.org> wrote:
> On 2007-01-26 17:03:16 +0100, Bill Allombert wrote:
> > Probably neither (directly). Blanking pages is the duty of the
> > kernel and occurs when memory is requested. It is probably caused by
> > the malloc library (normally part of the C library) . Maybe you
> > could try alternative malloc libraries or alternative OS.
>
> Page-zeroing should be done by the kernel for obvious security reasons.
> This means that whatever C library is used, pages will be zeroed. So,
> changing the malloc library probably won't have any effect, unless the
> default library does reads/writes or something else to make sure that
> the memory is really allocated (and not just address space like under
> Linux). But I don't know what the policy is under Mac OS X and I've
> never done any test about that.

However, so far the kernel has zeroed 10^13 bytes of memory for my single
process. Given that the process only has a memory footprint of ~150MB, that's
9,999,850MB of unnecessary zeroing of memory, causing a 20% performance hit.

When my processor goes idle, I'll try the non-GMP kernel, and see if it makes
any difference. I'll also see if alloca makes a difference in GMP.

Phil


I believe that the GMP source code implements memory management via a
set of macros: TMP_DECL, TMP_MARK, TMP_ALLOC, TMP_FREE, etc.  By
default on most platforms, these pickup the standard C library memoy
allocation functions during the configure stage.  However, you can
certainly edit the header files to include your own memory management
functions.

It might be reasonable in your case to write your own memory manager
(much the same way memory is handled in the Pari C library).  Allocate
one giant block at the beginning, and then treat it like a stack (with
periodic block copying to keep it somewhat contiguous).  In fact, you
can probably find code to do this somewhere out there on the web...
it's a common assignment for upper level CS classes.

Good Luck!!

--jason

--
Jason Worth Martin
Asst. Prof. of Mathematics
James Madison University
http://www.math.jmu.edu/~martin
phone: (+1) 540-568-5101
fax: (+1) 540-568-6857

"Ever my heart rises as we draw near the mountains.
There is good rock here." -- Gimli, son of Gloin