5 ms·
Comparison of Malloc() Algorithms
- benjojo12 17d agoERR_SSL_VERSION_OR_CIPHER_MISMATCH on my phone it seems?
- Nnnes 17d agohttps://web.archive.org/web/20260915165314/https://egbert.net/blog/articles/comparison-of-arena-architecture-in-malloc.html https://web.archive.org/web/20260915165314/https://egbert.ne... Funny SSL setup. Explanation from here https://news.ycombinator.com/item?id=49133598 https://news.ycombinator.com/item?id=49133598 > Oh, certain browser will not work with this blog if it cannot negotiate ONLY for Cha-Cha/Poly. It's by design as a showcase of why that particular web browser refuses to do that. I assume the "particular web browser" is Chromium, which won't load it on any OS I've tried. On Windows, Firefox and the built-in curl.exe also refuse to connect.
- bom-d-van 17d agolegend.
- deleted 17d ago[deleted]
- ncruces 17d agoThanks for the link. Article makes it look like nothing happened in the embed/low-memory/single-threaded malloc space in decades since Doug Lea's malloc. I just implemented TLSF for my minimal Wasm libc: fragmentation is just as good, performance is a lot more consistent (and on average better), for a significant reduction in code size. http://www.gii.upv.es/tlsf/index.html http://www.gii.upv.es/tlsf/index.html https://github.com/ncruces/wasm2go/blob/main/libc-gen/c/malloc_tlsf.c https://github.com/ncruces/wasm2go/blob/main/libc-gen/c/mall...
- egberts1 17d agoA great idea for another article. A focus, on embedded and malloc() I do do have a malloc() benchmark but it is in bad shape and directories have not coalesce nicely yet, tor a single run or a menu-driven one.
- thomasmg 17d agoInteresting! I have also implemented a version of TLSF for my (currently single-threaded) programming language. I also found it to be good for my use case (embedded / minimal code size). I'll compare it against yours. One improvement I did is some kind of preallocation for small blocks. https://github.com/thomasmueller/bau-lang/blob/main/src/main/java/org/bau/parser/StandardLib.java#L9 https://github.com/thomasmueller/bau-lang/blob/main/src/main...
- egberts1 17d agoIt keeps certain web scrapers and inline transparent proxies/IDS/XNS from fetching, 100% Certain browsers will suffer. Meh.
- quietbritishjim 17d agoFirefox on Windows user here, and it loads the blog fine. I don't have Chrome installed but Edge (which is Chromium engine based) doesn't load it.
- dark-star 16d agoI don't get what this is supposed to prove. That my browser doesn't allow websites to declare what encryption they use? I am pretty sure there's a point to all of this, but please let me (and my browser) choose which encryptions I want to trust. Is this a spec violation or something?
- gspr 16d agoIsn't the idea that the server and client should agree on a common subset? Here, the server's subset is very small, but not esoteric – so then surely it's the client that's lacking in features?
- ligarota 17d agoPlease write a "how to setup SSL" article
- eqvinox 17d agoIt seems to be intentional & if somebody wants to make a statement about TLS with their personal website that's their choice to make and execute.
- entrope 17d agoOn the bright side, lots of people will be saved from reading bad prose like "Malloc (libc) is the worst memory allocation API to use" and "Programs should avoid, if possible, allocating/deallocating memory too often". (By definition, "too often" means it can possibly be avoided, and usually that it can practically be avoided.)
- 0c3ca83 17d agoBeats the hell out of most of the LLM-generated "honest assesments" of things on this site.
- dezsiszabi 17d agoI might be stupid, but what's wrong with those sentences?
- entrope 16d agoThe first one was offered with no explanation and no claimed better alternative. malloc() is probably the simplest interface for generic runtime allocation, and simplicity has a lot in its favor. malloc() does not provide type safety, is susceptible to external fragmentation, and makes it harder to meet the performance goals outlined in the rest of the blog post. So malloc() reflects trade-offs, but saying that the standard API "is the worst memory allocation API to use" should be supported, even if briefly, instead of simply asserted: meeting the goals I listed inflicts other drawbacks, like needing to create and manage separate heaps. I thought my explanation for the second one was already clear: "Programs should avoid, if possible, [doing X] too often" is a truism because "too often" implies that some reduction is possible. One should leave out the ", if possible," -- although deciding what is "too often" can be challenging and sometimes a matter of taste. (Is reducing allocation frequency by 5% worth doubling the CPU usage or memory usage or code complexity? Maybe in some cases, but often not.)
- Someone 17d agoNot 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 (http://jemalloc.net/ http://jemalloc.net/), the idea of arenas is from the 1960s, and Wikipedia claims the term was coined in 1990 (https://en.wikipedia.org/wiki/Region-based_memory_management#History_and_concepts https://en.wikipedia.org/wiki/Region-based_memory_management...), and the linked paper (https://www.cs.princeton.edu/techreports/1988/191.pdf https://www.cs.princeton.edu/techreports/1988/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.
- eqvinox 17d agoThe tables look mostly correct, and that's what I'll be bookmarking this for… I don't think I've seen any elsewhere that are this extensive (in both axis, total allocators covered & details per allocator).
- egberts1 17d agoThank you. I got tired of reading AI prose so I compiled and wrote it from my collections of others' whitepapers. As a "For Reference Only", at the very least, for me. As usual, anyone is welcome to improve upon it under CC BY-NC-SA.
- skavi 17d agoyup 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.
- AnimalMuppet 17d agoCouldn't read the article (ERR_SSL_VERSION_OR_CIPHER_MISMATCH, Chrome on Windows). But I'm remembering something a coworker told me some time around... 1991 to 1993, maybe? Forgive me if I repeat some of what the article says - I did try to read it! While he was at the university, they were experimenting with different kind of mallocs. One was called the "buddy" malloc. It kept a list of free blocks of various sizes, and when you asked for a block and it didn't have one, it asked the OS for twice as much as you asked for. From the rest, it made another block (identical to yours, called the "buddy" block), and put it on the free list of that size. Well, they experimented with a similar algorithm, but the idea was that most requests were small. So it took the buddy block and broke it into smaller pieces, one half the size of the request, one a quarter the size, and so on, and put those on their respective free lists. They called this the "donner" malloc, because you carved up your buddy. From the way my coworker smiled, I think he thought it was amusing, but I don't think he was making it up.
- egberts1 17d agoD. S. Hirschberg, A Class of Dynamic Memory Allocation, CACM 16(10) 1973 covered this variants of halving Buddy Allocator.
- brcmthrowaway 17d agoWhat malloc does macOS use in userspace? How about kernel?
- egberts1 17d agoIn NextSTEP 3, it was zoned-based allocation. Rhapsody and early MacOS X, Darwin also used zone-based Early iPhone also zone-based. Later MacOS X implemented scalable zone, magazine allocator. iPhone 12+ then went Nano allocator, ScalableZone + large/VM allocator Latest iOS/iPadOS use Nano2
- D2OQZG8l5BI1S06 17d agoEvery time I tried to replace the allocator in an app, the speedup was negligible.
- egberts1 15d agoThen don't worry about it. Your CPU is obviously able to handle your purportedly high-transactional workload ... until it doesn't.