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 686646 9ac16f7e3e9eb1cc600edf0bd2f0581e58e46576
parent 686645 124d2e277a55cb09dc499c5c9c0ce9eb0cc327d0
child 686647 edebf42d73d0e7367d6cc56a03e0ff31bcc913c9
push id86234
push userbmo:mh+mozilla@glandium.org
push dateThu, 26 Oct 2017 05:06:52 +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)
@@ -4326,25 +4325,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);