Comparison of Malloc() Algorithms
Thread
Loading the complete thread in the background. This saved snapshot is available now. Refresh
Unofficial Hacker News client; not affiliated with Y Combinator.
Comparison of Malloc() Algorithms
Loading the complete thread in the background. This saved snapshot is available now. Refresh
Unofficial Hacker News client; not affiliated with Y Combinator.
benjojo12 · · focus · HN ↗
j4k0bfr · · focus · HN ↗
Rygian · · focus · HN ↗
Nnnes · · focus · HN ↗
Funny SSL setup. Explanation from here <a href="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 · · focus · HN ↗
[deleted] · · focus · HN ↗
[deleted]
ncruces · · focus · HN ↗
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 better of average, for a significant reduction in code size.
<a href="http://www.gii.upv.es/tlsf/index.html" rel="nofollow">http://www.gii.upv.es/tlsf/index.html
<a href="https://github.com/ncruces/wasm2go/blob/main/libc-gen/c/malloc_tlsf.c" rel="nofollow">https://github.com/ncruces/wasm2go/blob/main/libc-gen/c/mall...
egberts1 · · focus · HN ↗
thomasmg · · focus · HN ↗
egberts1 · · focus · HN ↗
quietbritishjim · · focus · HN ↗
dark-star · · focus · HN ↗
Is this a spec violation or something?
gspr · · focus · HN ↗
egberts1 · · focus · HN ↗
dark-star · · focus · HN ↗
ligarota · · focus · HN ↗
eqvinox · · focus · HN ↗
entrope · · focus · HN ↗
0c3ca83 · · focus · HN ↗
dezsiszabi · · focus · HN ↗
entrope · · focus · HN ↗
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.)
egberts1 · · focus · HN ↗
egberts1 · · focus · HN ↗
Someone · · focus · HN ↗
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://jemalloc.net/" rel="nofollow">http://jemalloc.net/), the idea of arenas is from the 1960s, and Wikipedia claims the term was coined in 1990 (<a href="https://en.wikipedia.org/wiki/Region-based_memory_management#History_and_concepts" rel="nofollow">https://en.wikipedia.org/wiki/Region-based_memory_management...), and the linked paper (<a href="https://www.cs.princeton.edu/techreports/1988/191.pdf" rel="nofollow">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 · · focus · HN ↗
egberts1 · · focus · HN ↗
skavi · · focus · HN ↗
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.
imp0cat · · focus · HN ↗
egberts1 · · focus · HN ↗
skavi · · focus · HN ↗
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://news.ycombinator.com/item?id=47403847">https://news.ycombinator.com/item?id=47403847
imp0cat · · focus · HN ↗
We've tried tcmalloc, too. I don'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.
skavi · · focus · HN ↗
to confirm, you were using tcmalloc from <a href="https://github.com/google/tcmalloc" rel="nofollow">https://github.com/google/tcmalloc and not from <a href="https://github.com/gperftools/gperftools" rel="nofollow">https://github.com/gperftools/gperftools, right?
the latter is a lot worse iiuc.
imp0cat · · focus · HN ↗
skavi · · focus · HN ↗
[0]: <a href="https://github.com/google/tcmalloc/blob/master/docs/gperftools.md" rel="nofollow">https://github.com/google/tcmalloc/blob/master/docs/gperftoo...
zX41ZdbW · · focus · HN ↗
egberts1 · · focus · HN ↗
zX41ZdbW · · focus · HN ↗
egberts1 · · focus · HN ↗
skavi · · focus · HN ↗
<a href="https://news.ycombinator.com/item?id=47403847">https://news.ycombinator.com/item?id=47403847
egberts1 · · focus · HN ↗
adrian_b · · focus · HN ↗
> "The first memory allocation scheme started with a stack-based memory allocation. Next came the dynamic-based memory allocation scheme where linked-list and bucket-heap mechanism are used to divide the private-heap using size class approach. Soon, garbage collection algorithm introduced the initial backend of the memory allocation scheme."
Since no specific operating system is mentioned, these sentences appear to refer to the general history of dynamic memory allocation, in which case they are wrong.
"malloc" is a late comer in this history. It has appeared as the statement "ALLOCATE", together with the statement "FREE", in the programming language PL/I of IBM, by the end of 1964.
At that time many other techniques of managing memory had already been used for a few years.
Dynamic allocation of memory has started with allocation without ever freeing the allocated memory before the termination of the process.
Then, in 1960, 3 methods of handling dynamic memory allocation were published: the use of garbage collectors in April (John McCarthy), the use of stacks in May (E. W. Dijkstra), and the use of reference counts in December (George E. Collins @ IBM).
So the use of garbage collectors is actually the oldest published method for handling dynamic memory allocation, not a newer method.
egberts1 · · focus · HN ↗
adrian_b · · focus · HN ↗
Garbage collectors: "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I", John McCarthy, Communications of the ACM, pp. 184-195, 1960-04.
Stacks and stack pointers: "Recursive Programming", Edsger Wybe Dijkstra, 1960-05-11.
Reference counts for memory allocation were introduced in "A Method for Overlapping and Erasure of Lists", George E. Collins (IBM), Communications of the ACM, Volume 3, Issue 12, 1960-12, pp. 655–657.
egberts1 · · focus · HN ↗
AnimalMuppet · · focus · HN ↗
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 · · focus · HN ↗
brcmthrowaway · · focus · HN ↗
egberts1 · · focus · HN ↗
ddcc7 · · focus · HN ↗
egberts1 · · focus · HN ↗
D2OQZG8l5BI1S06 · · focus · HN ↗
egberts1 · · focus · HN ↗