Stream: t-compiler/help

Topic: OOM building rustc_middle


Josh Triplett (Jun 14 2020 at 00:10, on Zulip):

I'm trying to build the compiler, and I'm repeatedly finding that I run out of memory compiling rustc_middle.

Josh Triplett (Jun 14 2020 at 00:11, on Zulip):

I initially thought it might be because my config.toml set parallel-compiler = true and codegen-units = 0, but I've since reverted both of those settings, and I still haven't managed to successfully build rustc_middle without having rustc killed by the OOM killer.

Josh Triplett (Jun 14 2020 at 00:12, on Zulip):

(I have 8GB of RAM.)

Josh Triplett (Jun 14 2020 at 00:12, on Zulip):

I would appreciate some help trying to figure out if I've done something wrong here.

nagisa (Jun 14 2020 at 00:23, on Zulip):

I recall having had trouble building rustc with 8G of memory at about the time 2018 edition was being cooked. Given that the compiler only ever gets more complex (and LLVM ever so slightly more quadratic), I can see it just genuinely not fitting.

nagisa (Jun 14 2020 at 00:24, on Zulip):

Though there are a couple of things you can try: a clean checkout and just x.py build without even creating a config.toml (so the defaults are used) is one.

Josh Triplett (Jun 14 2020 at 00:25, on Zulip):

I'll give that a try, just to make sure.

Josh Triplett (Jun 14 2020 at 00:26, on Zulip):

I've been using ./x.py build -i --stage 1 src/libstd. Is that likely to be a problem?

nagisa (Jun 14 2020 at 00:27, on Zulip):

I would try without -i, given that it is a scratch build anyway.

Josh Triplett (Jun 14 2020 at 00:29, on Zulip):

Already kicked off a build with -i and no config.toml, but if that fails too then I'll try without.

Josh Triplett (Jun 14 2020 at 00:38, on Zulip):

Related question: is there any option in the compiler to report a "high water mark" of total memory usage, from the allocator?

Josh Triplett (Jun 14 2020 at 00:39, on Zulip):

Would be useful for memory usage profiling and optimization.

Josh Triplett (Jun 14 2020 at 00:45, on Zulip):

Well, it's making it further, but still coming very close to OOM.

Josh Triplett (Jun 14 2020 at 00:48, on Zulip):

...and there it went. Killed after 13 minutes of CPU time.

Josh Triplett (Jun 14 2020 at 00:49, on Zulip):

Trying again with ./x.py clean and then just ./x.py build.

Josh Triplett (Jun 14 2020 at 01:03, on Zulip):

Too early to tell, but compiling rustc_middle seems to be using drastically less memory without -i.

nagisa (Jun 14 2020 at 01:04, on Zulip):

I don’t believe rustc or x.py has an option for high watermark, but running code under a memory profiler such as massif would give that information.

nagisa (Jun 14 2020 at 01:05, on Zulip):

(genuinely not sure if its even feasible to get x.py use massif, @Nicholas Nethercote would know better)

Josh Triplett (Jun 14 2020 at 01:10, on Zulip):

Looks like that did it. Incremental compilation massively increases memory usage.

Josh Triplett (Jun 14 2020 at 01:23, on Zulip):

https://github.com/rust-lang/rust/issues/73337

marmeladema (Jun 14 2020 at 11:41, on Zulip):

I just verified and locally building rustc can take up to 10GB

marmeladema (Jun 14 2020 at 11:43, on Zulip):

Even more in fact

Jake Goulding (Jun 14 2020 at 14:37, on Zulip):

I can say it works on my laptop with 32 GB :-)

Josh Triplett (Jun 14 2020 at 20:21, on Zulip):

I've been able to successfully build it with 8GB, but it takes some care, and that's unfortunate.

Josh Triplett (Jun 14 2020 at 20:22, on Zulip):

Once I finish the project I'm working on, I may try doing some memory profiling and see if I can reduce peak memory consumption enough to make it fit more comfortably, and support incremental builds.

Josh Triplett (Jun 14 2020 at 20:23, on Zulip):

(Also, I managed to get incremental builds working by freeing up a little more memory, doing the build once, and now as long as I don't touch anything that goes into rustc_middle I can keep doing incremental builds. But that's not ideal either.)

Camelid (Jun 14 2020 at 20:43, on Zulip):

Maybe splitting up rustc_middle into separate crates would solve the problem? Obviously a huge undertaking though

Camelid (Jun 14 2020 at 20:44, on Zulip):

What's the difference between rustc_hir and rustc_middle::hir?

Josh Triplett (Jun 14 2020 at 20:45, on Zulip):

@Camelid As I understand it, that's been a desirable goal for a long time, but that's separate from incremental compilation taking up an excessive amount of memory.

Camelid (Jun 14 2020 at 20:45, on Zulip):

I guess it would just fix the symptom of the problem rather than the problem itself

mark-i-m (Jun 15 2020 at 23:35, on Zulip):

I usually add some swap space so I don't oom, but yeah this regularly happens to me... it's one of the reasons I try to use CI to test

mark-i-m (Jun 15 2020 at 23:36, on Zulip):

The other thing is that if there are multiple jobs running it's worse

Nicholas Nethercote (Jun 15 2020 at 23:51, on Zulip):

I've never done it myself. I'm sure it's possible in some fashion, but it might require modifying x.py.

eddyb (Jul 16 2020 at 12:56, on Zulip):

@Camelid the reason rustc_hir even exists is part of the start of that process

eddyb (Jul 16 2020 at 12:56, on Zulip):

rustc_middle is still where everything came from but I'm not sure who is still working on trying to break it up

eddyb (Jul 16 2020 at 12:57, on Zulip):

some of the approaches are less great than others, there are nice ways and there are hacks that involve redirecting stuff through e.g. fn pointers in global variables etc.

Camelid (Jul 16 2020 at 16:30, on Zulip):

Yeah, breaking this stuff up looks really hard!

Camelid (Jul 16 2020 at 16:31, on Zulip):

Thanks for the background information by the way :)

Last update: Sep 27 2020 at 13:00UTC