This repository has been archived by the owner on Nov 17, 2024. It is now read-only.
Support a soft memory limit for Memory Limit Exceeded errors. #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We required the ability for isolate to result in MLE, instead of either RTE or TLE when it hit a memory cap. We implemented this by adding moreoless the same code as mooshak's safeexec program runs, but adapted to make the most of the functions already in place.
This adds a new parameter
--soft-mem
which is a memory limit which is not hard; there is more memory available, but it cannot be used. This way the program can actually attempt to allocate more memory, but it is detected and the program is terminated. Just make sure that--mem
or--cg-mem
is set to something higher if at all.For this to be added, the
wait4
loop had to be changed, so that instead of lettingwait4
block execution, a do-while loop with regular sleep intervals handles that.For getting the current memory usage, the data section of
/proc/<pid>/statm
is read. That is, the total memory usage of the process is considered to beVmData + VmStk
.Although this is a cap, it is enforced somewhat lightly, and in theory atleast, a program could allocate too much memory in less than 67ms and then immediately exit, therefore bypassing the check.
In a contest environment however, this will rarely be the case, and any overflow will be handled by a hard upper limit like
--cg-mem
.