Skip to content

miri: optimize zeroed alloc#136035

Merged
bors merged 1 commit into
rust-lang:masterfrom
SpecificProtagonist:miri-zeroed-alloc
Jan 30, 2025
Merged

miri: optimize zeroed alloc#136035
bors merged 1 commit into
rust-lang:masterfrom
SpecificProtagonist:miri-zeroed-alloc

Conversation

@SpecificProtagonist

@SpecificProtagonist SpecificProtagonist commented Jan 25, 2025

Copy link
Copy Markdown
Contributor

When allocating zero-initialized memory in MIR interpretation, rustc allocates zeroed memory, marks it as initialized and then re-zeroes it. Remove the last step.

I don't expect this to have much of an effect on performance normally, but in my case in which I'm creating a large allocation via mmap it gets in the way.

@rustbot

rustbot commented Jan 25, 2025

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 25, 2025
@rustbot

rustbot commented Jan 25, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @rust-lang/wg-const-eval

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@jieyouxu

Copy link
Copy Markdown
Member

r? miri

@SpecificProtagonist

Copy link
Copy Markdown
Contributor Author

Sorry, I'm not sure how I closed this – misclick?

@Kobzol

Kobzol commented Jan 25, 2025

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 25, 2025
@bors

bors commented Jan 25, 2025

Copy link
Copy Markdown
Collaborator

⌛ Trying commit bd28faf with merge 837b710...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2025
…c, r=<try>

miri: optimize zeroed alloc

When allocating zero-initialized memory in MIR interpretation, rustc allocates zeroed memory, marks it as initialized and then re-zeroes it. Remove the last step.

I don't expect this to have much of an effect on performance normally, but in my case in which I'm creating a large allocation via mmap miri is unusable without this.

There's probably a better way – with less code duplication – to implement this. Maybe adding a zero_init flag to the relevant methods, but then `Allocation::uninit` & co need a new name :)
@bors

bors commented Jan 25, 2025

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 837b710 (837b710e5dd54b53b888f1ab109a3b93efc9a144)

@rust-timer

This comment has been minimized.

@oli-obk

oli-obk commented Jan 25, 2025

Copy link
Copy Markdown
Contributor

This is not gonna show up in perf. No code path outside miri is changed

@RalfJung

Copy link
Copy Markdown
Member

We should definitely explore ways to do this with less code duplication. :)
Adding a flag sounds like a good idea. The name of the method could just be Allocation::new etc?

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (837b710): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.2%, 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 2
Improvements ✅
(primary)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 1

Cycles

Results (primary -1.6%, secondary -0.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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-1.6% [-1.6%, -1.6%] 1
Improvements ✅
(secondary)
-1.6% [-1.6%, -1.6%] 1
All ❌✅ (primary) -1.6% [-1.6%, -1.6%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 771.261s -> 771.165s (-0.01%)
Artifact size: 325.82 MiB -> 325.82 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 25, 2025
@SpecificProtagonist

Copy link
Copy Markdown
Contributor Author

Adding a flag sounds like a good idea. The name of the method could just be Allocation::new etc?

Changed 👍

Comment thread compiler/rustc_const_eval/src/interpret/memory.rs Outdated
Comment thread compiler/rustc_middle/src/mir/interpret/allocation.rs Outdated
Comment thread compiler/rustc_const_eval/src/interpret/memory.rs Outdated
new_size: Size,
new_align: Align,
kind: MemoryKind<M::MemoryKind>,
init: AllocInit,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to explain in a doc comment for the fn that this only refers to the new, grown part of the alloc; the carried-over part is as (un)initialized as the old allocation.

@oli-obk

oli-obk commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

Please squash the commits once the final doc comment has been added

Co-authored-by: Ralf Jung <post@ralfj.de>
@oli-obk

oli-obk commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jan 28, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit eee9df4 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2025
@RalfJung

RalfJung commented Jan 28, 2025 via email

Copy link
Copy Markdown
Member

@bors

bors commented Jan 30, 2025

Copy link
Copy Markdown
Collaborator

⌛ Testing commit eee9df4 with merge 5e55679...

@bors

bors commented Jan 30, 2025

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 5e55679 to master...

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5e55679): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.6%, secondary 2.9%)

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.

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

Cycles

Results (secondary 0.0%)

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 775.772s -> 775.404s (-0.05%)
Artifact size: 328.49 MiB -> 328.40 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants