Bug 1423000 - Remove Replay::Commit. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 30 Nov 2017 10:48:41 +0900
changeset 707236 d799dbcaa01f79f1491c5361d992bba64d94f293
parent 707235 e19b017880c8d71385aed453bacbe2b473757e90
child 707237 316ab3e270ee8e14a4f9f3d4feacc6014738a6b4
push id92052
push userbmo:mh+mozilla@glandium.org
push dateMon, 04 Dec 2017 23:34:17 +0000
reviewersnjn
bugs1423000
milestone59.0a1
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()