Skip to content

rustc hangs after ICEing due to memory limit #110771

Closed
@matthiaskrgr

Description

@matthiaskrgr

I use prlimit to limit rustcs memory usage and max runtime per thread (like a light sandboxing basically) and I have a giant
files.par_iter().for_each(|file| rustc_flags.iter(|flag| exec( prlimit_run rustc flag file.rs))).collect::vec<ICE>(); loop

I run prlimit --noheadings --as=3076000000 --cpu=30 rustc file flags, so a rustc process is limited to roughly 3 gb of ram and 30 seconds of cpu time.

I noticed that after 39cf520 #109507 (I bisected this), my rayon loop would sometimes get stuck randomly.
It was very weird because there was no cpu load, just as if someone had temporarily suspended one of the rayon threads and now we'd wait for it/them to finish indefinitely.

I can reproduce the problem tests/ui/limits/huge-struct.rs for example:

prlimit --noheadings --as=3076000000 --cpu=30 /home/matthias/.rustup/toolchains/master/bin/rustc /tmp/IM/huge-struct.rs -Zdump-mir-dir=/tmp/icemaker_global_tempdir.lyoD6fyhTfAh/rustc_testrunner_tmpdir.VNlnLWzycl69 -Zno-codegen -Zunstable-options -Zvalidate-mir -Zverify-llvm-ir=yes -Zincremental-verify-ich=yes -Zmir-opt-level=0 -Zmir-opt-level=1 -Zmir-opt-level=2 -Zmir-opt-level=3 -Zmir-opt-level=5 -Zunsound-mir-opts -Zdump-mir=all --emit=mir -Zprint-mono-items=eager -Zpolymorphize=on -Zalways-encode-mir -Zdrop-tracking -Zdrop-tracking-mir=yes -Zverbose -Zextra-const-ub-checks --edition=2018 -Ztranslate-lang=en_US -Zprint-type-sizes -Zmaximal-hir-to-mir-coverage -Zstrict-init-checks=yes '-Zcrate-attr=feature(return_type_notation)' '-Zcrate-attr=feature(async_fn_in_trait)' '-Zcrate-attr=feature(impl_trait_in_assoc_type)' '-Zcrate-attr=feature(transmute_generic_consts)' '-Zcrate-attr=feature(fn_ptr_trait)'

This causes rustc to be killed by prlimit because it would hit the memory limit, sometimes its backtrace is much shorter than usual

thread 'rustc' panicked at 'memory allocation of 671088640 bytes failed', library/alloc/src/alloc.rs:412:17
stack backtrace:
   0:     0x7fb16cf68f33 - std::backtrace_rs::backtrace::libunwind::trace::h93382db32298e592
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb16cf68f33 - std::backtrace_rs::backtrace::trace_unsynchronized::h077b1367e10a1417
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb16cf68f33 - std::sys_common::backtrace::_print_fmt::h68f17e98ca35b7bf
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fb16cf68f33 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h341120b670d06b15
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fb16cfc9d4f - core::fmt::write::ha614952dcf5c10f0
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/core/src/fmt/mod.rs:1247:17
   5:     0x7fb16cf5bf61 - std::io::Write::write_fmt::h10934ba4b215c50c
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/io/mod.rs:1712:15
   6:     0x7fb16cf68d45 - std::sys_common::backtrace::_print::heb0370ce5b64b518
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fb16cf68d45 - std::sys_common::backtrace::print::h98331c1359b10e7b
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fb16cf6b84f - std::panicking::default_hook::{{closure}}::h5b08409ff035083a
   9:     0x7fb16cf6b507 - std::panicking::default_hook::hfc3c525b7b9bf324
                               at /rustc/64bcb326516ef7490db46de88b87a4c0990097fe/library/std/src/panicking.rs:293:9
thread 'rustc' panicked at 'memory allocation of 6291456 bytes failed', library/alloc/src/alloc.rs:412:17

and my console would not be freed, so there is still something running.
You may need to run this a couple of times to hit the hang.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions