Bill Allombert on Mon, 13 Nov 2000 20:03:16 +0100 (MET)

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

Re: *** the PARI stack overflows !!!

>If there is no serious shortage of swap space, you may shamelessly
>run gp with something like -s 50000000 .  This will reserve that
>many bytes of virtual memory  (and thus block that much swap space
>from being used by other processes),  but it will not take up any
>physical RAM unless and until it actually needs it.  (NB this state-
>ment is Solaris-specific;  on other platforms your mileage may vary.
>Contact me directly via my work address in the Reply-To if you have
>Solaris-specific questions arising from this.)

Under Linux things are a little different.

You may allocate as much memory as total of real memory(swap+RAM) minus
the amount of allocated memory.
For example on my machine with 64Mb+128Mb swap I can launch 3 gp -s100M

At this time the memory is not truly allocated. A certain number of
virtual memory pages (a page is typically 4kb ) are created and link
to a zero page with the flag "copy on write". No memory is used until
you write on the page.  Then the page became a real page and the
writing is done.  However a page is never automatically freed by this

A nice trick to do under Linux

$ gp -s 50M
? {big computation}
? allocatemem(0) \\ free page
? allocatemem(50*10^6) \\ realloc page
? {new computation}

You are sure to never use more memory than neccessary, while having a
sort of automatic stack growth.

The big caveats is that a lot of functions use the stack size to
determine if they must garbage collect, so a big stack lead to less
conservative garbage collecting. I thing that PARI should use another
value. Say, a flag -w "wanted_stack_size" to gp and use
wanted_stack_size and not stacksize. The problem with this approach is
what to do when with are between wanted_stack_size and not stacksize ?

You can say the amount of memory of program use with 'ps aux'

bill      3200  0.0  6.3 132604 4032 pts/5   S    19:46   0:00 gp -s 130M
bill      3201  0.0  6.3 132604 4032 pts/7   S    19:46   0:00 gp -s 130M
bill      3225  9.5  6.3 122836 4032 pts/8   S    19:56   0:00 gp -s 120M

VSZ is the virtual memory allocated
RSS is the real memory used.

You can see a GP process use only 4Mb after startup

yellowpig% cat /proc/meminfo
        total:    used:    free:  shared: buffers:  cached:
Mem:  64991232 63877120  1114112 35131392  1339392 15491072
Swap: 131567616 18644992 112922624
MemTotal:     63468 kB
MemFree:       1088 kB
MemShared:    34308 kB
Buffers:       1308 kB
Cached:       15128 kB
SwapTotal:   128484 kB
SwapFree:    110276 kB

I hope this will help Linux users to use stack size for the best.

Cheers, Bill.