Cargo build being randomly terminated by Ubuntu for excessive memory

"cargo build --release" occasionally gets killed by Ubuntu for excessive memory consumption. This is on a non-virtual machine with 32GB of RAM, The performance graph shows only about 6BG in use at peak.

Suddenly the terminal window just closes while compiling. I have to look in syslog to see why:

Dec 18 19:34:56 user-desktop systemd-oomd[840]: Killed /user.slice/user-1001.slice/user@1001.service/app.slice/app-org.gnome.Terminal.slice/vte-spawn-dbb4a75e-031f-480d-924b-5de5af7579d2.scope due to memory pressure for /user.slice/user-1001.slice/user@1001.service being 51.07% > 50.00% for > 20s with reclaim activity
Dec 18 19:34:56 user-desktop systemd[1837]: vte-spawn-dbb4a75e-031f-480d-924b-5de5af7579d2.scope: systemd-oomd killed 12 process(es) in this unit.
Dec 18 19:34:57 user-desktop systemd[1837]: vte-spawn-dbb4a75e-031f-480d-924b-5de5af7579d2.scope: Consumed 5h 17min 34.893s CPU time.

Here's the graph of the system load. Memory in use is about 6GB of 32GB. The part in the middle of the graph where there's some compute load is the compile.

This fails about once in every 50 builds. Anyone else seeing this?

Machine is x86_64. No virtualization.

rustc 1.74.0 (79e9716c9 2023-11-13)
Ubuntu 22.04.3 LTS

systemd-oomd being overzealous on Ubuntu is something I've read about before. This is unrelated to Rust. Anyways, I can't quite find the explanation I've read somewhere a while back.. I could find e. g. this page right now systemd-oomd issues on desktop reminds me that maybe, if I recall correctly, the bug / problem here is related to swap being too full or so. Maybe only occurring with relatively small swap sizes - what's your swap size, anyways?

Then again, the page I linked says something about an alternative "memory pressure" condition (that I can't claim to really have understood), and the error message you've posted seems to relate to tbst.

Ah. Swap size is only 2GB, because, with 32GB of RAM, swap isn't necessary. But earlier today a program went into a loop and used all of memory before it aborted, which allocated some swap. That might be related.

I read the systemd-oomd issues article. That's from 2022, and it indicates that you have to use up physical memory before that triggers, which is reasonable. It also mentions that the way memory usage is measured by Ubuntu may be wrong. I will follow this up on the Ubuntu side.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.