This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
32 bit malloc on x86_64
- From: Jeremy Sanders <jss at ast dot cam dot ac dot uk>
- To: libc-help at sourceware dot org
- Date: Mon, 7 Jul 2008 17:49:27 +0100 (BST)
- Subject: 32 bit malloc on x86_64
Hi -
I'm trying to get a program working again on 64 bit linux. It's ancient
astronomy code which contains lots of Fortran 77. It has dynamic memory
allocation for F77 by simulating it by returning integer indices into an
array which spans the whole of memory. C malloc is used to allocate the
memory. This is pretty horrible but mostly works.
As the array indices are only 32 bit integers, this means it fails if the
returned address from malloc is outside of the 1st 32 bit range. This
cannot be fixed generally in the fortran code.
The authors of the program have hacked around this by using
"mallopt(M_MMAP_MAX, 0)" to only provide dynamic memory from low addresses
on the heap and not get it from mmaping memory. I have no idea whether
this behaviour is guaranteed by this function call.
Unfortunately between kernel versions 2.6.24.7-92.fc8.x86_64 and
2.6.25.4-10.fc8.x86_64, Fedora 8 now returns large addresses randomly,
despite the mallopt, even though there is lots of low memory available.
The behaviour seems to be random. Sometimes it does this and sometimes it
doesn't for the same program and data.
Is this change in behaviour a bug in Fedora, glibc or the kernel?
I have come up with a workaround, which is to use mmap myself to allocate
the memory with the MAP_32BIT flag. This appears to work okay in test I
have done, but it is a pain as I have to keep track of the allocated
length for munmap. I read that MAP_32BIT really only gives you 31 bits of
memory, but this program doesn't use huge amounts of memory.
Is this a sensible way to proceed?
Thanks
Jeremy
--
Jeremy Sanders <jss@ast.cam.ac.uk> http://www-xray.ast.cam.ac.uk/~jss/
X-Ray Group, Institute of Astronomy, University of Cambridge, UK.
Public Key Server PGP Key ID: E1AAE053