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

Small testcase uses extreme amount of memory if compiled with -g and -mrelocation-model static #19405

Closed
DimitryAndric opened this issue Mar 3, 2014 · 3 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category

Comments

@DimitryAndric
Copy link
Collaborator

Bugzilla Link 19031
Resolution FIXED
Resolved on Nov 12, 2014 13:55
Version 3.4
OS All
Attachments Small testcase using way too much memory for its size
CC @adrian-prantl,@dwblaikie,@echristo,@fredriss

Extended Description

A post on the FreeBSD toolchain mailing list showed a clang crash due to OOM:
http://lists.freebsd.org/pipermail/freebsd-toolchain/2014-February/001125.html

the log of the build is here (crash is at the end):
http://beefy2.isc.freebsd.org/bulk/head-amd64-default/2014-02-28_01h43m56s/logs/arx-libertatis-1.0.3_2.log

The OP notes an RSS of 15GB. I did some creduce'ing on his sample files, using clang trunk r202496, and ended up with the attached sample program, just ~100 lines of code. If you compile this with just -O2, it is very fast to compile, and uses little memory:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelocation-model static -O2 too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
0.04 real 0.02 user 0.00 sys
19020 maximum resident set size
42992 average shared memory size
101 average unshared data size
298 average unshared stack size
1057 page reclaims
0 page faults
0 swaps
0 block input operations
1 block output operations
20 messages sent
0 messages received
0 signals received
22 voluntary context switches
0 involuntary context switches

if you add -g, though, it suddenly balloons to ~2.5 GiB! E.g.:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelocation-model static -O2 -g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
7.87 real 4.26 user 3.53 sys
2661660 maximum resident set size
32178 average shared memory size
75 average unshared data size
255 average unshared stack size
1069959 page reclaims
0 page faults
0 swaps
0 block input operations
1 block output operations
27 messages sent
0 messages received
0 signals received
30 voluntary context switches
167 involuntary context switches

I know generating debug information always uses more memory, but this is a little bit ridiculous. :-)

Also interesting is that removing the -mrelocation-model static helps:

$ /usr/bin/time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -O2 -g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
0.07 real 0.01 user 0.03 sys
19476 maximum resident set size
19346 average shared memory size
45 average unshared data size
153 average unshared stack size
1156 page reclaims
0 page faults
0 swaps
0 block input operations
1 block output operations
36 messages sent
0 messages received
0 signals received
38 voluntary context switches
0 involuntary context switches

So this seems to be some sort of bad interaction between the static relocation model and debug information generation?

When building the original testcase from the mailing list, this is all even worse, and it blows up my testing VM before it can compile, having used up at least 8GB resident set size. Similarly to the minimized testcase, removing -mrelocation-model static allows it to compile, within about 3.5 seconds, and just 91 MiB of RSS.

I can also reproduce these results on Linux, btw, so it is not specifically FreeBSD-related.

@echristo
Copy link
Contributor

echristo commented Mar 3, 2014

It's a problem with resolving all of the dbg_value instructions I believe.

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 25, 2014

I'd allow myself to rise its priority. This bug affects much software and will probably block FreeBSD 11 may its release happen soon enough.

@DimitryAndric
Copy link
Collaborator Author

Fixed by r221709, similar to bug 20893.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants