Question Authors' Forum

Cannot allocate memory Warning

Cannot allocate memory Warning

by yunus akarsu -
Number of replies: 9

Hello,

We ran the code on C++, but we keep seeing Syntax Error(s) virtual memory exhausted: Cannot allocate memory message.

We used to set Swap as 6 Gb and RAM 16 Gb on the server, but we keep getting errors.

2


Our Code;

#include <bits/stdc++.h>

#include <string>

#include <algorithm>


string removeDuplicates(const string &s) {

        stack<char> stk;

        for(auto c:s)

        {

            if(stk.empty())

            {

                stk.push(c);

            }

            else

            {

                if(stk.top() != c)

                    stk.push(c);

                else

                    stk.pop();

            }

        }

        string ans = "";

        while(!stk.empty())

        {

            ans+= stk.top();

            stk.pop();

        }

       reverse(ans.begin(), ans.end());

        return ans;

    }



In reply to yunus akarsu

Re: Cannot allocate memory Warning

by Richard Lobb -
Are those settings (6GB swap and 16GB RAM) for the Moodle server or for the Jobe server? The error is coming from the Jobe server.

As a first check, try temporarily switching back to our default outward-facing Jobe server at U Canterbury - do you still get the error?

The error apparently comes from the C++ compiler. Compilation is subject to the same resource limits as the runtime, which are set by the question type. If you get the error both on your Jobe server and ours, try setting the memory limit for the question to 0, which turns off memory limit checking for that question. You access the memory limit by customising the question (click the "Customise" checkbox) then opening the Advanced Customisation panel.

I would have hoped that the default memory limit for a C++ question type would be sufficient to accommodate any normal compilation run and certainly shouldn't be a problem with a simple example like the one you quote. So please let me know if that is the problem.

If the error goes away when you switch to our Jobe server, your Jobe server must have very serious resource constraints.
In reply to Richard Lobb

Re: Cannot allocate memory Warning

by yunus akarsu -
Hello Richard,

Thanks for your replay. Our settings (6GB swap and 16GB RAM) for the Jobe server. I tried U Canterbury Job server its working i didnt see error. I can see error message only my job server. We can see this error message only the C++ compiler.

Can I try setting the memory limit for the question to 0, which turns off memory limit checking for that question?

What do you think?
In reply to yunus akarsu

Re: Cannot allocate memory Warning

by Richard Lobb -
The fact that your question runs with our test Jobe server (a modest 4GB RAM machine) but not with yours (a much bigger machine) is a bit surprising. Is your Jobe server using JobeInABox or was it built using the install instructions on github? If the latter, what is the base OS and is it possible that it is applying memory limits to non-root users - specifically to jobe00, jobe01 etc, the users that run the various jobe tasks?

To answer your original question: there's certainly nothing to lose by setting the memory limit to your question to 0. Try it. My guess is that you'll get the same problem, because I think the limitation is being applied by the OS, not by the Jobe sandboxing.

If all else fails, installing jobeinabox on your Jobe server instead of the standard install might be a workaround.



In reply to Richard Lobb

Re: Cannot allocate memory Warning

by yunus akarsu -
Hello Richard,

Thanks for help I changed Mem Limit 0 and its working now
In reply to yunus akarsu

Re: Cannot allocate memory Warning

by Richard Lobb -
Well that's great, and also very interesting, Yunus. It does raise the question of why your question runs on our Jobe server with all the default settings but not on yours. But ...

I don't teach C++ any more, so it's a long time since I've looked at the Jobe settings for C++. I see that it sets a minimum of 200 MB for a compile but the question can raise the value higher or set it to 0 to turn off the limit altogether. I copied your code and experimented to find how much memory that code needed to compile on our system - the answer is 170 MB. That's getting rather close to the default value of 200 MB. Your compiler must require more memory than ours. I'd be interested to hear from you how much above 200 MB you need to set the Mem Limit value in order to get your code to compile - would you be able to check that, please?

For now, I've raised the default value for the minimum compile time memory allocation to 500 MB and pushed to github.

Thanks for raising the issue here :)
In reply to Richard Lobb

Re: Cannot allocate memory Warning

by yunus akarsu -
Hello Richard,

You're welcome, maybe we've solved an important issue :)
In reply to Richard Lobb

Re: Cannot allocate memory Warning

by yunus akarsu -
Hello Richard,

In addition, our C++ teacher sent me this e-mail and I wanted to share it with you.

Based on my calculation, the code requires 11MB on average, but it really depends on how the class string is implemented on the compiler we are using. Anyways, I set all questions to 0MB so we don’t have limits (also for python and java).

Just to be on the same page, this is the code that raised the issue:

string removeDuplicates(string s) {
stack stk;
for(auto c:s)
{
if(stk.empty())
{
stk.push(c);
}
else
{
if(stk.top() != c)
stk.push(c);
else
stk.pop();
}
}
s = "";

while(!stk.empty())
{
s+= stk.top();
stk.pop();
}
reverse(s.begin(), s.end());
return s;
}

it is only one example, I had the error in several other cases.
In reply to yunus akarsu

Re: Cannot allocate memory Warning

by Richard Lobb -
Thanks for the update. But the figure of 11MB sounds like it's the memory requirements for the run, not for the compile. The value you set for MemLimit is used for the run and also for the compile except that there's a minimum value set for the compile of 200 MB (which I just raised to 500 MB yesterday).

I strongly recommend that you do not use a value of 0 MB for the MemLimit. Having no memory limit means that a process that goes rogue (deliberately or by accident) can consume unlimited amounts of virtual memory and start the Jobe server thrashing, essentially rendering it inoperative. Try a value like 500 MB instead.

Regards

Richard
In reply to Richard Lobb

Re: Cannot allocate memory Warning

by yunus akarsu -
Thank you Richard I will Update MeM Limit

Regards

Yunus