Skip to content
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

Setting a lower RUST_MIN_STACK than DEFAULT_STACK_SIZE increases stack??? #126897

Open
biabbas opened this issue Jun 24, 2024 · 12 comments
Open

Setting a lower RUST_MIN_STACK than DEFAULT_STACK_SIZE increases stack??? #126897

biabbas opened this issue Jun 24, 2024 · 12 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@biabbas
Copy link
Contributor

biabbas commented Jun 24, 2024

While working on this issue #122357, I found that setting the RUST_MIN_STACK variable size to 7mb or more, the build is successful. But the default stack size in rust is 8mb. Why do we have to set RUST_MIN_STACK again for this to work?

Steps to create the example directory are in this link #122357 (comment)
To verify this please follow these steps.

  1. setup the example from above link.
  2. Run cargo build in the example, this time the build would fail.
  3. Export RUST_MIN_STACK=$((7*1024*1024) and run cargo build again. This time the build is successful.
@biabbas biabbas added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 24, 2024
@ChrisDenton
Copy link
Member

ChrisDenton commented Jun 24, 2024

The default stack size of new threads is 2 MiB. However, the default stack size of the main thread varies depending on the platform and possibly platform-dependent build configuration.

@workingjubilee
Copy link
Member

Rust does not override every last platform-specific behavior. To do so would likely be quite harmful.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2024
@workingjubilee
Copy link
Member

workingjubilee commented Jun 24, 2024

Actually, wait. I'm confused. For rustc, this shouldn't matter because of the DEFAULT_STACK_SIZE (not to be confused with the default stack size).

@workingjubilee
Copy link
Member

@biabbas What version of rustc did you test with?

@workingjubilee
Copy link
Member

workingjubilee commented Jun 24, 2024

No repro on x86_64-unknown-linux-gnu.

@workingjubilee workingjubilee changed the title Rust default stack size varies across compilation Large builds just-barely inside rustc's stack envelope sometimes fail Jun 24, 2024
@workingjubilee workingjubilee added S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 24, 2024
@workingjubilee
Copy link
Member

Wait, I misapplied some directions.

It... does repro? What.

@workingjubilee workingjubilee removed the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label Jun 24, 2024
@workingjubilee workingjubilee changed the title Large builds just-barely inside rustc's stack envelope sometimes fail Setting a lower RUST_MIN_STACK than DEFAULT_STACK_SIZE increases stack??? Jun 24, 2024
@biabbas
Copy link
Contributor Author

biabbas commented Jun 25, 2024

@biabbas What version of rustc did you test with?

I was able to reproduce this behavior on rust 1.75, 1.78, 1.79 stable.

@biabbas
Copy link
Contributor Author

biabbas commented Jun 25, 2024

The default stack size of new threads is 2 MiB. However, the default stack size of the main thread varies depending on the platform and possibly platform-dependent build configuration.

You are right, default stack size for new threads is 2mb. I went through the std thread code and I see that min_stack uses this RUST_MIN_STACK variable to influence the size of thread builder stack size. In the test case what stack is overflowed and why RUST_MIN_STACK workaround fixes it?

@biabbas
Copy link
Contributor Author

biabbas commented Jun 25, 2024

Actually, wait. I'm confused. For rustc, this shouldn't matter because of the DEFAULT_STACK_SIZE (not to be confused with the default stack size).

Could you please elaborate and differentiate between the two.

@workingjubilee
Copy link
Member

workingjubilee commented Jun 25, 2024

@biabbas DEFAULT_STACK_SIZE is a constant used by rustc to set the thread builder's stack amount, the "default stack size" we've mentioned in a few cases in this thread is the platform's implicit stack size for the main thread.

@biabbas
Copy link
Contributor Author

biabbas commented Jun 28, 2024

Can rustc be using parallelism( sub threads with limit around 2mb) for program compilation? In that case the error message should emit the actual stack that is overflowed. I know cargo uses parallelism for build but not sure if rustc also uses this.

I had access to reproduce and work on #113612. This example would compile with RUST_MIN_STACT set to 3mb.
Maybe the thread builder stack size is overwriting the main threads stack size, in which case it needs a fix.

@workingjubilee
Copy link
Member

Yes, we deliberately set the stack size by spawning a thread.

However, I would expect we are setting it to 8MB.

We emit a suggestion that suggests setting RUST_MIN_STACK to double the previous value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants