Skip to content
0:00 / 0:00

#rust#jemalloc#madvise

Why does this Rust program leak memory?

fasterthanlime

57K subscribers • 8 videos on Hallway

YouTube

Intermediate. Assumes working knowledge.

64K views3 years ago3 recommendations

Systems programmingProgramming languagesRustMemory managementOperating systems

fasterthanlime explains how memory allocators, virtual memory, RSS, and the madvise system call affect memory usage in Rust programs.

Follow me on Mastodon: hachyderm.io/@fasterthanlime Support my work: fasterthanli.me/donate Thanks to Omer from Egypt for submitting this question: github.com/mariocynicys/mem-hog Submit your own questions: fasterthanli.me/submit Making our own executable packer: fasterthanli.me/series/making-our-own-executable-packer Contents What does the program do? Memory usage, Vec, and jemalloc How does malloc even work? Visualizing allocations with memusage Where is the heap? /proc/PID/maps Virtual memory vs RSS Tracing syscalls with strace Virtual memory vs physical memory The madvise syscall What's technique 2 doing? Iterator size hints What's technique 3 doing? Mystery solved Thanks & outro

Why it's here

3 people recommend this

What people say. Recommended to help understand whether a Rust program is actually leaking memory or if the allocator is just ballooning memory.

u/Compux72in r/rust • Recommends

On “My Rust program (Well, game) is leaking memory, 4MB/s.”

You sure is a memory leak and not the allocator ballooning memory? link to this video

u/Luxalpain r/rust • Recommends

On “Is moving to rust from c# easy?”

…ds to the infamous "GC pauses" in realtime applications, but it also can have memory and performance benefits, as it can reduce memory fragmentation. In theory, a GC language could also switch out their GC with an Arc-based allocator (I believe this is how Swift works) in order to be more similar to Rust/C++/C. Here is a very cool video about it: link to this video…

u/wageofin r/kubernetes • Recommends

On “High memory usage on Java app pod”

…et pages allocated, then Java fills those pages as it sees fit. If Java decides to not fully fill a page, it is still allocated and consumed from the perspective of the OS leading to OOM kills. If you want to get a deeper understanding about how all of this works I would watch this video. This is about Rust but all of the same principles apply: link to this video…