Code Monkey home page Code Monkey logo

Comments (5)

hermanzdosilovic avatar hermanzdosilovic commented on July 23, 2024

Hi @Vasilut,

let me try to explain you what happened here.

I have run your code in Judge0 IDE, an online code editor that uses isolate as sandbox. And as you can see your program used only 252 KB of memory because GCC compiler didn't even generate code for array definition in line 7. You can see that for yourself using Compiler Explorer. So even with no optimization -O0 compiler is smart enough to see that there is no need to allocate stack memory for x because it is not used. If you change -O0 to -O2 you will see that compiler will optimize your code even further and won't even generate code for for loop in line 8 [link].

If we modify your code slightly [link] you will see that this program now uses 4200 KB of memory. Godbolting this code show that with -O0 flag compiler generated code as you expected. With -O2 flag that is not the case [link]. Simple modification of this program will make compiler generate expected code even with -02 flag [link] [link].

I hope you now understand why isolate showed you results you got. 😃

BR,
Herman

from isolate.

Vasilut avatar Vasilut commented on July 23, 2024

Hi Herman.

Thanks for your response.
I understand now why the memory was not alocated in my case.
Still, I have one questions. Regarding the code that consumes 4200 Kb of memory:

#include
#include
using namespace std;

int main()
{
int x[1000000];
for(int i = 0; i < 500000000; ++i)
{
if (i < 1000000)
{
x[i] = i;
}
}

cout << " Good 3l";

return 0;

}

When I ran the following command: ./isolate --cg --meta=/tmp/logo.txt --time=1.5 --run -- prog
I got the next result:
time:1.026
time-wall:1.247
max-rss:6932
csw-voluntary:1
csw-forced:2287
cg-mem:17604
Why I'm getting 17604 (I guess are 17604Kb), no ?
Also, If I put --cg-mem=15000, the program does not return memory limit exceeded.

Thanks.
Lucian

from isolate.

hermanzdosilovic avatar hermanzdosilovic commented on July 23, 2024

I am not sure. I think that @gollux, @bblackham or @seirl know the exact answer.

from isolate.

stefano-maggiolo avatar stefano-maggiolo commented on July 23, 2024

Not sure why you get such a high cg-memory usage (yes, it's about 17MiB), I get ~500KiB with -O2 and ~4.2MiB with -O0, similar to Herman.

The reason it doesn't fail with exceeded memory is most likely that you have swap enabled. Afaiu --cg-mem limits physical memory, but if you have swap enabled it will just swap more (with this workload it's not going to make a difference in running time, but an average program will take much more time.

cg-mem in the reporting instead is a maximum between memory.max_usage_in_bytes and memory.memsw.max_usage_in_bytes, which I assume means it takes the maximum between the max physical memory and the max swap used during the running time of the program.

Another similar unexpected situation with --cg-mem is, for example, when you declare a big array but you use only a part of it - this is not going to trigger memory limits even with swap disabled because the full array is never mapped fully in physical memory, just the pages you are actually using.

from isolate.

Vasilut avatar Vasilut commented on July 23, 2024

Thanks @stefano-maggiolo and @hermanzdosilovic for your answers. I will close the issue.

from isolate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.