Re: mmap alignment.
Re: mmap alignment.
- Subject: Re: mmap alignment.
- From: Theo Schlossnagle <email@hidden>
- Date: Tue, 14 Feb 2006 00:00:25 -0500
- Domainkey-status: good
On Feb 13, 2006, at 11:31 PM, Mike Smith wrote:
On Feb 13, 2006, at 3:04 PM, email@hidden wrote:
I'm porting an app that uses mmap() and banks on its alignment
behaviour on Solaris and Linux.
I'd like to mmap a 64k and have the resulting address be aligned on a
64k boundary. I'm trying with:
mmap((void *)65536, 65536, PROT_NONE, MAP_PRIVATE | MAP_ANON |
MAP_NORESERVE | MAP_ALIGN, -1, 0);
This is almost always guaranteed to fail, as you are trying to map
*at* 64KB, and normally you will find your program's text mapped
around there.
MAP_ALIGN is not supported on Mac OS X.
However, the return address is not modulo 64k. How do I
accomplish what I want?
Well now, what is it, specifically, that you think you want? Why
is a virtual address modulo 64K important? (Pointer overloading?)
One approach would be to use vm_allocate to allocate an N + 64K
sized chunk, round the base address up to the next boundary, free
the chunk and then mmap with that address as a hint. Unless you
have activity elsewhere (on e.g. another thread) in your app,
that's pretty safe).
Thanks everyone for the replies.
What I am attempting to do it port Solaris' super-scalable slab
sllocator (libumem) to Darwin. We have a product that runs ons on a
variety of architecture that leverages a custom allocator for
performance and uniformity. The Solaris would seems a bit better
than ours and we wanted to adopt it while still having a consistent
allocator across all platforms.
Using the vm_map() directly may be one approach. We already use
pthread_mach_thread_np in part of the porting effort. As it will be
allocating a tremendous amount of memory and efficient use is a goal,
over-allocating and doing alignment ourselves isn't the right approach.
// Theo Schlossnagle
// Principal Engineer -- http://www.omniti.com/~jesus/
// OmniTI Computer Consulting, Inc. -- http://www.omniti.com/
// Ecelerity: Run with it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden