SWI-Prolog / swipl-devel

SWI-Prolog Main development repository
http://www.swi-prolog.org
Other
959 stars 175 forks source link

Global stack allocation sometimes exceeds specified limit #64

Closed triska closed 4 years ago

triska commented 9 years ago

SWI-Prolog sometimes allocates more global stack than specified with the -G option.

For example, with euler_172.pl on a 64-bit machine (tested with Debian 8.1 and OSX Yosemite), I get:

$ swipl -f euler_172.pl  -G5M
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.2)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- run(7), statistics.
len_num(7, 8754480).
% Started at Tue Jul 14 23:24:16 2015
% 2.500 seconds cpu time for 13,823,938 inferences
% 6,860 atoms, 4,208 functors, 3,250 predicates, 57 modules, 153,713 VM-codes
% 
%                        Limit    Allocated       In use
% Local  stack:    268,435,456       61,440        1,832 Bytes
% Global stack:      5,242,880    6,287,344        1,344 Bytes
% Trail  stack:    268,435,456    2,095,096        2,632 Bytes
% 
% 130 garbage collections gained 148,676,256 bytes in 0.471 seconds.
% Stack shifts: 2 local, 11 global, 10 trail in 0.001 seconds
% 1 threads, 0 finished threads used 0.000 seconds

A slightly more extreme example is:

swipl -O -f euler_172.pl -G26G -T4G -g "run(18),statistics,halt"

Yielding:

len_num(18, 227485267000992000).
% Started at Mon Jul 13 11:42:12 2015
% 35257.269 seconds cpu time for 113,872,091,044 inferences
% 6,174 atoms, 3,962 functors, 3,205 predicates, 52 modules, 147,218 VM-codes
% 
%                        Limit    Allocated       In use
% Local  stack:    268,435,456      126,976        1,792 Bytes
% Global stack: 27,917,287,424 34,359,734,256 14,435,913,504 Bytes
% Trail  stack:  4,294,967,296 4,294,965,240        2,256 Bytes
% 
% 589 garbage collections gained 1,465,242,723,928 bytes in 13010.921 seconds.
% Stack shifts: 2 local, 32 global, 27 trail in 0.411 seconds
% 1 threads, 0 finished threads used 0.000 seconds

Such exceeding allocations can lead to unexpected OS swapping and also to unexpected termination of the process (or other processes) even in situations where there would have been enough RAM to perform the intended computation within the specified stack limits.

If possible, please throw a Prolog exception instead of exceeding the specified limits. Thank you!

JanWielemaker commented 4 years ago

As stack management is completely rewritten, this is outdated. Closing.