[PATCH] Add a chunk_aligned_alloc function handling alignment constraints on chunks

Mike Hommey mh+jemalloc at glandium.org
Wed Apr 11 05:24:16 PDT 2012


On Tue, Apr 10, 2012 at 02:59:03PM -0700, Jason Evans wrote:
> On Apr 10, 2012, at 10:54 AM, Mike Hommey wrote:
> > On Tue, Apr 10, 2012 at 07:50:33PM +0200, Mike Hommey wrote:
> >> From: Mike Hommey <mh at glandium.org>
> >> 
> >> ---
> >> include/jemalloc/internal/chunk.h      |   15 ++++++++++-
> >> include/jemalloc/internal/chunk_dss.h  |    2 +-
> >> include/jemalloc/internal/chunk_mmap.h |    2 +-
> >> src/chunk.c                            |    7 ++---
> >> src/chunk_dss.c                        |   46 +++++++++++++++++++-------------
> >> src/chunk_mmap.c                       |   28 +++++++++----------
> >> src/huge.c                             |   33 ++---------------------
> >> 7 files changed, 63 insertions(+), 70 deletions(-)
> > 
> > The reason why I'm interested in this is that the way VirtualAlloc and
> > VirtualFree work on Windows makes it cumbersome to do "huge" alignment,
> > and would require going through hoops and repeating code between huge.c
> > and chunk_mmap.c. It gets simpler if everything is handled in one place.
> > 
> > I'm not sure how to best stress test the changes in chunk_dss.c, so I'm
> > not sure it doesn't break in subtle ways. The changes in chunk_mmap.c
> > are much more straightforward.
> 
> There were problems in the dss code that I had to fix, and I did some
> other refactoring that this change allowed (e.g. huge_malloc() now
> just calls huge_palloc()).  The result is committed now; please let me
> know if you encounter any problems with the changes I made.

It looks good, although I didn't test dss since Windows doesn't have
sbrk. Since I don't think it makes sense to emulate sbrk in jemalloc,
chunk_dss should be completely disabled there. How would you feel about
a patch that doesn't build chunk_dss.c and sets all functions declared in
chunk_dss.h to be dummy inline functions when dss is not enabled? That
would allow to keep the if (config_dss) parts and avoid replacing them
with #ifdefs. Or are you just fine with replacing them with #ifdefs?

> By the way, I'm excited to see hints of Windows support in the works. =)

At this point, I have jemalloc working single-threaded with mingw and
mingw64: the test suite pass, but I have random asserts in the threaded
tests. I haven't implemented tsd and proper mutexes yet.

Mike



More information about the jemalloc-discuss mailing list