-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
OOM (huge memory usage) during release compilation with include_str of 100MB #70035
Comments
Automated testing:
run_test() {
echo -n "Testing $1 ... "
file="$(mktemp)"
outfile="$(mktemp)"
python -c "print($1, end='')" > "$file"
echo -n "file=$(numfmt --to=iec-i --suffix=B $(stat --printf="%s" "$file")) ... "
kb="$(/usr/bin/time -v rustc -A warnings -O -o "$outfile" /dev/stdin <<EOT 2>&1 | grep 'Maximum resident set size' | cut -d ':' -f 2
use std::collections::HashMap;
static TESTDATA: &str = include_str!("$file");
fn parse_testdata() -> $outtype {
let mut map = Default::default();
for line in TESTDATA.lines() {
}
map
}
pub fn do_stuff() {
let (tx, _) = std::sync::mpsc::channel();
let testdata = parse_testdata();
tx.send(vec![0]).unwrap();
}
fn main() {
do_stuff();
}
EOT
)"
echo "ram=$(numfmt --to=iec-i --suffix=B --from-unit 1024 $kb)"
rm "$file" "$outfile"
}
run_all() {
echo "Running $outtype tests"
run_test "'foo bar baz qux 1337 42\n' * 1_000_000"
run_test "'foo bar baz qux 1337 42 ' * 1_000_000"
run_test "'a' * 25*1024*1024"
run_test "'a' * 10*1024*1024"
run_test "'a' * 1*1024*1024"
echo
}
outtype="HashMap<(), ()>" run_all
outtype="Vec<()>" run_all
rustc --version |
Duplicate of #52380 |
I'm not sure, if #52380 is the same bug. Reproducing the case in #52380 with the 100MB file only results in "only" 670MB RAM being used ("for comparison, include_str just with a hello-world requires 670MB"). Compiling a plain hello world takes 115MB of RAM. While this means that including a file increases the RAM usage by roughly 5 times that file's size, it's nowhere near the factor of 160 times in my example. |
I'm pretty sure they're caused by the same thing though. This one does look like a pretty hefty regression though, so reopening. |
@rustbot ping cleanup, would be nice to find why it regressed so bad between 1.40 and 1.41. |
@rustbot ping cleanup |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
Running This is the slightly cleaned up output using the script from @main--
used command for reference:
|
When compiling a project of mine, my PC with 32GB of RAM went OOM. I reduced the problem to the following code:
Compiling this code with
/usr/bin/time -v cargo build --release
shows a maximum resident RAM usage of 16GB if testdata is generated withpython -c "print('foo bar baz qux 1337 42\n' * 4_500_000)" > testdata
(103MB). In debug mode, only 1.3GB RAM are used. It doesn't matter if edition is 2018 or not.Here are some different testdata sizes with their compilation memory usage:
'foo bar baz qux 1337 42\n' * 4_500_000
'foo bar baz qux 1337 42 ' * 4_500_000
'a' * 100*1024*1024
'a' * 80*1024*1024
'a' * 50*1024*1024
'a' * 25*1024*1024
'a' * 10*1024*1024
'a' * 1*1024*1024
If anything in the code is changed, the problem gets slightly better. Here is the RAM usage after some small changes for 100MB (for comparison,
include_str
just with a hello-world requires 670MB):Vec
instead of theHashMap
: 2.5GBparse_testdata
function: 6GBparse_testdata
function manually: 6GBparse_testdata
not return anything and remove the HashMap from the function: 2.5GB()
instead ofvec![0]
: 6GBdo_stuff
: 672MBMeta
uname -a
:Linux 5.5.4-arch1-1-vfio #1 SMP PREEMPT Wed, 19 Feb 2020 15:49:02 +0000 x86_64 GNU/Linux
(Archlinux)Tested on (always testing with 100MB):
rustc 1.42.0 (b8cedc004 2020-03-09)
: 16GBrustc 1.43.0-nightly (45ebd5808 2020-03-15)
: 16GBrustc 1.41.1 (f3e1a954d 2020-02-24)
: 16GBrustc 1.41.0 (5e1a79984 2020-01-27)
: 16GBrustc 1.40.0 (73528e339 2019-12-16)
: 2.5GBrustc 1.39.0 (4560ea788 2019-11-04)
: 2.5GBrustc 1.38.0 (625451e37 2019-09-23)
: 6GBrustc 1.35.0 (3c235d560 2019-05-20)
: 6GBrustc 1.34.0 (91856ed52 2019-04-10)
: 6GBrustc 1.32.0 (9fda7c223 2019-01-16)
: 8GBrustc 1.30.0 (da5f414c2 2018-10-24)
: 5GBThe text was updated successfully, but these errors were encountered: