Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo test renders device unresponsive due to MSVC linker RAM usage #12916

Open
djeedai opened this issue Nov 5, 2023 · 3 comments
Open

cargo test renders device unresponsive due to MSVC linker RAM usage #12916

djeedai opened this issue Nov 5, 2023 · 3 comments
Labels
A-doctests Area: rustdoc --test C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@djeedai
Copy link

djeedai commented Nov 5, 2023

Problem

Invoking cargo t on an i7-13700K Win11 with 32GB RAM makes the whole device unresponsive.

CPU is around 20-30%, RAM climbs at 100% and is likely paging heavily, process explorer shows 1 instance of the MSVC linker (link.exe) per core (24), each consuming 1+ GB of RAM.

Steps

  1. Get a project with more doc tests than physical cores, and than GB or RAM. A good example is https://github.com/bevyengine/bevy, my own test is from https://github.com/djeedai/bevy_hanabi.
  2. Run cargo t on Windows 11 (not sure version matters; use of MSVC is required though)

Possible Solution(s)

  • Limit the number of threads used when cargo test runs rustdoc on Windows, due to the large RAM footprint of the MSVC linker (about 1 GB per test running / link.exe instance). This is likely not ideal because RAM footprint probably depends on crate(s) linked. In the example used (Bevy) the project is very large (300+ packages), so the linker very busy.
  • Allow per-project configuring in advance the number of doc tests, for example in Cargo.toml (Enable specifying --test-threads in Cargo.toml #8430)

Notes

Confirmed that cargo t -- --test-threads=8 yields a lot smoother experience, as RAM usage never goes above 60% and therefore CPU usage is much higher (almost CPU bound).

This affects only doc tests, not regular tests (which don't link I guess). Solution ideally shouldn't limit the number of parallel tests for regular tests, only limit parallel linker instances / doc tests.

Somewhat related to #8430 but for different reason.

Version

cargo 1.72.1 (103a7ff2e 2023-08-15)
release: 1.72.1
commit-hash: 103a7ff2ee7678d34f34d778614c5eb2525ae9de
commit-date: 2023-08-15
host: x86_64-pc-windows-msvc
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.1.2-DEV (sys:0.4.63+curl-8.1.2 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 Professional) [64-bit]
@djeedai djeedai added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Nov 5, 2023
@epage epage added the A-doctests Area: rustdoc --test label Nov 6, 2023
@epage
Copy link
Contributor

epage commented Nov 6, 2023

We're tracking CPU/memory pressure during compilation at #12912. doctests adds an interesting twist to this problem.

@djeedai
Copy link
Author

djeedai commented Nov 6, 2023

Thanks @epage. I'd like to highlight that the pressure of non-doc tests has never been a problem with the mentioned projects as far as I know. Doctest ones though have started to be a consistent issue locally for several months, possibly more.

@weihanglo
Copy link
Member

weihanglo commented Nov 6, 2023

Specifically to linker RAM usage, they might be attributed to these issue:

At least on Linux, the debug_pubtypes and debug_pubnames take the largest portion in a binary. Doc tests do suffer from this as well from my experience.

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: rustdoc --test C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
Status: No status
Development

No branches or pull requests

3 participants