Peter Bruin on Fri, 11 Sep 2015 17:15:01 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Trying to allocate too much memory is not handled gracefully


PS: it might have been better to submit this as a bug report...


Peter Bruin <P.J.Bruin@math.leidenuniv.nl> wrote:

> Bonjour,
>
> When one tries to allocate an impossible amount of memory using
> allocatemem() or default(parisizemax), GP does not always handle this
> gracefully.
>
> 1) allocatemem(s) causes GP to crash for values of s >= 2^63 (on a
>    64-bit system, with parisizemax set to 0):
>
> gp> allocatemem(2^63)
>   ***   Warning: not enough memory, new stack 4611686018427387904
>   ***   Warning: not enough memory, new stack 2305843009213693952
>   .........
>   ***   Warning: not enough memory, new stack 140737488355328
>   ***   Warning: not enough memory, new stack 70368744177664
>   ***   Warning: new stack size = 9223372036854775808 (8796093022208.000 Mbytes).
> Segmentation fault
>
> This is due to a "minss" that should be a "minuu".  While debugging
> this, I noticed in addition that when the requested size s needs to be
> halved, it may no longer be aligned as it should.  Finally, when s is
> extremely close to 2^64, it is not halved but set to the minimum
> possible stack size due to an overflow.
>
> 2) default(parisizemax, s) prints the requested value s instead of the
>    value that was actually allocated:
>
> gp> default(parisizemax,2^63-1)  \\ maximum value of this default
>   ***   Warning: not enough memory, new stack 4611686018427387904
>   ***   Warning: not enough memory, new stack 2305843009213693952
>   .........
>   ***   Warning: not enough memory, new stack 140737488355328
>   ***   Warning: not enough memory, new stack 70368744177664
>   ***   Warning: new maximum stack size = 9223372036854775807 (8796093022208.000 Mbytes).
>
> The attached patch is one possible way to fix these bugs.  It fixes the
> output of default(parisizemax), and it seems to make allocatemem(s) work
> as expected for all s <= 2^64 - 1.
>
> A somewhat related problem is that allocatemem(s) causes GP to crash
> when s is very small, but I have not looked into this.
>
> Thanks,
>
> Peter