Doug Lea's Malloc

(cs.oswego.edu)

32 points | by grep_it 3 days ago

6 comments

  • senderista 3 hours ago
    It was a good single-threaded allocator back in the day but in the multicore era the design is now thoroughly obsolete. I suggest reading e.g. the jemalloc[1] and mimalloc[2] papers if you want to understand how modern allocators are implemented.

    [1] https://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemal...

    [2] https://www.microsoft.com/en-us/research/wp-content/uploads/...

    • HexDecOctBin 2 hours ago
      Considering that global allocators are usually an anti-pattern and that most applications should have component-specific allocators, dlmalloc isn't all that bad when used through its mspace API. Of course, if one doesn't actually need a general allocator, they should simply use an arena allocator.
      • Conscat 1 hour ago
        Musl still supports single threaded slab allocations. In Musl, the difference comes down to one lock, some atomics, and a #define. My library extracts out its algorithm and let's you use scoped single and multi threaded Musl allocators freely mixed with each other.
    • jart 1 hour ago
      Cosmopolitan uses dlmalloc and just wraps it with an rseq allocator for multicore performance. See also https://jart.dev/rseq/
    • brcmthrowaway 2 hours ago
      Has anyone tried jev as an allocator?
  • pcwalton 1 hour ago
    Besides the lack of thread-local allocation buffers that other comments have mentioned, the other problem with dlmalloc is that the metadata is stored inline, right next to the chunks. This is bad for security as it makes it much easier to weaponize out-of-bounds writes.
  • ncruces 36 minutes ago
    Still used quite a bit on Wasm/WASI (mostly single threaded).

    I recently switched to using TLSF for that: https://github.com/ncruces/wasm2go/blob/main/libc-gen/c/mall...

  • asveikau 3 hours ago
    In the mid 2000s I was a student in upstate NY and I very briefly met Doug Lea. (I'm 100% sure he doesn't remember me at all.) He was a very warm, approachable, down to earth guy. The computer labs at Oswego had a bunch of giant Sun Microsystems logos on all the gear, I guess because they were funding him.
  • acyclic 2 days ago
    The only algorithm to be named after someone's full name, first and last name
  • tripdout 3 hours ago
    I believe this was the original malloc used in Android's bionic libc.
    • egberts1 2 hours ago
      False.

      Android up to v4.1 bionic is based on Doug Lea's dlmalloc v2.8.3

      Android v4.2 upgraded to dlmalloc v2.8.6

      Android v5.0 transitioned to jemalloc.

      Modern Android is based on jemalloc or Scudo, based on build configuration.

      Android never used original dlmalloc.

      • Conscat 1 hour ago
        Am I confused or did you agree with your parent comment that dlmalloc was the original algorithm used by Android?