Bug 820401 - Default DMD to sample-below=4093. r=njn, a=jlebar
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 11 Dec 2012 18:26:43 -0500
changeset 122875 6733372df4c10d02ac3f0cd6fc9aaccc9021fa02
parent 122874 123cde3d73646c437772f4bd27ade0b9a7048d6f
child 122876 b7b17631f55de58cbd97047d36896e2c0c680409
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn, jlebar
bugs820401
milestone19.0a2
Bug 820401 - Default DMD to sample-below=4093. r=njn, a=jlebar Also print out the sample size, since it's no longer explicit in the $DMD envvar.
memory/replace/dmd/DMD.cpp
memory/replace/dmd/test-expected.dmd
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -1306,31 +1306,48 @@ OptionLong(const char* aArg, const char*
       return true;
     }
   }
   return false;
 }
 
 static const size_t gMaxSampleBelowSize = 100 * 1000 * 1000;    // bytes
 
+// Default to sampling with a sample-below size that's a prime number close to
+// 4096.
+//
+// Using a sample-below size ~= 4096 is much faster than using a sample-below
+// size of 1, and it's not much less accurate in practice, so it's a reasonable
+// default.
+//
+// Using a prime sample-below size makes our sampling more random.  If we used
+// instead a sample-below size of 4096, for example, then if all our allocation
+// sizes were even (which they likely are, due to how jemalloc rounds up), our
+// alloc counter would take on only even values.
+//
+// In contrast, using a prime sample-below size lets us explore all possible
+// values of the alloc counter.
+static const size_t gDefaultSampleBelowSize = 4093;
+
 static void
 BadArg(const char* aArg)
 {
   StatusMsg("\n");
   StatusMsg("Bad entry in the $DMD environment variable: '%s'.\n", aArg);
   StatusMsg("\n");
   StatusMsg("Valid values of $DMD are:\n");
   StatusMsg("- undefined or \"\" or \"0\", which disables DMD, or\n");
   StatusMsg("- \"1\", which enables it with the default options, or\n");
   StatusMsg("- a whitespace-separated list of |--option=val| entries, which\n");
   StatusMsg("  enables it with non-default options.\n");
   StatusMsg("\n");
   StatusMsg("The following options are allowed;  defaults are shown in [].\n");
-  StatusMsg("  --sample-below=<1..%d> Sample blocks smaller than this [1]\n",
-            int(gMaxSampleBelowSize));
+  StatusMsg("  --sample-below=<1..%d> Sample blocks smaller than this [%d]\n"
+            "                         (prime numbers recommended).\n",
+            int(gMaxSampleBelowSize), int(gDefaultSampleBelowSize));
   StatusMsg("  --mode=<normal|test|stress>   Which mode to run in? [normal]\n");
   StatusMsg("\n");
   exit(1);
 }
 
 // WARNING: this function runs *very* early -- before all static initializers
 // have run.  For this reason, non-scalar globals such as gStateLock and
 // gStackTraceTable are allocated dynamically (so we can guarantee their
@@ -1339,17 +1356,17 @@ static void
 Init(const malloc_table_t* aMallocTable)
 {
   MOZ_ASSERT(!gIsDMDRunning);
 
   gMallocTable = aMallocTable;
 
   // Set defaults of things that can be affected by the $DMD env var.
   gMode = Normal;
-  gSampleBelowSize = 1;
+  gSampleBelowSize = gDefaultSampleBelowSize;
 
   // DMD is controlled by the |DMD| environment variable.
   // - If it's unset or empty or "0", DMD doesn't run.
   // - Otherwise, the contents dictate DMD's behaviour.
 
   char* e = getenv("DMD");
 
   StatusMsg("$DMD = '%s'\n", e);
@@ -1732,17 +1749,18 @@ Dump(Writer aWriter)
       reportedUsableSize += b.mBlockSize.Usable();
       AddBlockToBlockGroupTable(reportedBlockGroupTable, b, b);
     }
     anyBlocksSampled = anyBlocksSampled || b.mBlockSize.mSampled;
   }
   size_t totalUsableSize = unreportedUsableSize + reportedUsableSize;
 
   WriteTitle("Invocation\n");
-  W("$DMD = '%s'\n\n", gDMDEnvVar);
+  W("$DMD = '%s'\n", gDMDEnvVar);
+  W("Sample-below size = %lld\n\n", (long long)(gSampleBelowSize));
 
   PrintSortedGroups(aWriter, "Double-reported", "double-reported",
                     *gDoubleReportBlockGroupTable, kNoSize, kNoSize);
 
   PrintSortedBlockAndFrameGroups(aWriter, "Unreported", "unreported",
                                  unreportedBlockGroupTable,
                                  unreportedUsableSize, totalUsableSize);
 
@@ -1802,16 +1820,19 @@ UseItOrLoseIt(void* a)
 // The output from this should be compared against test-expected.dmd.  It's
 // been tested on Linux64, and probably will give different results on other
 // platforms.
 static void
 RunTestMode(FILE* fp)
 {
   Writer writer(FpWrite, fp);
 
+  // The first part of this test requires sampling to be disabled.
+  gSampleBelowSize = 1;
+
   // 0th Dump.  Zero for everything.
   Dump(writer);
 
   // 1st Dump: 1 freed, 9 out of 10 unreported.
   // 2nd Dump: still present and unreported.
   int i;
   char* a;
   for (i = 0; i < 10; i++) {
--- a/memory/replace/dmd/test-expected.dmd
+++ b/memory/replace/dmd/test-expected.dmd
@@ -1,13 +1,14 @@
 ------------------------------------------------------------------
 Invocation
 ------------------------------------------------------------------
 
 $DMD = '--mode=test'
+Sample-below size = 1
 
 ------------------------------------------------------------------
 Double-reported blocks
 ------------------------------------------------------------------
 
 (none)
 
 ------------------------------------------------------------------
@@ -30,16 +31,17 @@ Total:      0 bytes
 Reported:   0 bytes ( 0.00%)
 Unreported: 0 bytes ( 0.00%)
 
 ------------------------------------------------------------------
 Invocation
 ------------------------------------------------------------------
 
 $DMD = '--mode=test'
+Sample-below size = 1
 
 ------------------------------------------------------------------
 Double-reported blocks
 ------------------------------------------------------------------
 
 Double-reported: 3 blocks in block group 1 of 1
  96 bytes (90 requested / 6 slop)
  Allocated at
@@ -199,16 +201,17 @@ Total:      14,928 bytes
 Reported:   9,600 bytes (64.31%)
 Unreported: 5,328 bytes (35.69%)
 
 ------------------------------------------------------------------
 Invocation
 ------------------------------------------------------------------
 
 $DMD = '--mode=test'
+Sample-below size = 1
 
 ------------------------------------------------------------------
 Double-reported blocks
 ------------------------------------------------------------------
 
 Double-reported: 1 block in block group 1 of 1
  8 bytes (0 requested / 8 slop)
  Allocated at
@@ -281,16 +284,17 @@ Total:      2,600 bytes
 Reported:   536 bytes (20.62%)
 Unreported: 2,064 bytes (79.38%)
 
 ------------------------------------------------------------------
 Invocation
 ------------------------------------------------------------------
 
 $DMD = '--mode=test'
+Sample-below size = 128
 
 ------------------------------------------------------------------
 Double-reported blocks
 ------------------------------------------------------------------
 
 (none)
 
 ------------------------------------------------------------------