Bill Allombert on Fri, 11 Sep 2015 21:47:14 +0200


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

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


On Fri, Sep 11, 2015 at 04:17:38PM +0200, Peter Bruin 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.

Thanks I have applied your patch (except for the last line, 
default(parisizemax) should return what the user gave).

> 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.

To be honest, I recommend against setting parisizemax to much more than 1/2 of
the physical memory of the system, because PARI needs some memory outside the
stack for various operation, and it is easy to make a mistake and have the
stack fill up quickly. So I would not expect anything sensible to occur when
setting parisizemax to 2^63.

Thanks for the fix!
Bill