Bug 1360772 - Indicate to chunk_recycle callers that pages_commit has zeroed the chunk. r=njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 06 Jul 2017 16:58:18 +0900
changeset 606608 9bcce7387a6820841983d435c967e3fdcf6da9a5
parent 606607 8d7a9b29ea143d87a1f7ab2e32d3859a53097a88
child 606609 14cf6c30707f18afd1f74b5e60ec7ab0d5e049ee
push id67733
push userbmo:mh+mozilla@glandium.org
push dateTue, 11 Jul 2017 04:56:33 +0000
reviewersnjn
bugs1360772
milestone56.0a1
Bug 1360772 - Indicate to chunk_recycle callers that pages_commit has zeroed the chunk. r=njn Before returning a chunk, chunk_recycle calls pages_commit (when MALLOC_DECOMMIT is enabled), which is guaranteed to zero the chunk. The code further zeroing the chunk afterwards, which is now moved out to chunk_alloc callers, never took advantage of that fact, duplicating the effort of zeroing the chunk on Windows. By indicating to the callers that the chunk has already been zeroed, we allow callers to skip zeroing on their own.
memory/mozjemalloc/mozjemalloc.cpp
--- a/memory/mozjemalloc/mozjemalloc.cpp
+++ b/memory/mozjemalloc/mozjemalloc.cpp
@@ -2055,16 +2055,20 @@ chunk_recycle(extent_tree_t *chunks_szad
 	recycled_size -= size;
 
 	malloc_mutex_unlock(&chunks_mtx);
 
 	if (node)
 		base_node_dealloc(node);
 #ifdef MALLOC_DECOMMIT
 	pages_commit(ret, size);
+	// pages_commit is guaranteed to zero the chunk.
+	if (zeroed) {
+		*zeroed = true;
+	}
 #endif
 	return (ret);
 }
 
 #ifdef MOZ_MEMORY_WINDOWS
 /*
  * On Windows, calls to VirtualAlloc and VirtualFree must be matched, making it
  * awkward to recycle allocations of varying sizes. Therefore we only allow