-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Avoid copying some undef memory in MIR #62655
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
r? @oli-obk |
r? @RalfJung |
I think (hope, really) that @oli-obk and me will both review this.^^ Not sure why you switched us around here. I also still think it should be investigated why the test program that triggered this consumes 20GB as opposed to 2. There seems to be something deeply wrong somewhere and we shouldn't just paper over that. |
Yes, this might not fix it entirely. The resulting constant in the program is not a |
To land this we should definitely have benchmarks that it helps, at least. Otherwise it seems pointless. |
I don't think we need a benchmark. Simply having a compile-pass test with |
build-pass, you mean. :) |
I'm going to rename a few parts based on feedback above:
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I think unit tests in rustc that would fail to compile without this PR, but do compile with it totally suffice |
@bors r- retry |
That |
71b4350
to
c8c4734
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
c8c4734
to
12eb105
Compare
☔ The latest upstream changes (presumably #66225) made this pull request unmergeable. Please resolve the merge conflicts. |
@HeroicKatora I'm sorry I didn't see that this PR got updated. Can you please rebase again? Also there's two unresolved comments on the source left about updating comments to represent or explain the current situation. |
Ping from triage: |
Pinging again from triage: |
Was somewhat short on time in the last two weeks, the PR has stretched out for quite a while. I'll get to it this weekend. |
During MIR interpretation it may happen that a place containing uninitialized bytes is copied. This would read the current representation of these bytes and write it to the destination even though they must, by definition, not matter to the execution. This elides that representation change when no bytes are defined in such a copy, saving some cpu cycles. In such a case, the memory of the target allocation is not touched at all which also means that sometimes no physical page backing the memory allocation of the representation needs to be provided by the OS at all, reducing memory pressure on the system.
12eb105
to
df72632
Compare
@@ -695,6 +695,12 @@ impl<Tag, Extra> Allocation<Tag, Extra> { | |||
} | |||
} | |||
|
|||
impl AllocationDefinedness { | |||
pub fn all_bytes_undef(&self) -> bool { | |||
self.initial == false && self.ranges.len() == 1 |
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.
self.initial == false && self.ranges.len() == 1 | |
// The `ranges` are run-length encoded and of alternating definedness. | |
// So if `ranges.len() > 1` then the second block is a range of defined bytes. | |
self.initial == false && self.ranges.len() == 1 |
Ping from triage - @HeroicKatora can you address the suggestions from oli-obk? Thanks. |
I'm going to close this, I just don't have the time and the effect of this is minimal on |
Avoid memory copy logic for zsts r? @oli-obk One of the included commits is work done by @HeroicKatora in #62655
Copying memory between allocations in MIR is not required to preserve the current representation of undef bytes. When the complete source of a copy is in undef state then there are no bytes that need to be copied and the function can return nearly immediately. In some cases this completely avoids writing to the allocation's memory with should have various benefits.
This for example reduces required physical memory when interpreting
const fn
involving large uninitialized values, such asMaybeUninit::uninit()
.(*This description has been changed from the original one after parts have been integrated into #63561 *)