‹ BackHN Continuity

Thread

Comparison of Malloc() Algorithms

144 points · 51 comments · egberts1

  1. Someone · · focus · HN ↗
    Not a good article, IMO.

    FTA: “When multiple threads simultaneously allocate or deallocate memory from the allocator, the allocator will serialize them. Programs making intensive use of the allocator actually slow down as the number of processors increases.”

    The article does later retract on that, but that’s no reason to lead with such a blatantly false (with current allocators) statement.

    Also FTA “In 2006, a third pool was introduced (after operating system memory pool and library-based memory pool) called the “arena”. Arena is a jemalloc-term”

    Jemalloc is from around 2005 (<a href="http:&#x2F;&#x2F;jemalloc.net&#x2F;" rel="nofollow">http:&#x2F;&#x2F;jemalloc.net&#x2F;), the idea of arenas is from the 1960s, and Wikipedia claims the term was coined in 1990 (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Region-based_memory_management#History_and_concepts" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Region-based_memory_management...), and the linked paper (<a href="https:&#x2F;&#x2F;www.cs.princeton.edu&#x2F;techreports&#x2F;1988&#x2F;191.pdf" rel="nofollow">https:&#x2F;&#x2F;www.cs.princeton.edu&#x2F;techreports&#x2F;1988&#x2F;191.pdf) is from 1988.

    Then, a typo: “as well as memory tied to specific to each of the multiple CPU core or even CPU infinity.”

    “Infinity” should be “affinity” there.

    1. skavi · · focus · HN ↗
      yup and the characterization of each allocator is so fuzzy, with zero methodology provided.

      allocators are so simple to just swap into your program. if you can put together a few representative workloads, you should just try out a few allocators and profile whatever metrics you care about.

      1. imp0cat · · focus · HN ↗
        And finally end up with either jemalloc or possibly mimalloc. ;)
        1. skavi · · focus · HN ↗
          we actually ended up with (new) tcmalloc.

          for us, tc was among the fastest in runtime while being very space efficient [0]. large rust application using far too many threads.

          we’ve since also had great success with tc’s built in profiling tools.

          [0]: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47403847">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47403847

          1. imp0cat · · focus · HN ↗
            Interesting, is there an accompanying article?

            We&#x27;ve tried tcmalloc, too. I don&#x27;t remember the exact details, but we basically ended using jemalloc because it was using way less memory.

            Same story with mimalloc - it usually provided a tiny bit more speed, but required more cpu and memory.

            1. skavi · · focus · HN ↗
              no article, sorry, grabbed the numbers from an old PR.

              to confirm, you were using tcmalloc from <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;tcmalloc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;tcmalloc and not from <a href="https:&#x2F;&#x2F;github.com&#x2F;gperftools&#x2F;gperftools" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gperftools&#x2F;gperftools, right?

              the latter is a lot worse iiuc.

              1. imp0cat · · focus · HN ↗
                Good point. It was from the <a href="https:&#x2F;&#x2F;packages.debian.org&#x2F;trixie&#x2F;google-perftools" rel="nofollow">https:&#x2F;&#x2F;packages.debian.org&#x2F;trixie&#x2F;google-perftools Debian package, which points to the gperftools project - so it was the worse one I guess.
                1. skavi · · focus · HN ↗
                  yeah that’s a common mistake when evaluating tcmalloc. gperftools tcmalloc diverged quite a while ago. doesn’t have a lot of the fancier features of modern tcmalloc [0].

                  [0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;tcmalloc&#x2F;blob&#x2F;master&#x2F;docs&#x2F;gperftools.md#differences" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;tcmalloc&#x2F;blob&#x2F;master&#x2F;docs&#x2F;gperftoo...

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.