jemalloc builds

Since just before the holidays, Jason and I have been working on getting jemalloc ported to Windows, Mac and Linux as well as integrated in to our build system.  Each platform has its own set of challenges, with Windows being the most exciting.  I tried several approaches including dynamically patching over the C runtime allocation functions (malloc, free, etc) in memory, but kept running in to issues with the allocations the CRT does during startup.  Things like putenv() realloc and free allocations that were done before we had the chance to patch in.  I talked to Benjamin about replacing the CRT and he did a bunch of work to get a CRT building with jemalloc.  It turned out not to be very difficult — Microsoft includes the source as part of Visual Studio Professional (sadly, you can’t redistribute it).  I had to make various changes to the init functions to make sure we could use CRITICAL_SETIONs and thread local storage during malloc initialization.  Was a bit of a pain to make sure the malloc initialization code didn’t call things that needed to allocate but eventually I got everything working.  The result: A Windows jemalloc build.  The sunspider JS test looks to run about 5% faster.  You’ll notice that these builds take up a bit more memory initially but they should level out around 80mb.  There is plenty of tuning left to do, but I’m curious to hear how these run for people after running for a long time.

Linux builds are stable but I don’t have one handy.  Mac builds run for a little while before they crash, but the crash looks like one I fixed on Windows so I expect to have those early next week.

Explore posts in the same categories: Mozilla

Tags: , , ,

You can comment below, or link to this permanent URL from your own site.

17 Comments on “jemalloc builds”

  1. Ferdinand Says:

    I tried your build and it feels faster but doesn’t seem to make a real difference in memory usage. I have loaded heavy pages like Google Reader, Gmail and Digg to get the memory usage as high as possible. Right now Windows Taskmanager(vista 32bit) reports 151.652K with only this page open.

  2. sdwilsh Says:

    So, how would we be shipping a build with this for windows? Don’t we have to distribute our source code?

  3. Nils Says:

    For Windows: Can’t you just specify your own entry point which will do the patching and afterwards call the CRT entry-point?
    Something along the lines of:
    void __cdecl mozmainCRTStartup( void ) {
    /* … patching … */
    mainCRTStartUp(); // or WinMainCRTStartup ?
    linking it with /ENTRY:”mozmainCRTStartup”

  4. pavlov Says:

    Ferdinand: Thanks for the data point. We’ll keep tuning it.

    sdwilsh: We can distribute a script to patch things I think. It might just be a little delicate.

    Nils: I tried doing that but in order to start up the allocator we need a couple things that don’t allocate to be initialized in the CRT. Bad ordering problem ;(

  5. Schrep Says:

    On Vista loading/closing the same 50 web pages:

    Today’s trunk: 67MB
    JEMalloc: 64.5MB

    So a definite small improvement. Note these tests arn’t deterministic since ad content can vary. Once you get me mac builds I can run longer and more repeatable tests.

    5% on SunSpider is nothing to sneeze at neither!

  6. Thales Says:

    Any chance of jmalloc land in Firefox 3.0 trunk? The speed difference is great.

  7. jimis Says:

    Did you try setting various glibc mallopt() options, as I had proposed in previous comments?

  8. Roger Says:

    It keeps crashing with some MSVC++ error dialog after some time (several hours), even when I’m not using it at the moment (crashed a while ago while I was watching a movie).
    I’m using my FF3beta profile, so take with a grain of salt.

  9. [...] now on the trunk Our Windows nightlies (beta4pre, this is not in beta 3) now include jemalloc.  These builds are leaps and bounds better than the last build I [...]

  10. pavlov Says:

    jimis: I haven’t yet. We’re just now looking at Linux so I’ll take a look here shortly.

  11. Pola Says:

    I’ve tried to compile te mozdev19.dll.
    After fixing the missing file unhandld.obj; I am still unable to compile it.

    I got
    fatal error LNK1181: cannot open input file ‘build\intel\dll_obj\asctime.obj’
    NMAKE : fatal error U1073: don’t know how to make ‘build\intel\dll_obj\_setargv.obj’

    Do you have any sugestion.

    Thanks in advance.

  12. [...] on trunk — linux edition Back on the 12th of February we turned jemalloc on in our Linux builds.  Sorry for not posting sooner!  We saw a good performance increase and a [...]

  13. [...] a renewed commitment to addressing these criticisms, as does Stuart Parmenter’s work on reducing memory fragmentation. Stories like this should help to win over geek hearts and minds, although end users will withhold [...]

  14. [...] carefully studied the fragmentation effects of various allocators and concluded that jemalloc gave us the smallest amount of fragmentation after running for a long period of time. I’ve [...]

  15. cgk Says:

    So, simply re#defining malloc/free/realloc and then mapping them to an own no-/low-fragmentation heap implementation (e.g., like ) was not an option?

    Or just replacing the malloc/free/realloc calls with project-unique names with the same signature.

  16. [...] build available. In addition to using the same source as Firefox 3 RC3, XULRunner RC3 also enables jemalloc support on Windows, just like [...]

  17. [...] the primary place to track our efforts to fix the problem. However, it became clear that porting jemalloc to WinCE was the best way to handle the situation, so bug 478044 became the bug to watch. As you [...]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: