News for hackers. Stuff that matters.
Re:What is malloc doing, anyway? by loeg on Monday November 09, 2026 @04:14PM (#50432254)
This is mostly describing a kind of obsolete allocator that uses the brk to adjust a single contiguous heap range. This is basically irrelevant with virtual memory and mmap. The good malloc impls (jemalloc, mimalloc) don't do this.
Re:What is malloc doing, anyway? by schmichael on Monday November 09, 2026 @04:41PM (#50432645)
mmap is covered later on, and as an introduction to heap memory management this seems like the right place to start. jemalloc and mimalloc build upon the fundamentals explained here.

What I'd love is for an article that goes a step back in allocator theory instead of "forward" to jemalloc/mimalloc. Optimal resource allocation has a rich history in pre-computer fields whose general theories are applicable today. Replace "linear memory" with "paper roll" and "types" with "items", and instead of malloc you have the cutting stock problem! https://en.wikipedia.org/wiki/Cutting_stock_problem

The reason why allocator fundamentals are important is because there is no universally optimal solution. jemalloc "emphasizes fragmentation avoidance and scalable concurrency support" while mimalloc focuses on a bounded worst-case allocation latency. Meanwhile if you're writing extremely memory constrained code for certain embedded systems, you may still be best off using a simple bump allocator with no free! https://devblogs.microsoft.com/oldnewthing/20180228-00/?p=98... The optimal resource allocation strategy is always use case dependent.

Re:What is malloc doing, anyway? by nayuki on Monday November 09, 2026 @05:26PM (#50433181)
> Since the missile will explode when it hits its target or at the end of its flight, the ultimate in garbage collection is performed without programmer intervention.

I would argue that the missile performs the ultimate in physical garbage creation at the end of its flight.

Re:What is malloc doing, anyway? by cadamsdotcom on Monday November 09, 2026 @06:33PM (#50433909)
Whoosh
Re:What is malloc doing, anyway? by bkallus on Monday November 09, 2026 @05:00PM (#50432871)
> The good malloc impls (jemalloc, mimalloc) don't do this.

I agree.

> This is mostly describing a kind of obsolete allocator

I disagree. glibc malloc is still extremely relevant and sees a lot of development, and uses exactly this strategy (unless an allocation request is too big, in which case it mmaps, just like the allocator described in the article).

Re:What is malloc doing, anyway? by puffybuf on Monday November 09, 2026 @07:42PM (#50434572)
yea I did this in openbsd with ktrace / kdump and utrace calls. I had to increase the size significantly to see mmap calls