Don't commit thread stack on Windows #52847
Merged
Conversation
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
|
I have verified locally with the following program: use std::thread;
use std::time::Duration;
fn main() {
let threads: Vec<_> = (0..10).map(|_| {
thread::Builder::new()
.stack_size(100 * 1024 * 1024)
.spawn(|| {
thread::sleep(Duration::from_secs(3600));
}).unwrap()
}).collect();
for thread in threads {
thread.join().unwrap();
}
}It normally commits ~1GB memory, while building with a toolchain with this change, it only commits ~1MB. |
|
It looks like adding this flag is a pretty unambiguously the right thing to do: https://bugs.chromium.org/p/webrtc/issues/detail?id=2902 cc @alexcrichton LGTY? |
|
@bors: r+ This is an awesome find! Sounds like a great idea to me |
|
|
bors
added a commit
that referenced
this pull request
Aug 2, 2018
Don't commit thread stack on Windows On Windows, there is a system level resource limitation called commit limit, which is roughly the sum of physical memory + paging files[1]. `CreateThread` by default commits the stack size[2], which unnecessarily takes such resource from the shared limit. This PR changes it to only reserve the stack size rather than commit it. Reserved memory would only take the address space of the current process until it's actually accessed. This should make the behavior on Windows match other platforms, and is also a pretty standard practice on Windows nowadays. [1] https://blogs.technet.microsoft.com/markrussinovich/2008/11/17/pushing-the-limits-of-windows-virtual-memory/ [2] https://docs.microsoft.com/zh-cn/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread
|
|
moz-v2v-gh
pushed a commit
to mozilla/gecko-dev
that referenced
this pull request
Oct 4, 2018
This updates our windows builders to use a version of rustc that includes rust-lang/rust#52847 We're not commiting to letting this change ride the trains at this time. Differential Revision: https://phabricator.services.mozilla.com/D7663 --HG-- extra : moz-landing-system : lando
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-wordified-and-comments-removed
that referenced
this pull request
Oct 3, 2019
This updates our windows builders to use a version of rustc that includes rust-lang/rust#52847 We're not commiting to letting this change ride the trains at this time. Differential Revision: https://phabricator.services.mozilla.com/D7663 UltraBlame original commit: 556b2f4cd653aa7642956ba66e60839b4ea9f474
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-comments-removed
that referenced
this pull request
Oct 3, 2019
This updates our windows builders to use a version of rustc that includes rust-lang/rust#52847 We're not commiting to letting this change ride the trains at this time. Differential Revision: https://phabricator.services.mozilla.com/D7663 UltraBlame original commit: 556b2f4cd653aa7642956ba66e60839b4ea9f474
gecko-dev-updater
pushed a commit
to marco-c/gecko-dev-wordified
that referenced
this pull request
Oct 3, 2019
This updates our windows builders to use a version of rustc that includes rust-lang/rust#52847 We're not commiting to letting this change ride the trains at this time. Differential Revision: https://phabricator.services.mozilla.com/D7663 UltraBlame original commit: 556b2f4cd653aa7642956ba66e60839b4ea9f474
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
On Windows, there is a system level resource limitation called commit limit, which is roughly the sum of physical memory + paging files[1].
CreateThreadby default commits the stack size[2], which unnecessarily takes such resource from the shared limit.This PR changes it to only reserve the stack size rather than commit it. Reserved memory would only take the address space of the current process until it's actually accessed.
This should make the behavior on Windows match other platforms, and is also a pretty standard practice on Windows nowadays.
[1] https://blogs.technet.microsoft.com/markrussinovich/2008/11/17/pushing-the-limits-of-windows-virtual-memory/
[2] https://docs.microsoft.com/zh-cn/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread