Comments (5)
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.
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.
I am not sure. I think that @gollux, @bblackham or @seirl know the exact answer.
from isolate.
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.
Thanks @stefano-maggiolo and @hermanzdosilovic for your answers. I will close the issue.
from isolate.
Related Issues (20)
- cg2 version fails if memory.swap.max does not exist HOT 7
- I also encountered the same issue. This worked for me:
- Getting Resource temporarily unavailable error while compiling C program HOT 3
- Is this possible? HOT 13
- cg2: `cf_cg_root` points to junk after `clone()` on Fedora HOT 2
- Unable to access internet inside isolate box even after using --share-net HOT 4
- "No such file or directory" issue when trying to run C# program using Dotnet HOT 7
- Memory corruption bug in cg_init HOT 2
- C# program failed to compile using mcs - error CS2001: Source file `Main.cs' could not be found HOT 1
- make install exited with error code 1. HOT 1
- Error Running isolate in Ubuntu:22.04 with Systemd HOT 10
- Support for Docker HOT 12
- Error using isolate HOT 15
- Assertion Failure Issue HOT 4
- --as-uid and --as-gid seem to be not usable in Docker container HOT 3
- Cannot set disk quota: No such process HOT 1
- chown: cannot access /var/local/lib/isolate/XX/box': No such file or directory HOT 6
- CPU time (--time) consumed in subsequent runs in the same box with cg (cgroup2) enabled HOT 9
- Limitation on number of sandboxes HOT 1
- [Query] Isolate Mac OS setup HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isolate.