-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional heap size limit would be very useful #2294
Comments
There must be a way to do this in rust when even |
Wow, I was just working on something similar as a stepping stone to dealing with actual out of memory errors in the heap (#16). Currently the heap is just a For this and more reasons, I think that |
We could just do what they do, which is reading |
Who writes this message |
It's the Rust global allocator. It doesn't give a fallible interface, it just shows this message and aborts in this case. Should we also abort after the resource error when we catch this case? I think it seems appropriate, because even the toplevel may not work if there is no more memory. |
Throwing an exception resets all heap allocations and therefore should return to the same heap state encountered when the query was initiated. |
To clarify: This item can be completely solved by reasoning about the virtual machine state of the WAM as implemented by Scryer Prolog, it is a matter of checking whether the WAM register The entire point of this issue is to obtain a Prolog exception so that "out-of-WAM-memory" conditions can be handled in Prolog applications. It is never acceptable for Scryer Prolog to crash. |
The major source of overflows in Prolog is non-termination of completely correct predicates in certain use cases. So the code is not wrong, just the query is a bit too general. Like
compare this to SICStus:
Which one makes a better impression? |
Would it also be good to have this limit by default, and maybe dynamic? Maybe we could check how much memory is available in the system once in a while and put the limit to 80 or 90% of that. Even just putting the default limit to something like 2GB would be helpful I think, most basic Prolog programs don't need that much memory, and if you need you could just increase the limit. Either of these would give default behavior close to the SICStus example above. |
Don't overthink it. I use |
Prolog applications and test cases may cause Scryer Prolog to allocate a lot of memory to store terms on the WAM heap. Even more so now, while garbage collection is not yet implemented. When no more memory can be allocated, the system currently simply crashes instead of throwing Prolog exceptions that can be caught and reasoned about in programs (#16).
It is my understanding that "out of memory" conditions can currently not be reliably or easily caught due to shortcomings in Rust itself. However, it would already help tremendously if Scryer Prolog provided a way to dynamically configure an optional heap size limit, for example via a command line option or system-specific fact, as in:
This example would make Scryer act as if only 100_000 bytes were available for the heap, and throw an exception when the heap grows beyond this size. It is not necessary to check this limit after every WAM instruction or every logical inference. It would suffice to check this limit every N inferences (N to be defined), which can be checked when the global inference count is incremented (see 54166b9). Adding such a check for the WAM heap seems much easier than catching the case of the true (as opposed to the virtual) machine running out of memory.
In addition, there are currently terms that are not allocated on the heap, notably strings and large integers. Ideally, their size is also taken into account as long as they are not allocated on the heap. I hope that this additional complication may soon become irrelevant, when these data structures are also allocated on the heap for faster memory reclamation on backtracking and also other efficiency reasons.
If anyone is interested in this issue, please have a look, I would greatly appreciate your help with this! Thank you a lot!
The text was updated successfully, but these errors were encountered: