Bug 690 - Mono crashes when the app takes more than 4GB in memory
Summary: Mono crashes when the app takes more than 4GB in memory
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: Normal critical
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-09-09 14:55 UTC by Arsen Zahray
Modified: 2013-09-08 19:03 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Arsen Zahray 2011-09-09 14:55:46 UTC
Description of Problem:
Mono crashes every time my app takes more than 4 GB in memory.

Once the app takes 4GB in memory, following stacktrace appears:

 Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS

  at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
  at System.Text.RegularExpressions.Interpreter.GenerateMatch (System.Text.RegularExpressions.Regex) <0x001b8>
  at System.Text.RegularExpressions.Interpreter.Scan (System.Text.RegularExpressions.Regex,string,int,int) <0x00078>
  at System.Text.RegularExpressions.Match.NextMatch () <0x000e2>
  at System.Text.RegularExpressions.BaseMachine.Split (System.Text.RegularExpressions.Regex,string,int,int) <0x00099>
  at System.Text.RegularExpressions.Regex.Split (string,int,int) <0x0006c>
  at System.Text.RegularExpressions.Regex.Split (string) <0x0003a>
  at System.Text.RegularExpressions.Regex.Split (string,string,System.Text.RegularExpressions.RegexOptions) <0x0005e>
  at System.Text.RegularExpressions.Regex.Split (string,string) <0x0001b>
  at lawyerGatherBot.Merger.LawyerRepresentation..ctor (string) <0x000ec>
  at lawyerGatherBot.Program.OrgamizeRecordsByPhoneNumbers () <0x0016d>
  at lawyerGatherBot.Program.Main (string[]) <0x00010>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

        mono() [0x48f4eb]
        /lib/libpthread.so.0(+0xf8f0) [0x7f832c5ca8f0]
        /lib/libc.so.6(gsignal+0x35) [0x7f832c26ba75]
        /lib/libc.so.6(abort+0x180) [0x7f832c26f5c0]
        mono() [0x5e8684]
        mono() [0x5e4438]
        mono() [0x5e48c1]
        mono() [0x5e4aac]
        mono() [0x5e4c69]
        mono() [0x5d88d9]
        mono() [0x5dc7ee]
        mono() [0x5da819]

Debug info from gdb:

Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

Steps to reproduce the problem:
1. Create an app
2. Build create objects untill it takes more than 4GB of RAM
try a code silimar to:

Dictionary<string, List<LawyerRepresentation>> phoneNumbers = new Dictionary<string, List<LawyerRepresentation>>();
            //read and sort the data
            using (StreamReader rdr = new StreamReader(@"merger-result.csv"))
                while (true)
                    var ln = rdr.ReadLine();
                    if (ln == null)
                    LawyerRepresentation lr = new LawyerRepresentation(ln);
                    List<string> removePhones = new List<string>();
                    foreach (var item in lr.Phones)
                        if (item.Length<12)
                        string pn = item;
                        if (item.Length>12)
                            pn = item.Substring(item.Length - 12);
                        if (!phoneNumbers.ContainsKey(pn))
                            phoneNumbers[pn] = new List<LawyerRepresentation>();
                    if (removePhones.Count>0)
                        lr.Phones = lr.Phones.Except(removePhones).ToList(); 

Actual Results:
App crashes

Expected Results:
A large dictionary is allocated into memory

How often does this happen? 

Additional Information:
I'm doing this on Amazon AMI ami-4dde1d24 with 7GB of RAM, operating system is Ubuntu 10.4, with mono 2.10.5 compiled on this platform from tarball
Comment 1 Rodrigo Kumpera 2013-09-08 19:03:37 UTC
Boehm doesn't support large heaps. Please switch to sgen and 64bits mono.

Optionally, you can edit libgc source, increase those limits and recompile.