News for hackers. Stuff that matters.
Re:Dealing with Out-of-Memory Conditions in Rust by wyldfire on Saturday August 14, 2021 @11:23AM (#28181355)
You can probably use a pool allocator that won't go back to the OS for more when it's exhausted.

I wouldn't be surprised if the popular allocators - jemalloc/tcmalloc/scudo or even the defaults in glibc/musl support a setting like this.

Re:Dealing with Out-of-Memory Conditions in Rust by remram on Saturday August 14, 2021 @02:10PM (#28182762)
I suppose I could use a custom allocator that calls mlock() on each page. I will look whether the ones you mention have Rust integrations and whether they expose a setting like that.
Re:Dealing with Out-of-Memory Conditions in Rust by eqvinox on Saturday August 14, 2021 @03:22PM (#28183256)
I understood wyldfire's post to mean counting & imposing your own artificial memory limit, no mlock involved. But I wouldn't know how to pick that limit :/.
Re:Dealing with Out-of-Memory Conditions in Rust by remram on Saturday August 14, 2021 @08:12PM (#28185083)
Oh I see. Well I'm not trying to add a limit to my RSS, I just want to be notified when allocation fail in my process on my machine where overcommit is enabled.

Maybe what I'm asking for makes no sense though, because even if my process handles out of memory errors gracefully, it might still get OOM-killed when another process allocates some more.

Re:Dealing with Out-of-Memory Conditions in Rust by wyldfire on Saturday August 14, 2021 @06:30PM (#28184492)
Yes that is what I meant. And it would avoid the latency hit of a system call to satisfy an allocation. However doing an mlock would avoid the latency hit of paging, so that's good too.