Rust Allocators and Memory Management

  Рет қаралды 9,713

Michael Mullin

Michael Mullin

Күн бұрын

Пікірлер: 23
@Hector-bj3ls
@Hector-bj3ls Жыл бұрын
I love a good "level 2" understanding of a subject.
@meanmole3212
@meanmole3212 5 ай бұрын
it is good but wait until you get a taste of level 7
@TehGettinq
@TehGettinq Жыл бұрын
Ahh a habs fan, fellow rust programmer and vim user. Delightful combination. Thanks for the video.
@seikatsu_ki
@seikatsu_ki Жыл бұрын
We yearn for serious topics, thank you for sharing with us your digging deep's journey!
@masmullin
@masmullin Жыл бұрын
Thank you. This is one of my favourite compliments I've received.
@meyou118
@meyou118 3 ай бұрын
love this - glad i stumbled on this
@kuhluhOG
@kuhluhOG 5 күн бұрын
There is one interesting takeaway: Microsoft seems to have nailed the defaults pretty darn well when it comes to their allocator. Sure, one can make it better or worse with different allocators and configurations, but as a default, this is pretty darn good.
@kuhluhOG
@kuhluhOG 5 күн бұрын
One question I have (especially with your example application) is how using arena allocators (e.g. one arena per request) who use the global allocator as a backing allocator would influence the memory usage and performance.
@ronlevi8298
@ronlevi8298 2 ай бұрын
Great video, super useful
@semigsedem
@semigsedem Жыл бұрын
Many thanks, I learned a lot. Just the right detail level for me I think :)
@masmullin
@masmullin Жыл бұрын
Glad it helped!
@mike-barber
@mike-barber Жыл бұрын
Nice one! Might be good to critique the system allocator on Alpine too, since it's not just glibc, and seems to perform quite poorly in some cases. Nice to have mimalloc and jemalloc available to work around it.
@masmullin
@masmullin Жыл бұрын
Oh, now I'm kicking myself. That's a really good idea
@mike-barber
@mike-barber Жыл бұрын
@@masmullin thanks! I think it could be quite interesting indeed!
@masmullin
@masmullin Жыл бұрын
Looks like musl (the standard libc of alpine) has a bespoke malloc implementation (elixir.bootlin.com/musl/latest/source/src/malloc/mallocng/malloc.c). This allocator is significantly slower than glibc (and jemalloc/mimalloc). The good news is that it's just as easy to replace the allocator in musl as it is with glibc. By switching to mimalloc+musl, the test application shown at the end of the video performs only about 4% slower than mimalloc+glibc (roughly on par with glibc alone), and musl alone is 38% slower than mimalloc+musl. jemalloc_perf+musl is the same as mimalloc+musl, but with the high memory initial overhead as seen with jemalloc+glibc.
@irlshrek
@irlshrek Жыл бұрын
absolutely loving your content!
@CamaradaArdi
@CamaradaArdi Жыл бұрын
Really good video. Please do another one with the heap analyzer you mentioned
@user-zq8bt6hv9k
@user-zq8bt6hv9k Жыл бұрын
Interesting, thanks for the work
@terrnnoo7007
@terrnnoo7007 Жыл бұрын
Didn't quite catch why wouldn't allocator give back 2559 dirty pages to OS if these 64 bytes are in use. Does allocator want us to free all requested memory to give those pages back or bcs we wrote data to these 10 Mb but freed only 9.9 Mb?
@masmullin
@masmullin Жыл бұрын
This is difficult to explain, sorry for the confusion. There's two types of allocation in Linux. One uses sbrk to move something called the break for the heap up and down. Think of the break like a line. In the case where you move the break up 10mb, either in one big jump, or many small jumps, then you use all of that 10mb, the you free all the memory other than the very top; the allocator cannot move the break back down because that very top is still being used. The other way to allocate is via mmap. If you use mmap by hand, you can grab a 10mb chunk of memory, use it, and the mark 9.9mb of that memory as DONT_NEED, I've not seen that sort of behaviour when an allocator uses mmap to grab memory and then give it to you via malloc/free. In the case where an allocator uses mmap, it will (hopefully) mark that 10mb chunk of memory as DONT_NEED when you are completely done with it. also, allocators try to be smart with mmap. Eg jemalloc will wait to mark an mmap as dont_need for some amount of time in case you ask for more memory.
@terrnnoo7007
@terrnnoo7007 Жыл бұрын
@@masmullin So if allocator uses sbrk syscall there is particular reason why 9.9 Mb isn't freed (bcs 64 bytes are located at top of the 9.9 Mb). But in case of mmap it seems like nothing prevents allocator from freeing 9.9 Mb if it wants so, bcs mmap doesn't increase brk segment address but instead giving us pages of memory somewhere. So is it true that 'Dirty Pages' are really possible only while using sbrk, bcs if allocator use mmap it can call free syscall on freed(by allocator API) memory pages?
Rust and RAII Memory Management - Computerphile
24:22
Computerphile
Рет қаралды 234 М.
I built my own memory profiler (in Rust, on Linux)
22:58
fasterthanlime
Рет қаралды 61 М.
From Small To Giant 0%🍫 VS 100%🍫 #katebrush #shorts #gummy
00:19
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 37 МЛН
When Zig Outshines Rust | Prime Reacts
23:31
ThePrimeTime
Рет қаралды 144 М.
Why does this Rust program leak memory?
35:24
fasterthanlime
Рет қаралды 58 М.
The Performance overhead of WASM over Native Rust
30:57
Michael Mullin
Рет қаралды 15 М.
Constructors Are Broken
18:16
Logan Smith
Рет қаралды 111 М.
Rust: The Dangers of Early Performance Optimization
36:22
Michael Mullin
Рет қаралды 7 М.
Nicholas Matsakis - Rust 2024 and beyond
33:48
Rust Nation UK
Рет қаралды 14 М.
Implement Methods on Rust Structs 🦀
27:27
Trevor Sullivan
Рет қаралды 6 М.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Ryan Fleury
Рет қаралды 50 М.
Base [4]: Memory Management
15:44
Mr. 4th Programming
Рет қаралды 14 М.