Re: mmap alignment.
Re: mmap alignment.
- Subject: Re: mmap alignment.
- From: Jim Magee <email@hidden>
- Date: Thu, 16 Feb 2006 23:03:54 -0500
On Feb 14, 2006, at 12:00 AM, Theo Schlossnagle wrote:
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.
Note that over-allocating and aligning only wastes virtual space.
Physical memory is not allocated for the "alignment slop." At least
not in most normal uses.
But if you are already using Mach interfaces, then using vm_map()'s
alignment mask parameter is probably a good way to go.
--Jim
_______________________________________________
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