Allow maximum block size to be specified as an environment variable.
authorMichael Brasser <michael.brasser@live.com>
Thu, 20 Feb 2014 16:43:09 +0000 (10:43 -0600)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 13 Mar 2014 15:39:34 +0000 (16:39 +0100)
A smaller maximum block size helps limit RAM usage on constrained
systems, at the cost of more frequent garbage collection.

Change-Id: Iba07d9cc628e3178dfaad35664c631844540bc9d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4mm.cpp

index 7bb41f1..30a8a47 100644 (file)
@@ -152,6 +152,7 @@ struct MemoryManager::Data
     uint allocCount[MaxItemSize/16];
     int totalItems;
     int totalAlloc;
+    uint maxShift;
     struct Chunk {
         PageAllocation memory;
         int chunkSize;
@@ -184,6 +185,7 @@ struct MemoryManager::Data
         , stackTop(0)
         , totalItems(0)
         , totalAlloc(0)
+        , maxShift(10)
         , largeItems(0)
     {
         memset(smallItems, 0, sizeof(smallItems));
@@ -193,6 +195,12 @@ struct MemoryManager::Data
         scribble = !qgetenv("QV4_MM_SCRIBBLE").isEmpty();
         aggressiveGC = !qgetenv("QV4_MM_AGGRESSIVE_GC").isEmpty();
         exactGC = qgetenv("QV4_MM_CONSERVATIVE_GC").isEmpty();
+
+        QByteArray overrideMaxShift = qgetenv("QV4_MM_MAXBLOCK_SHIFT");
+        bool ok;
+        uint override = overrideMaxShift.toUInt(&ok);
+        if (ok && override <= 11 && override > 0)
+            maxShift = override;
     }
 
     ~Data()
@@ -308,10 +316,10 @@ Managed *MemoryManager::alloc(std::size_t size)
 
     // no free item available, allocate a new chunk
     {
-        // allocate larger chunks at a time to avoid excessive GC, but cap at 64M chunks
+        // allocate larger chunks at a time to avoid excessive GC, but cap at maximum chunk size (32MB by default)
         uint shift = ++m_d->nChunks[pos];
-        if (shift > 10)
-            shift = 10;
+        if (shift > m_d->maxShift)
+            shift = m_d->maxShift;
         std::size_t allocSize = CHUNK_SIZE*(size_t(1) << shift);
         allocSize = roundUpToMultipleOf(WTF::pageSize(), allocSize);
         Data::Chunk allocation;