Bug 1411786 - Make the chunk size and recycle limit constant. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 26 Oct 2017 09:38:48 +0900
changeset 686561 bd98e381dc6804acb32e0d059eb6dd232e5dcc45
parent 686560 22b3e6e6d00565d1de14491b1d418c6f55436543
child 686562 9347950359dafd558bfb424efb97f66257ba747a
push id86210
push userbmo:mh+mozilla@glandium.org
push dateThu, 26 Oct 2017 00:56:01 +0000
reviewersnjn
bugs1411786, 1403843
milestone58.0a1
Bug 1411786 - Make the chunk size and recycle limit constant. r?njn Bug 1403843 made more things constant, but missed a few that don't depend on the page size.
memory/build/mozjemalloc.cpp
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -455,38 +455,37 @@ static unsigned nsbins; /* Number of (2^
 #define calculate_arena_header_pages() \
  ((calculate_arena_header_size() >> pagesize_2pow) + \
   ((calculate_arena_header_size() & pagesize_mask) ? 1 : 0))
 
 /* Max size class for arenas. */
 #define calculate_arena_maxclass() \
  (chunksize - (arena_chunk_header_npages << pagesize_2pow))
 
+#define CHUNKSIZE_DEFAULT ((size_t) 1 << CHUNK_2POW_DEFAULT)
+static const size_t chunksize = CHUNKSIZE_DEFAULT;
+static const size_t chunksize_mask = CHUNKSIZE_DEFAULT - 1;
+
+#ifdef MALLOC_STATIC_PAGESIZE
+static const size_t chunk_npages = CHUNKSIZE_DEFAULT >> pagesize_2pow;
+#define arena_chunk_header_npages calculate_arena_header_pages()
+#define arena_maxclass calculate_arena_maxclass()
+#else
+static size_t chunk_npages;
+static size_t arena_chunk_header_npages;
+static size_t arena_maxclass; /* Max size class for arenas. */
+#endif
+
 /*
  * Recycle at most 128 chunks. With 1 MiB chunks, this means we retain at most
  * 6.25% of the process address space on a 32-bit OS for later use.
  */
 #define CHUNK_RECYCLE_LIMIT 128
 
-#ifdef MALLOC_STATIC_PAGESIZE
-#define CHUNKSIZE_DEFAULT ((size_t) 1 << CHUNK_2POW_DEFAULT)
-static const size_t chunksize = CHUNKSIZE_DEFAULT;
-static const size_t chunksize_mask = CHUNKSIZE_DEFAULT - 1;
-static const size_t chunk_npages = CHUNKSIZE_DEFAULT >> pagesize_2pow;
-#define arena_chunk_header_npages calculate_arena_header_pages()
-#define arena_maxclass calculate_arena_maxclass()
 static const size_t recycle_limit = CHUNK_RECYCLE_LIMIT * CHUNKSIZE_DEFAULT;
-#else
-static size_t chunksize;
-static size_t chunksize_mask; /* (chunksize - 1). */
-static size_t chunk_npages;
-static size_t arena_chunk_header_npages;
-static size_t arena_maxclass; /* Max size class for arenas. */
-static size_t recycle_limit;
-#endif
 
 /* The current amount of recycled bytes, updated atomically. */
 static size_t recycled_size;
 
 /******************************************************************************/
 
 /* MALLOC_DECOMMIT and MALLOC_DOUBLE_PURGE are mutually exclusive. */
 #if defined(MALLOC_DECOMMIT) && defined(MALLOC_DOUBLE_PURGE)
@@ -4327,25 +4326,20 @@ MALLOC_OUT:
     }
   }
 
 #ifndef MALLOC_STATIC_PAGESIZE
   /* Set bin-related variables. */
   bin_maxclass = (pagesize >> 1);
   nsbins = pagesize_2pow - SMALL_MAX_2POW_DEFAULT - 1;
 
-  /* Set variables according to the value of CHUNK_2POW_DEFAULT. */
-  chunksize = (1LU << CHUNK_2POW_DEFAULT);
-  chunksize_mask = chunksize - 1;
   chunk_npages = (chunksize >> pagesize_2pow);
 
   arena_chunk_header_npages = calculate_arena_header_pages();
   arena_maxclass = calculate_arena_maxclass();
-
-  recycle_limit = CHUNK_RECYCLE_LIMIT * chunksize;
 #endif
 
   recycled_size = 0;
 
   /* Various sanity checks that regard configuration. */
   MOZ_ASSERT(quantum >= sizeof(void *));
   MOZ_ASSERT(quantum <= pagesize);
   MOZ_ASSERT(chunksize >= pagesize);