During some build stages rust/cargo eats a lot of memory using its default settings making it more or less not viable for low/mid-rage systems.
Can we consider setting cogegen-units to 1 or add a toggle for it and also perhaps parallel compiling?
Daniel, I'm sorry, not trying to ignore you but unsure of expectations.
Seems worthwhile but someone needs to run the builds, get some
before and after numbers, research downsides if any, and then I
guess we can set codegen-units=1 if it looks ok, sure.
As for some of the comments from the review:
> [...] uses LLVM from their package tree instead of bundled, perhaps that's worth looking into?
lang/rust had an LLVM_PORT option once, but that only works if
somebody feels responsible for supporting it and fixing any regressions
that might happen. But nobody really did so we removed it.
> Unbundle libssh2?
It's bundled now I guess because we bundle libgit2 now too (because
devel/libgit2 was not updated fast enough again). Since we update
the toolchain every 6 weeks it is all probably not worth the hassle.
I mainly started to look into this as building Rust on my low-end server (specs below) failed despite having quite a bit of RAM and swap at disposal.
While this isn't ideal way of logging here's a graph of memory usage at the end of compiling rust (2 jobs) that succeeds.
This box is an old Dell T20 with a dual core Intel Pentium G3220 CPU, 12Gb of RAM and running ZFS for Poudriere but not on rootfs. It runs 12.2-RELEASE-p6 and building Rust in a 12.2 jail. It's lightly loaded and uses about 5-6Gb of RAM (incl ZFS) without any Poudriere job running. I have no specific ZFS tuning set, however from what I can tell ZFS cache seems to grow quite a bit compiling Rust.
Setting codegen reduces memory usage about 1-1.5Gb from what I can tell but memory usage is still quite high.
I also gave this a go on my RockPro64 (arm64) (4Gb of RAM) running 13-STABLE (stable/13-n245283-70a2e9a3d44), UFS only and while it took 14h+ hours (-j1) it did finish. During compiing it used about 2Gb (the job not the complete system) tops which is a lot less than what I'm seeing on my server.
I'll give this a go on another box running 13-STABLE (amd64) and see if that also consumes a lot of memory.
Thanks for replying about LLVM and libssh2, if it's too much of a hassle I understand the decision :-)
Hmm... compiling & optimizing seems to use a bit more memory, I did see a few processes use more than 2.5Gb of memory. Wired memory is a lot more though, ~4.8G and peaked at 6.7G so I guess that's due to ZFS?
A commit in branch main references this bug:
Author: Tobias Kortkamp <tobik@FreeBSD.org>
AuthorDate: 2021-06-14 18:50:33 +0000
Commit: Tobias Kortkamp <tobik@FreeBSD.org>
CommitDate: 2021-06-14 20:51:11 +0000
lang/rust-nightly: Try to reduce memory usage/pressure
Try to reduce memory usage/pressure by only using one code generation
"This flag [codegen-units] controls how many code generation units
the crate is split into. It takes an integer greater than 0.
When a crate is split into multiple codegen units, LLVM is able to
process them in parallel. Increasing parallelism may speed up
compile times, but may also produce slower code. Setting this to
1 may improve the performance of generated code, but may be slower
Suggested by: Daniel Engberg
lang/rust/Makefile | 3 +++
1 file changed, 3 insertions(+)