maximally misaligned

Jason Evans jasone at canonware.com
Thu Oct 3 14:27:42 PDT 2013


On Dec 26, 2012, at 3:50 PM, Bradley C. Kuszmaul <kuszmaul at gmail.com> wrote:
> It would be useful if there were a way to configure jemalloc to give
> the worst acceptable alignment for every returned object.
> 
> I'm currently debugging a program that uses O_DIRECT for file I/O.
> This option requires that all pointers passed to read() and write() be
> 512-byte aligned.  There is an occasional function that uses malloc()
> to create a buffer instead of something like memalign().  I'd like it
> if the malloc() could be tweaked so that the returned pointer from
> malloc(4096) was aligned to be off by, say 16 bytes.  Otherwise there
> fact that malloc(4096) seems to return a 512-byte aligned pointer
> masks a bug in the program.
> 
> I've implemented this misaligned mallocator on top of malloc() for my purposes.
> 
> Is this something that might belong in the jemalloc library instead of
> in my code?  Maybe it's already there and I don't know about it.
> Maybe this is a dumb idea and it really belongs in the application, as
> I've done it.

I have tentative plans to make alignment of allocations more random, in order to reduce CPU cache conflicts.  However, I don't think intentional minimal alignment for allocations will ever fit well in jemalloc, because jemalloc tries hard to pack objects in ways that conflict with the misalignment feature you built.

Jason


More information about the jemalloc-discuss mailing list