Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 786978 - media-video/mkvtoolnix-56.1.0 OOM during compile
Summary: media-video/mkvtoolnix-56.1.0 OOM during compile
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Media-video project
URL: https://gitlab.com/mbunkus/mkvtoolnix...
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2021-04-29 22:25 UTC by Vincent Reher
Modified: 2021-05-23 07:23 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Modified ebuild (mkvtoolnix-56.1.0-r1.ebuild,3.01 KB, text/plain)
2021-04-29 22:25 UTC, Vincent Reher
Details
Build log (media-video:mkvtoolnix-56.1.0:20210429-011531.log,131.33 KB, text/plain)
2021-04-29 22:26 UTC, Vincent Reher
Details
emerge --info for mkvtoolnix-56.1.0-r1 (mkvtoolnix-56.1.0-r1.txt,11.47 KB, text/plain)
2021-04-30 01:18 UTC, Vincent Reher
Details
emerge --info for mkvtoolnix-51.0.0 (mkvtoolnix-51.0.0.txt,11.34 KB, text/plain)
2021-04-30 01:23 UTC, Vincent Reher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Reher 2021-04-29 22:25:21 UTC
Created attachment 704115 [details]
Modified ebuild

My system ran out of memory while trying to build this package. Specifically, while compiling src/common/iso639_language_list.cpp, gcc start consuming an ever increasing amount of RAM, then swapping hell starts, and eventually the linux OOM killer terminates the compiled. See attached log for example.

I filed this bug with upstream: https://gitlab.com/mbunkus/mkvtoolnix/-/issues/3105
Apparently the problem lies with using any optimization when compiling this particular module. In fact this one should be compiled with -O0 and all of the others should be with -O3.

The attached ebuild is a slight modification of the existing one in that it replaces '--disable-optimization' with '--enable-optimization' during configuration and filters out any user-specified compiler optimization.
Comment 1 Vincent Reher 2021-04-29 22:26:30 UTC
Created attachment 704118 [details]
Build log
Comment 2 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2021-04-29 22:45:33 UTC
Please add the output of

  emerge --info mkvtoolnix

as a comment to this bug.
Comment 3 Vincent Reher 2021-04-30 01:18:32 UTC
Created attachment 704124 [details]
emerge --info for mkvtoolnix-56.1.0-r1

This is information relative to my *modified* ebuild that installed the package today.
Comment 4 Vincent Reher 2021-04-30 01:23:41 UTC
Created attachment 704127 [details]
emerge --info for mkvtoolnix-51.0.0

I don't know if this is useful or relevant, but this is information pertaining to the previous installation of mkvtoolnix in same environment on 2021-03-16
Comment 5 Ionen Wolkens gentoo-dev 2021-04-30 06:34:51 UTC
Rakefile replaces " -O\d+ " by " -O0 ". Note the spaces on both sides, and also that \d is digits-only

e.g. for iso639_language_list.cpp:
CXXFLAGS="-march=native -O2 -pipe" is replaced by -O0
CXXFLAGS="-march=native -O2" is still -O2
CXXFLAGS="-march=native -Os -pipe" still -Os
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-04-30 06:35:31 UTC
Borderline horrifying so I’ll see what Soap thinks.
Comment 7 Andrew Savchenko gentoo-dev 2021-05-22 15:26:39 UTC
Same problem with 16 GB RAM…
:sigh:
Comment 8 Andrew Savchenko gentoo-dev 2021-05-22 15:42:03 UTC
(In reply to Vincent Reher from comment #0)

> I filed this bug with upstream:
> https://gitlab.com/mbunkus/mkvtoolnix/-/issues/3105
> Apparently the problem lies with using any optimization when compiling this
> particular module. In fact this one should be compiled with -O0 and all of
> the others should be with -O3.

Why upstream is not using __attribute__((optimize(0))?
 
> The attached ebuild is a slight modification of the existing one in that it
> replaces '--disable-optimization' with '--enable-optimization' during
> configuration and filters out any user-specified compiler optimization.

This will filter-out other very useful options like -march.
Comment 9 Moritz Bunkus 2021-05-22 17:13:48 UTC
MKVToolNix author here.

What changed between versions is that the language list has grown considerably, from a couple hundred entries to over 7000. There might be some kind of exponential growth in time needed for optimizations based on the number of entries.

I'm not using __attribute__((optimize(0))) for two reasons:

1. I hadn't actually been aware that such an attribute exists until it was mentioned over on my issue tracker today.

2. It doesn't actually work that well.

With -O0 and any attributes compilation of that one file takes ~2.5 minutes (clang++; g++ is similar). Sure that's long but acceptable.

With the default -O3 and __attribute__((optnone)) for clang++ compilation took nearly 9 minutes (g++ with __attribute__((optimize(0))) took more than 20 minutes which was when I aborted the experiment). As I'm compiling this stuff all the time (and compilation of the whole application only takes 3 minutes or so due to high parallelization), such a slowdown isn't acceptable to me. Haven't looked where memory usage peaks.

If anyone can come up with a way to use the attributes and get similar compilation times as -O0, please let me know.

As for the regex replacing the optimization flags: sure, that one can be changed to work better with custom flags. How about:

(^| )-O[^ ]*

That should work with -O at the start or at least after a space and continue up but excluding to the next space (or the end of the string). It should take care of all the examples Ionen Wolkens posted and doesn't require you to run configure with "--disable-optimizations" or so. I'll commit that for the next release (not 57.0.0 which was released earlier today, though).
Comment 10 Moritz Bunkus 2021-05-22 17:48:22 UTC
I've just committed the change to Rakefile's regular expression for filtering out optimization flags: https://gitlab.com/mbunkus/mkvtoolnix/-/commit/ba6db89e24aa84316372d59e6bba4ac88145b32a

Ideally this change alone should allow compilation on Gentoo again without any other fixes.
Comment 11 Andrew Savchenko gentoo-dev 2021-05-22 18:42:22 UTC
(In reply to Moritz Bunkus from comment #10)
> I've just committed the change to Rakefile's regular expression for
> filtering out optimization flags:
> https://gitlab.com/mbunkus/mkvtoolnix/-/commit/
> ba6db89e24aa84316372d59e6bba4ac88145b32a
> 
> Ideally this change alone should allow compilation on Gentoo again without
> any other fixes.

Thank you! With this patch mkvtoolnix builds like a charm (I built current in-tree version 56.1.0 for now).

@Soap, OK to apply?
Comment 12 Andrew Savchenko gentoo-dev 2021-05-22 18:47:20 UTC
(In reply to Moritz Bunkus from comment #9)
> MKVToolNix author here.
> 
> What changed between versions is that the language list has grown
> considerably, from a couple hundred entries to over 7000. There might be
> some kind of exponential growth in time needed for optimizations based on
> the number of entries.
> 
> I'm not using __attribute__((optimize(0))) for two reasons:
> 
> 1. I hadn't actually been aware that such an attribute exists until it was
> mentioned over on my issue tracker today.
> 
> 2. It doesn't actually work that well.
> 
> With -O0 and any attributes compilation of that one file takes ~2.5 minutes
> (clang++; g++ is similar). Sure that's long but acceptable.
> 
> With the default -O3 and __attribute__((optnone)) for clang++ compilation
> took nearly 9 minutes (g++ with __attribute__((optimize(0))) took more than
> 20 minutes which was when I aborted the experiment). As I'm compiling this
> stuff all the time (and compilation of the whole application only takes 3
> minutes or so due to high parallelization), such a slowdown isn't acceptable
> to me. Haven't looked where memory usage peaks.

Very interesting information. Maybe it has something to do with implicit class members.
Comment 13 David Seifert gentoo-dev 2021-05-22 21:41:03 UTC
(In reply to Andrew Savchenko from comment #11)
> (In reply to Moritz Bunkus from comment #10)
> > I've just committed the change to Rakefile's regular expression for
> > filtering out optimization flags:
> > https://gitlab.com/mbunkus/mkvtoolnix/-/commit/
> > ba6db89e24aa84316372d59e6bba4ac88145b32a
> > 
> > Ideally this change alone should allow compilation on Gentoo again without
> > any other fixes.
> 
> Thank you! With this patch mkvtoolnix builds like a charm (I built current
> in-tree version 56.1.0 for now).
> 
> @Soap, OK to apply?

sure, apply it
Comment 14 Larry the Git Cow gentoo-dev 2021-05-23 07:23:29 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bae380256f345d9a79a0941b6259b8fb700fbf5e

commit bae380256f345d9a79a0941b6259b8fb700fbf5e
Author:     Andrew Savchenko <bircoph@gentoo.org>
AuthorDate: 2021-05-23 07:16:28 +0000
Commit:     Andrew Savchenko <bircoph@gentoo.org>
CommitDate: 2021-05-23 07:23:09 +0000

    media-video/mkvtoolnix: fix OOM during build
    
    Apply upstream patch[1] to drop iso639_language_list.cpp
    optimization level to 0 due to special nature of this source file.
    
    [1] https://gitlab.com/mbunkus/mkvtoolnix/-
    /commit/ba6db89e24aa84316372d59e6bba4ac88145b32a
    
    Closes: https://bugs.gentoo.org/786978
    Package-Manager: Portage-3.0.18, Repoman-3.0.3
    Signed-off-by: Andrew Savchenko <bircoph@gentoo.org>

 .../mkvtoolnix/files/mkvtoolnix-56.1.0-optlevel.patch     | 15 +++++++++++++++
 media-video/mkvtoolnix/mkvtoolnix-56.1.0.ebuild           |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)