db5a2b9747
Optimizing Stacked Borrows (part 2): Shrink Item This moves protectors out of `Item`, storing them both in a global `HashSet` which contains all currently-protected tags as well as a `Vec<SbTag>` on each `Frame` so that when we return from a function we know which tags to remove from the protected set. This also bit-packs the 64-bit tag and the 2-bit permission together when they are stored in memory. This means we theoretically run out of tags sooner, but I doubt that limit will ever be hit. Together these optimizations reduce the memory footprint of Miri when executing programs which stress Stacked Borrows by ~66%. For example, running a test with isolation off which only panics currently peaks at ~19 GB, with this PR it peaks at ~6.2 GB. To-do - [x] Enforce the 62-bit limit - [x] Decide if there is a better order to pack the tag and permission in - [x] Wait for `UnsafeCell` to become infectious, or express offsets + tags in the global protector set Benchmarks before: ``` Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/backtraces/Cargo.toml Time (mean ± σ): 8.948 s ± 0.253 s [User: 8.752 s, System: 0.158 s] Range (min … max): 8.619 s … 9.279 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/mse/Cargo.toml Time (mean ± σ): 2.129 s ± 0.037 s [User: 1.849 s, System: 0.248 s] Range (min … max): 2.086 s … 2.176 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/serde1/Cargo.toml Time (mean ± σ): 3.334 s ± 0.017 s [User: 3.211 s, System: 0.103 s] Range (min … max): 3.315 s … 3.352 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/serde2/Cargo.toml Time (mean ± σ): 3.316 s ± 0.038 s [User: 3.207 s, System: 0.095 s] Range (min … max): 3.282 s … 3.375 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/unicode/Cargo.toml Time (mean ± σ): 6.391 s ± 0.323 s [User: 5.928 s, System: 0.412 s] Range (min … max): 6.090 s … 6.917 s 5 runs ``` After: ``` Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/backtraces/Cargo.toml Time (mean ± σ): 6.955 s ± 0.051 s [User: 6.807 s, System: 0.132 s] Range (min … max): 6.900 s … 7.038 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/mse/Cargo.toml Time (mean ± σ): 1.784 s ± 0.012 s [User: 1.627 s, System: 0.156 s] Range (min … max): 1.772 s … 1.797 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/serde1/Cargo.toml Time (mean ± σ): 2.505 s ± 0.095 s [User: 2.311 s, System: 0.096 s] Range (min … max): 2.405 s … 2.603 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/serde2/Cargo.toml Time (mean ± σ): 2.449 s ± 0.031 s [User: 2.306 s, System: 0.100 s] Range (min … max): 2.395 s … 2.467 s 5 runs Benchmark 1: cargo +miri miri run --manifest-path bench-cargo-miri/unicode/Cargo.toml Time (mean ± σ): 3.667 s ± 0.110 s [User: 3.498 s, System: 0.140 s] Range (min … max): 3.564 s … 3.814 s 5 runs ``` The decrease in system time is probably due to spending less time in the page fault handler.