Address space: what's safe?

Martijn van Oosterhout kleptog at svana.org
Fri Mar 7 10:31:19 EST 2003


On Fri, Mar 07, 2003 at 09:54:27AM +1100, Steve Blackburn wrote:
> Hi,
> 
> I want to know (preferably at run time) what parts of the address
> space are safe for me to use (in user space).
> 
> The context is the memory management subsystem of Jikes RVM, where
> certain algorithms want as much virtual memory as possible with
> various alignment restrictions etc.  Because we have all sorts of
> constraints about alignments etc, we use mmap to get ourselves the
> memory.  mmap does not tell you if a shared library is about to
> clobber the space you just got or you're about to clobber a shared
> library (at least not as far as I can tell!---if it can, then this
> might be all I need).

Let me get this straight. You are assuming as free any memory within your
start/end range, even though you havn't mmap()ed at the time. And you're
surprised that when it's unmapped and you load a shared library (which uses
mmap()) can end up in that space? The kernel can't tell the difference
between mmap() for memory and mmap() for shared lib.

> To date we've approached it via statically defining safe start and end
> ranges and have had to change those constants by trial and error as
> new releases come out (new releases of the shared libraries, I
> suppose)---I run our system on a new release and we suffer some
> horrible memory corruption problem and then I find that a shared
> library has been loaded over the top of an address range we previously
> believed to be safe.

If you havn't mapped it, it's not safe.

> What we'd like is a way of establishing these ranges at run time, or
> at worst, at build time.  We really want a map of what parts of the
> address space are free for us to mess with, or an interface that tells
> us what we can't use---so we can make our own map.

The only space you know nothing will go into is the heap (ie brk() and
related).

My suggestion is to simply map at the beginning a huge anonymous block of
the size required. This will be contiguous. But none of the pages will be
initialised until you actually touch them. With careful coding you can
probably make sure of that (you must be already). And then unmap/remap when
you want to reset a page.

Actually, there is mmap( PROT_NONE ) which may allocate the space but still
segfault if you touch it. Dunno if that works though.

Hope this helps,
-- 
Martijn van Oosterhout   <kleptog at svana.org>   http://svana.org/kleptog/
> Support bacteria! They're the only culture some people have.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.samba.org/archive/linux/attachments/20030307/482cc555/attachment.bin


More information about the linux mailing list