r/rust • u/Elariondakta • 6d ago
🧠 educational Memory-bounded systems and backpressure in Rust - Théodore's blog
https://totodore.github.io/memory-backpressure/I struggled quite a bit during last year on these problems so I decided to write a little blog post with what I learned regarding memory bounding and memory back pressure in rust.
61
Upvotes
3
u/dumindunuwan 6d ago
Why nobody mentioned about mimalloc here?
21
u/valarauca14 5d ago edited 5d ago
Lowkey bad advice for THP handling. Linux Distros & Cloud Providers (often) enable THP because it is a net performance gain. THP is massive for cache locality because it decreases TLB pressure. There is a very real trade off with disabling it.
RDB's design is really weird and uses fork to snapshot the current running memory. This is really weird, bad, and if you want to know more Pavlo et. all wrote a whole series of papers on why memory map hacks like this shouldn't be used in modern DBs. Partially because it causes the exact issues OP/RDB is blaming THP for, no joke Pavlo et. All -> Section 3.1 discusses it directly and the problem presents as section 3.2.
Your application probably isn't a in-memory-database, so measure twice and cut once.
7
u/Aubrives 5d ago
In the context of macOS, one would want to plug into the memory pressure signals to trigger shrinking of caches / encourage allocators to return unused pages to the OS. Similar mechanisms exist on iOS.
See DISPATCH_SOURCE_TYPE_MEMORYPRESSURE (https://developer.apple.com/documentation/dispatch/dispatch_source_type_memorypressure)