phkmalloc

https://news.ycombinator.com/rss Hits: 5
Summary

phkmalloc Jason Evans laid jemalloc to rest yesterday, and gave a kind shoutout to my malloc, aka. “phkmalloc”, and it occured to me, that I should write that story down. I wrote a little bit about it in my article for the 30 year aniversary issue of the FreeBSD Journal but there is more to it than that. Why In FreeBSD we inherited Chris Kingsley’s malloc implementation from BSD, it worked, and we had much larger fish to fry, so we paid it no attention. During 1994 and 1995, RAM prices went through the roof, and therefore, conciously or subconciously, efficient use of RAM became a concern. In my case it became a huge concern, because my machine only had 4MB RAM and being release engineer, I ran GCC a lot. My system paged more than I thought it should, and in particular I noticed a very distinct burst of disk-activity whenever GCC terminated. The “death-rattle” was even more prominent with Tcl and Tk programs. That made no sense to me, why would things page when the program was freeing things prior to termination ? The “canonical” malloc implementation, the malloc implementation to start all malloc implementations, is in chapter 8.7 in The C Programming Language, and as all code in that book it is simple and elegant: A linked list holds the free blocks of memory, and that is pretty much it. If you are up for a challenge: Go read chapter 8.7 now, and see if you can predict what comes next :-) The problem K&R’s malloc was written on a swapping system, probably a PDP-11, where either the entire process is in memory or the process does not run. In the meantime we had gotten Virtual Memory, where pages may or may not be in RAM when you need them, but the kernel handles that, so from a programmes point of view, the only difference is that sometimes a memory access causes disk activity. Chris Kingsley’s malloc starts with this comment: /* * malloc.c (Caltech) 2/21/82 * Chris Kingsley, kingsley@cit-20. * * This is a very fast storage allocator. It allocates blocks of a small...

First seen: 2025-07-04 14:12

Last seen: 2025-07-04 18:13