-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Allow green-red query coloring race #150156
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: main
Are you sure you want to change the base?
Conversation
… deps are green too
|
rustbot has assigned @petrochenkov. Use |
|
My first idea was to add a special "locked" color, but I wasn't sure what was even happening in there because coloring races currently are considered to be normal anyway. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Allow green-red query coloring race
This comment has been minimized.
This comment has been minimized.
|
I ran rustc incremental builds as described in reproduction steps section for several hours with |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (bb5a19e): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -3.5%, secondary -1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.0%, secondary 3.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 479.055s -> 481.828s (0.58%) |
| pub(super) enum DepNodeColor { | ||
| Green(DepNodeIndex), | ||
| Red, | ||
| Red(() /* DepNodeIndex */), |
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.
| Red(() /* DepNodeIndex */), | |
| Red, |
Probably left from some debugging.
| } | ||
|
|
||
| impl DepNodeColor { | ||
| pub(super) fn as_green(self) -> Option<DepNodeIndex> { |
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.
| pub(super) fn as_green(self) -> Option<DepNodeIndex> { | |
| pub(super) fn expect_green(self) -> DepNodeIndex { |
The result is always unwrapped.
|
|
||
| return dep_node_index; | ||
| } | ||
| debug_assert_eq!(DepNodeColor::Unknown, color); |
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.
| debug_assert_eq!(DepNodeColor::Unknown, color); | |
| debug_assert_eq!(color, DepNodeColor::Unknown); |
(Sorry.)
| // session, its query was re-executed, but it doesn't compute a result hash | ||
| // (i.e. it represents a `no_hash` query), so we have no way of determining | ||
| // whether or not the result was the same as before. | ||
| if !feed && !cx.is_eval_always(key.kind) { |
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.
Need a comment explaining what's going on here.
| values: IndexVec<SerializedDepNodeIndex, AtomicU32>, | ||
| } | ||
|
|
||
| // All values below `COMPRESSED_RED` are green. |
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.
Outdated comment.
|
|
||
| Err(DepNodeIndex::from_u32(green)) | ||
| } | ||
| Err(green) => Err(DepNodeIndex::from_u32(green)), |
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.
Need comments explaining when all of the cases above may happen, and what we are asserting.
| Err(red) if red & COMPRESSED_RED_BIT != 0 => { | ||
| panic!("trying to encode a dep node twice for index {prev_index:?}") | ||
| } | ||
| Err(green) => Err(DepNodeIndex::from_u32(green)), |
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.
Need comments explaining when all of the cases above may happen, and what we are asserting.
| // previous session and has been marked green | ||
| for prev_index in data.colors.values.indices() { | ||
| if data.colors.current(prev_index) == Some(dep_node_index) { | ||
| if let DepNodeColor::Green(c) = data.colors.current(prev_index) |
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.
| if let DepNodeColor::Green(c) = data.colors.current(prev_index) | |
| if data.colors.current(prev_index) == DepNodeColor::Green(dep_node_index) { |
Or remove several derived impls on DepNodeColor as unnecessary.
|
|
||
| if is_green { | ||
| // Use `try_mark_green` to avoid racing when `send_promoted` is called concurrently | ||
| // on the same index. |
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.
Need to keep a comment similar to this one for both green and red cases.
| assert_eq!(index & COMPRESSED_RED_BIT, 0); | ||
| let green = index; | ||
|
|
||
| match self.values[prev_index].compare_exchange(COMPRESSED_UNKNOWN, green, Release, Acquire) |
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.
Perhaps just use SeqCst everywhere until the parallel frontend is stabilized?
Or add comments explaining the orderings, although I'm not sure who exactly they will be supposed to convince.
|
As usual, it would be nice to split the work into a few parts (especially given the perf regressions):
But it may be better to wait for a high level design review from Zoxc or cjgillot before doing that. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
Fixes #150018
Fixes #142778
Fixes #141540
This PR allows parallel front-end's green-red node coloring processes in the query dep graph to race. Recall that whenever one thread tries to mark query node green and then fails to reconstruct a subquery's key to force it, parent query is tried to be forced or executed too. The subquery could be marked green by the thread during execution the parent query because key is now present. Other thread during this process is able to mark green parent query itself. And so after some time the first thread finishes the execution and finds in its place a green node. This is bad for
no_hashqueries since those are conservatively presumed to be red but actually queries must be deterministic anyway and sono_hashnodes could be colored green if its deps are green too after its execution finishes. As such we can consider green color to be "stronger" that the red color and thus former would replace the latter.TODO: update rustc-dev-guide query docs and rustc comments on
no_hashmodifierI have left some refactor-ish changes I did during my dirty debugging. Let me know if you would want those to be redone or removed.
Steps to reproduce
Quote from #150018, more details there: