[Mono-dev] Large object size limits

Neale Ferguson NealeFerguson at verizon.net
Fri Jun 13 21:10:47 UTC 2014


If we include limits.h it includes posix1_lim.h which defines SSIZE_MAX

Neale

On Jun 14, 2014, at 4:07 AM, Rodrigo Kumpera <kumpera at gmail.com> wrote:

> Hi Neale,
> 
> We should change from SIZE_MAX to the max value a ssize_t can hold.
> 
> --
> Rodrigo
> 
> 
> On Thu, Jun 12, 2014 at 4:38 PM, Neale Ferguson <NealeFerguson at verizon.net> wrote:
> The following program runs fine on .NET -
> 
> using System;
> using System.Collections.Generic;
> using System.Runtime;
> using System.Text;
> 
> namespace LargeObjectTest
> {
>         class Program
>         {
>                 static void Main(string[] args)
>                 {
> 
>                         IList<double> myList = new List<double>();
> 
> 
>                         long index = 1024*1024*1024;
> 
>                         Console.WriteLine("index:" + index);
> 
>                         double[] array = null;
> 
>                         Console.WriteLine("UInt32.MaxValue: "+UInt32.MaxValue);
>                         try
>                         {
>                                 array = new double[index];
> 
>                                 Console.WriteLine("doubleArray:LongLength " + array.Length * sizeof(double) + " bytes");
>                                 Console.WriteLine("sizeof(double) " + sizeof(double) + " bytes");
>                                 Console.WriteLine("index " + index);
>                                 Console.WriteLine("doubleArray:LongLength " + array.LongLength);
>                                 Console.WriteLine("doubleArray:Size " + array.LongLength * sizeof(double) * 1.0 + " Bytes");
>                         }
>                         catch (Exception e)
>                         {
>                                 Console.WriteLine("Exception:" + e);
>                                 Console.WriteLine("Exception:" + e.Message + " allocating :" + index);
>                                 Console.WriteLine("Exception:" + e.Message + " allocating :" + index * sizeof(double));
>                         }
>                 }
>         }
> }
> 
> However, on mono on Linux it results in:
> 
> index:1073741824
> UInt32.MaxValue: 4294967295
> Exception:System.OutOfMemoryException: Out of memory
>   at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
>   at LargeObjectTest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
> Exception:Out of memory allocating :1073741824
> Exception:Out of memory allocating :8589934592
> 
> If I make the following change to override the SIZE_MAX value from /usr/include/stdint.h:
> 
> --- a/mono/metadata/sgen-los.c
> +++ b/mono/metadata/sgen-los.c
> @@ -342,8 +342,12 @@ sgen_los_alloc_large_inner (MonoVTable *vtable, size_t size)
>          *
>          * size <= SIZE_MAX - (mono_pagesize () - 1) - sizeof (LOSObject)
>          */
> +#undef SIZE_MAX
> +#define SIZE_MAX (17179869184U)
>         if (size > SIZE_MAX - (mono_pagesize () - 1) - sizeof (LOSObject))
>                 return NULL;
> +#undef SIZE_MAX
> +#define SIZE_MAX (4294967295U)
> 
>  #ifdef LOS_DUMMY
>         if (!los_segment)
> 
> Then the program works as it does under .NET:
> 
> index:1073741824
> UInt32.MaxValue: 4294967295
> doubleArray:LongLength 0 bytes
> sizeof(double) 8 bytes
> index 1073741824
> doubleArray:LongLength 1073741824
> doubleArray:Size 8589934592 Bytes
> 
> The question is, what is the correct value for the comparison in lieu of SIZE_MAX? I can't determine what the max is on .NET. Another question is what type of compacting happens with large objects like this?
> 
> Neale
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140614/c911f5aa/attachment-0001.html>


More information about the Mono-devel-list mailing list