]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix massif --pages-as-heap=yes does not report peak caused by mmap+munmap
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 10 Dec 2015 22:37:59 +0000 (22:37 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 10 Dec 2015 22:37:59 +0000 (22:37 +0000)
ms_unrecord_page_mem was wrongly taking the (possible) peak snapshot
when unrecording the last block.
But the peak snapshot will be detected when unrecording the first block
of an munmap, not when unrecording the last block.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15745

NEWS
massif/ms_main.c
massif/tests/Makefile.am
massif/tests/mmapunmap.c [new file with mode: 0644]
massif/tests/mmapunmap.post.exp [new file with mode: 0644]
massif/tests/mmapunmap.stderr.exp [new file with mode: 0644]
massif/tests/mmapunmap.vgtest [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 146251a108c8523e2c0bbc432fe3bde23088955b..b68d3c49d69c9370525fa853c914505ec8943fd2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -52,11 +52,12 @@ where XXXXXX is the bug number as listed below.
 354797  Added vbit tester support for PPC 64 isa 2.07 iops
 354933  Fix documentation of --kernel-variant=android-no-hw-tls option
 355188  valgrind should intercept all malloc related global functions
-355455  expected stderr of test cases wrapmalloc and wrapmallocstatic overconstrained
+355455  stderr.exp of test cases wrapmalloc and wrapmallocstatic overconstrained
 355454  do not intercept malloc related symbols from the runtime linker
 356044  Dwarf line info reader misinterprets is_stmt register
 
 n-i-bz Fix incorrect (or infinite loop) unwind on RHEL7 x86 32 bits
+n-i-bz massif --pages-as-heap=yes does not report peak caused by mmap+munmap
 
 Release 3.11.0 (22 September 2015)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index e55a774b797f75da27af27824f1997b939140baa..021d79095297cb23cb3fc43aed29701e6eea0f5b 100644 (file)
@@ -1816,10 +1816,13 @@ void ms_unrecord_page_mem( Addr a, SizeT len )
    Addr end;
    tl_assert(VG_IS_PAGE_ALIGNED(len));
    tl_assert(len >= VKI_PAGE_SIZE);
+   // Unrecord the first page. This might be the peak, so do a snapshot.
+   unrecord_block((void*)a, /*maybe_snapshot*/True);
+   a += VKI_PAGE_SIZE;
+   // Then unrecord the remaining pages, but without snapshots.
    for (end = a + len - VKI_PAGE_SIZE; a < end; a += VKI_PAGE_SIZE) {
       unrecord_block((void*)a, /*maybe_snapshot*/False);
    }
-   unrecord_block((void*)a, /*maybe_snapshot*/True);
 }
 
 //------------------------------------------------------------//
index 531d8e6e18a68bd27e54de412ba87e3a1db71a7e..4b69bfc7ed7084e45add7fb00744787bbb58758f 100644 (file)
@@ -24,6 +24,7 @@ EXTRA_DIST = \
        long-names.post.exp long-names.stderr.exp long-names.vgtest \
        long-time.post.exp long-time.stderr.exp long-time.vgtest \
        malloc_usable.stderr.exp malloc_usable.vgtest \
+       mmapunmap.post.exp mmapunmap.stderr.exp mmapunmap.vgtest \
        new-cpp.post.exp new-cpp.stderr.exp new-cpp.vgtest \
        no-stack-no-heap.post.exp no-stack-no-heap.stderr.exp no-stack-no-heap.vgtest \
        null.post.exp null.stderr.exp null.vgtest \
@@ -61,6 +62,7 @@ check_PROGRAMS = \
        insig \
        long-names \
        long-time \
+       mmapunmap \
        malloc_usable \
        new-cpp \
        null \
diff --git a/massif/tests/mmapunmap.c b/massif/tests/mmapunmap.c
new file mode 100644 (file)
index 0000000..4bb4e5a
--- /dev/null
@@ -0,0 +1,16 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "tests/sys_mman.h"
+
+int main()
+{
+   void *m;
+
+   m = mmap(NULL, 80 * 1000 * 1024,
+            PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
+            -1, 0);
+   munmap(m, 80 * 1000 * 1024);
+   return 0;
+}
diff --git a/massif/tests/mmapunmap.post.exp b/massif/tests/mmapunmap.post.exp
new file mode 100644 (file)
index 0000000..50e5c6e
--- /dev/null
@@ -0,0 +1 @@
+  n0: 81920000 0x........: main (mmapunmap.c:11)
diff --git a/massif/tests/mmapunmap.stderr.exp b/massif/tests/mmapunmap.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/massif/tests/mmapunmap.vgtest b/massif/tests/mmapunmap.vgtest
new file mode 100644 (file)
index 0000000..6969658
--- /dev/null
@@ -0,0 +1,6 @@
+prog: mmapunmap
+vgopts: --pages-as-heap=yes --threshold=30.0 -q
+vgopts: --stacks=no --time-unit=B --depth=8 --massif-out-file=massif.out
+vgopts: --ignore-fn=__part_load_locale --ignore-fn=__time_load_locale --ignore-fn=dwarf2_unwind_dyld_add_image_hook --ignore-fn=get_or_create_key_element
+post: grep -A3 -e =peak massif.out | grep -e 'main (mmapunmap.c:11)' | ../../tests/filter_addresses
+# cleanup: rm massif.out