-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow restricting the number of parallel linker invocations #9157
Copy link
Copy link
Open
Labels
A-jobserverArea: jobserver, concurrency, parallelismArea: jobserver, concurrency, parallelismA-linkageArea: linker issues, dylib, cdylib, shared libraries, soArea: linker issues, dylib, cdylib, shared libraries, soC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Metadata
Metadata
Assignees
Labels
A-jobserverArea: jobserver, concurrency, parallelismArea: jobserver, concurrency, parallelismA-linkageArea: linker issues, dylib, cdylib, shared libraries, soArea: linker issues, dylib, cdylib, shared libraries, soC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Type
Fields
Give feedbackNo fields configured for issues without a type.
In CI at my work, we ran into a situation where rustc would get OOM-killed while linking example binaries:
We were able to mitigate this by using a builder with more available memory, but it's unfortunate. We could dial down the parallelism of the whole build by explicitly passing
-jN, but that would make the non-linking parts of the build slower by leaving CPU cores idle.It would be ideal if we could explicitly ask cargo to lower the number of parallel linker invocations it will spawn. Compile steps are generally CPU-intensive, but linking is usually much more memory-intensive. In the extreme case, for large projects like Firefox and Chromium where the vast majority of code gets linked into a single binary, that link step far outweighs any other part of the build in terms of memory usage.
In terms of prior art, ninja has a concept of "pools" that allow expressing this sort of restriction in a more generic way:
The Ninja feature was originally motivated by Chromium builds switching to Ninja and wanting to support distributed builds, in which there might be capacity to spawn way more compile jobs in parallel since they can be run on distributed build nodes, but link jobs, needing to be run on the local machine, would want a lower limit.
If this were implemented, one could imagine a further step whereby cargo could estimate how heavy individual linker invocations are by the number of crates they link, and attempt to set a reasonable default value based on that and the amount of available system memory.