Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jamiees2
Copy link

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 letting wait4 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 be VmData + 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.

@giomasce
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants