Open jamiees2 opened 9 years ago
Hi.
Thanks for your contibution and sorry for the long delay before replaying.
Since at the moment this feature is not required in CMS and we do not like very much the polling mechanism, we are not including in our repository for now.
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
.