Measuring memory footprint in C/C++ code on FreeBSD
ivoras at freebsd.org
Fri Oct 21 12:08:53 UTC 2011
On 21/10/2011 12:57, Razmig K wrote:
> Le 21.10.2011 12:26, Ivan Voras a écrit :
>> Well, do you know that SIZE in top is virtual memory size, not resident
>> size (which is the "RES" column)? You can allocate whatever you want
>> from virtual memory, it is not "used" until it's touched.
> Yes, I do. So do you suggest using RES as a better indicator of memory
Almost certainly yes. Measuring virtual memory is significantly less
important for real-world loads. Some of this is very nicely described
here: https://www.varnish-cache.org/trac/wiki/ArchitectNotes .
> The program in question processes large 3D images via vtk, and I'd like
> to measure its memory usgae with different parameter configurations as
> the maximum amount of memory acquired during execution. Since SIZE often
> happens to be larger than RES, and increase more during execution, I
> thought of using it as an indicator of memory footprint.
No; the difference between SIZE and RES is "slack space" - allocated but
untouched virtual memory, which is *NOT PRESENT IN RAM*. You can verify
this yourself: make a small C program and allocate twice the physical
memory (+swap) you have on the machine (try terabytes on a 64-bit
machine), and it will succeed. If you look at this program in top, it
should (barring some optimizations) show you that SIZE is huge, but RES
is a couple of MB, basically like you didn't allocate anything at all.
Now, it is a whole other thing if you try to actually *use* this memory
Here's a random link on the topic from Google:
Unfortunately, the phrase "memory overcommit" has been hijacked by the
virtualization environment to mean the same thing but relating to the
memory in virtual machines.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20111021/3e8497e7/signature.pgp
More information about the freebsd-hackers