I recently discovered valgrind while searching for a way to see how much
memory (total memory footprint) my small program represented.

I was perplexed by the results I was seeing, since I expected at most to
use perhaps tens of thousands of bites not Millions. My application is not
dynamically requesting/allocating memory, all memory consumed is in the
form of statically assigned character arrays, automatic stack usage etc..

valgrind --version
valgrind-3.9.0

I'm running on LFS 7.4
linux-3.11
glibc-2.18
gcc-4.8.1

So I did a test by running valgrind against an empty C program. The program
does nothing but return. Can someone explain why the output shows
continually increasing memory used and in total over a 6 MB peak?

user [ ~/ccode/string_buffer ]> cat > ./just_return.c << "EOF"
> int main(void)
> {
> return 0;
> }
> EOF
user [ ~/ccode/string_buffer ]> gcc -O0 -Wall -g -o just_return
just_return.c
user [ ~/ccode/string_buffer ]> valgrind --tool=massif --pages-as-heap=yes
--time-unit=B ./just_return
==11740== Massif, a heap profiler
==11740== Copyright (C) 2003-2013, and GNU GPL'd, by Nicholas Nethercote
==11740== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==11740== Command: ./just_return
==11740==
==11740==
user [ ~/ccode/string_buffer ]> ms_print massif.out.11740
--------------------------------------------------------------------------------
Command:            ./just_return
Massif arguments:   --pages-as-heap=yes --time-unit=B
ms_print arguments: massif.out.11740
--------------------------------------------------------------------------------


    MB
5.902^
:

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #

|                                                                       #
     |
:::::::::::::::::::::::::::::::::::::::::::::#
     |
:                                            #
     |
:                                            #
     |
:                                            #
     |
:                                            #
     |
:                                            #
     |
:                                            #
   0
+----------------------------------------------------------------------->MB
     0
5.918

Number of snapshots: 21
 Detailed snapshots: [9, 19 (peak)]

--------------------------------------------------------------------------------
  n        time(B)         total(B)   useful-heap(B) extra-heap(B)
stacks(B)
--------------------------------------------------------------------------------
  0          4,096            4,096            4,096
0            0
  1          8,192            8,192            8,192
0            0
  2        139,264          139,264          139,264
0            0
  3        147,456          147,456          147,456
0            0
  4        151,552          151,552          151,552
0            0
  5        155,648          155,648          155,648
0            0
  6        159,744          159,744          159,744
0            0
  7        167,936          167,936          167,936
0            0
  8        172,032          172,032          172,032
0            0
  9        172,032          172,032          172,032
0            0
100.00% (172,032B) (page allocation syscalls) mmap/mremap/brk, --alloc-fns,
etc.
->100.00% (172,032B) 0xFFFFFFFFFFFFFFFF: ???

--------------------------------------------------------------------------------
  n        time(B)         total(B)   useful-heap(B) extra-heap(B)
stacks(B)
--------------------------------------------------------------------------------
 10        176,128          176,128          176,128
0            0
 11      2,277,376        2,277,376        2,277,376
0            0
 12      2,281,472        2,281,472        2,281,472
0            0
 13      2,297,856        2,297,856        2,297,856
0            0
 14      6,139,904        6,139,904        6,139,904
0            0
 15      6,164,480        6,164,480        6,164,480
0            0
 16      6,180,864        6,180,864        6,180,864
0            0
 17      6,184,960        6,184,960        6,184,960
0            0
 18      6,189,056        6,189,056        6,189,056
0            0
 19      6,201,344        6,176,768        6,176,768
0            0
100.00% (6,176,768B) (page allocation syscalls) mmap/mremap/brk,
--alloc-fns, etc.
->97.21% (6,004,736B) 0x4017119: mmap (in /lib/ld-2.18.so)
| ->96.22% (5,943,296B) 0x40064F0: _dl_map_object_from_fd (in /lib/
ld-2.18.so)
| | ->96.22% (5,943,296B) 0x4007F93: _dl_map_object (in /lib/ld-2.18.so)
| |   ->62.20% (3,842,048B) 0x400C230: openaux (in /lib/ld-2.18.so)
| |   | ->62.20% (3,842,048B) 0x400E682: _dl_catch_error (in /lib/ld-2.18.so
)
| |   |   ->62.20% (3,842,048B) 0x400C483: _dl_map_object_deps (in /lib/
ld-2.18.so)
| |   |     ->62.20% (3,842,048B) 0x4002D52: dl_main (in /lib/ld-2.18.so)
| |   |       ->62.20% (3,842,048B) 0x40150B3: _dl_sysdep_start (in /lib/
ld-2.18.so)
| |   |         ->62.20% (3,842,048B) 0x40049A4: _dl_start (in /lib/
ld-2.18.so)
| |   |           ->62.20% (3,842,048B) 0x4001136: ??? (in /lib/ld-2.18.so)
| |   |
| |   ->34.02% (2,101,248B) 0x400131C: map_doit (in /lib/ld-2.18.so)
| |     ->34.02% (2,101,248B) 0x400E682: _dl_catch_error (in /lib/ld-2.18.so
)
| |       ->34.02% (2,101,248B) 0x4000F78: do_preload (in /lib/ld-2.18.so)
| |         ->34.02% (2,101,248B) 0x40040C6: dl_main (in /lib/ld-2.18.so)
| |           ->34.02% (2,101,248B) 0x40150B3: _dl_sysdep_start (in /lib/
ld-2.18.so)
| |             ->34.02% (2,101,248B) 0x40049A4: _dl_start (in /lib/
ld-2.18.so)
| |               ->34.02% (2,101,248B) 0x4001136: ??? (in /lib/ld-2.18.so)
| |
| ->00.99% (61,440B) in 1+ places, all below ms_print's threshold (01.00%)
|
->02.79% (172,032B) 0xFFFFFFFFFFFFFFFF: ???

--------------------------------------------------------------------------------
  n        time(B)         total(B)   useful-heap(B) extra-heap(B)
stacks(B)
--------------------------------------------------------------------------------
 20      6,205,440        6,172,672        6,172,672
0            0


Thanks,
Rob Taylor
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to