Bug 1423000 - Remove Replay::Commit. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 30 Nov 2017 10:48:41 +0900
changeset 394979 be9b555ba23510fc3e92d706013b5fc9f9b194ff
parent 394952 ba48231d04a8a6cee4a0cccea4985c416029ed25
child 394980 921cfea08410f9b2d1e75abc58beac74c6503363
push id33029
push usercsabou@mozilla.com
push dateTue, 05 Dec 2017 22:05:52 +0000
treeherdermozilla-central@f84f292333c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1423000
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1423000 - Remove Replay::Commit. r=njn It adds an uncompressible and noticeable time overhead to replaying logs, even when one is not interested in measuring RSS. This has caused me to clear the method body on multiple occasions. If necessary, it is possible to enable zero or junk at the allocator level for the same effect.
memory/replace/logalloc/replay/Replay.cpp
--- a/memory/replace/logalloc/replay/Replay.cpp
+++ b/memory/replace/logalloc/replay/Replay.cpp
@@ -75,24 +75,23 @@ public:
 private:
   mutable T* mPtr;
 };
 
 /* Type for records of allocations. */
 struct MemSlot
 {
   void* mPtr;
-  size_t mSize;
 };
 
 /* An almost infinite list of slots.
  * In essence, this is a linked list of arrays of groups of slots.
- * Each group is 1MB. On 64-bits, one group allows to store 64k allocations.
+ * Each group is 1MB. On 64-bits, one group allows to store 128k allocations.
  * Each MemSlotList instance can store 1023 such groups, which means more
- * than 65M allocations. In case more would be needed, we chain to another
+ * than 130M allocations. In case more would be needed, we chain to another
  * MemSlotList, and so on.
  * Using 1023 groups makes the MemSlotList itself page sized on 32-bits
  * and 2 pages-sized on 64-bits.
  */
 class MemSlotList
 {
   static const size_t kGroups = 1024 - 1;
   static const size_t kGroupSize = (1024 * 1024) / sizeof(MemSlot);
@@ -338,105 +337,88 @@ public:
     return mSlots[index];
   }
 
   void malloc(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t size = parseNumber(aArgs);
     aSlot.mPtr = ::malloc_impl(size);
-    aSlot.mSize = size;
-    Commit(aSlot);
   }
 
   void posix_memalign(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t alignment = parseNumber(aArgs.SplitChar(','));
     size_t size = parseNumber(aArgs);
     void* ptr;
     if (::posix_memalign_impl(&ptr, alignment, size) == 0) {
       aSlot.mPtr = ptr;
-      aSlot.mSize = size;
     } else {
       aSlot.mPtr = nullptr;
-      aSlot.mSize = 0;
     }
-    Commit(aSlot);
   }
 
   void aligned_alloc(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t alignment = parseNumber(aArgs.SplitChar(','));
     size_t size = parseNumber(aArgs);
     aSlot.mPtr = ::aligned_alloc_impl(alignment, size);
-    aSlot.mSize = size;
-    Commit(aSlot);
   }
 
   void calloc(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t num = parseNumber(aArgs.SplitChar(','));
     size_t size = parseNumber(aArgs);
     aSlot.mPtr = ::calloc_impl(num, size);
-    aSlot.mSize = size * num;
-    Commit(aSlot);
   }
 
   void realloc(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     Buffer dummy = aArgs.SplitChar('#');
     if (dummy) {
       die("Malformed input");
     }
     size_t slot_id = parseNumber(aArgs.SplitChar(','));
     size_t size = parseNumber(aArgs);
     MemSlot& old_slot = (*this)[slot_id];
     void* old_ptr = old_slot.mPtr;
     old_slot.mPtr = nullptr;
-    old_slot.mSize = 0;
     aSlot.mPtr = ::realloc_impl(old_ptr, size);
-    aSlot.mSize = size;
-    Commit(aSlot);
   }
 
   void free(Buffer& aArgs)
   {
     mOps++;
     Buffer dummy = aArgs.SplitChar('#');
     if (dummy) {
       die("Malformed input");
     }
     size_t slot_id = parseNumber(aArgs);
     MemSlot& slot = (*this)[slot_id];
     ::free_impl(slot.mPtr);
     slot.mPtr = nullptr;
-    slot.mSize = 0;
   }
 
   void memalign(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t alignment = parseNumber(aArgs.SplitChar(','));
     size_t size = parseNumber(aArgs);
     aSlot.mPtr = ::memalign_impl(alignment, size);
-    aSlot.mSize = size;
-    Commit(aSlot);
   }
 
   void valloc(MemSlot& aSlot, Buffer& aArgs)
   {
     mOps++;
     size_t size = parseNumber(aArgs);
     aSlot.mPtr = ::valloc_impl(size);
-    aSlot.mSize = size;
-    Commit(aSlot);
   }
 
   void jemalloc_stats(Buffer& aArgs)
   {
     if (aArgs) {
       die("Malformed input");
     }
     jemalloc_stats_t stats;
@@ -446,21 +428,16 @@ public:
              "bookkeep: %zu; binunused: %zu\n", mOps, stats.mapped,
              stats.allocated, stats.waste, stats.page_cache,
              stats.bookkeeping, stats.bin_unused);
     /* TODO: Add more data, like actual RSS as measured by OS, but compensated
      * for the replay internal data. */
   }
 
 private:
-  void Commit(MemSlot& aSlot)
-  {
-    memset(aSlot.mPtr, 0x5a, aSlot.mSize);
-  }
-
   intptr_t mStdErr;
   size_t mOps;
   MemSlotList mSlots;
 };
 
 
 int
 main()