-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a jobserver proxy to ensure at least one token is always held #140145
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
base: master
Are you sure you want to change the base?
Conversation
r? @SparrowLii |
Thanks! |
This comment has been minimized.
This comment has been minimized.
Add a jobserver proxy to ensure at least one token is always held This adds a jobserver proxy to ensure at least one token is always held by `rustc`. Currently with `-Z threads` `rustc` can temporarily give up all its tokens, causing `cargo` to spawn additional `rustc` instances beyond the job limit. The current behavior causes an issue with `cargo fix` which has a global lock preventing concurrent `rustc` instances, but it also holds a jobserver token, causing a deadlock when `rustc` gives up its token. That is fixed by this PR. Fixes rust-lang#133873 and rust-lang#140093.
⌛ Trying commit 141055f with merge c4cd906f6dc68c4343777d06a86285dbccb53e58... |
self.wake_needer.notify_one(); | ||
} else { | ||
drop(data); | ||
self.client.release_raw().ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a comment to explain that another thread was released so we don't need the new thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow your comment here.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
cg_clif has https://github.com/rust-lang/rustc_codegen_cranelift/blob/master/src/concurrency_limiter.rs which I think does something similar to this PR. |
@bjorn3 What's the purpose of |
Finished benchmarking commit (c4cd906): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -0.7%, secondary -2.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -0.5%, secondary -2.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 775.257s -> 775.095s (-0.02%) |
It is responsible for requesting jobserver tokens and ensuring that the implicit token isn't returned to the jobserver. It also caches tokens that are expected to be used soon (it gets the total amount of cgus and only returns tokens if the amount of remaining cgus is less than the amount of tokens the compilation session has claimed in total). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I changed the code to use the jobserver's helper thread to help deal with a race which could leak a jobserver token when exiting the process. |
This adds a jobserver proxy to ensure at least one token is always held by
rustc
. Currently with-Z threads
rustc
can temporarily give up all its tokens, causingcargo
to spawn additionalrustc
instances beyond the job limit.The current behavior causes an issue with
cargo fix
which has a global lock preventing concurrentrustc
instances, but it also holds a jobserver token, causing a deadlock whenrustc
gives up its token. That is fixed by this PR.Fixes #133873 and #140093.