JSC should put bmalloc's scavenger into mini mode
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 May 2018 18:56:05 +0000 (18:56 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 May 2018 18:56:05 +0000 (18:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185988

Reviewed by Michael Saboff.

Source/bmalloc:

We expose an API for putting bmalloc into mini mode. All that means now
is that we'll run the scavenger more aggressively.

* bmalloc/Scavenger.cpp:
(bmalloc::Scavenger::enableMiniMode):
(bmalloc::Scavenger::threadRunLoop):
* bmalloc/Scavenger.h:
* bmalloc/Sizes.h:
* bmalloc/bmalloc.cpp:
(bmalloc::api::enableMiniMode):
* bmalloc/bmalloc.h:

Source/JavaScriptCore:

When we InitializeThreading, we'll now enable bmalloc's mini mode
if the VM is in mini mode. This is an 8-10% progression on the footprint
at end score in run-testmem, making it a 4-5% memory score progression.
It's between a 0-1% regression in its time score.

* runtime/InitializeThreading.cpp:
(JSC::initializeThreading):

Source/WTF:

* wtf/FastMalloc.cpp:
(WTF::fastEnableMiniMode):
* wtf/FastMalloc.h:

Tools:

This patch makes it so that we turn off the JIT when running run-testmem
that way we make JSC use its mini mode.

* Scripts/run-testmem:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232269 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/InitializeThreading.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/FastMalloc.cpp
Source/WTF/wtf/FastMalloc.h
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Scavenger.cpp
Source/bmalloc/bmalloc/Scavenger.h
Source/bmalloc/bmalloc/Sizes.h
Source/bmalloc/bmalloc/bmalloc.cpp
Source/bmalloc/bmalloc/bmalloc.h
Tools/ChangeLog
Tools/Scripts/run-testmem

index a92e107..fdc5955 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-29  Saam Barati  <sbarati@apple.com>
+
+        JSC should put bmalloc's scavenger into mini mode
+        https://bugs.webkit.org/show_bug.cgi?id=185988
+
+        Reviewed by Michael Saboff.
+
+        When we InitializeThreading, we'll now enable bmalloc's mini mode
+        if the VM is in mini mode. This is an 8-10% progression on the footprint
+        at end score in run-testmem, making it a 4-5% memory score progression.
+        It's between a 0-1% regression in its time score.
+
+        * runtime/InitializeThreading.cpp:
+        (JSC::initializeThreading):
+
 2018-05-29  Caitlin Potter  <caitp@igalia.com>
 
         [JSC] Fix Array.prototype.concat fast case when single argument is Proxy
index 659ec6e..9abcef3 100644 (file)
@@ -81,6 +81,9 @@ void initializeThreading()
 #if ENABLE(WEBASSEMBLY)
         Wasm::Thunks::initialize();
 #endif
+
+        if (VM::isInMiniMode())
+            WTF::fastEnableMiniMode();
     });
 }
 
index 87f05a1..840b169 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-29  Saam Barati  <sbarati@apple.com>
+
+        JSC should put bmalloc's scavenger into mini mode
+        https://bugs.webkit.org/show_bug.cgi?id=185988
+
+        Reviewed by Michael Saboff.
+
+        * wtf/FastMalloc.cpp:
+        (WTF::fastEnableMiniMode):
+        * wtf/FastMalloc.h:
+
 2018-05-29  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Unreviewed, follow-up after r232244
index 986b0f1..74d1b56 100644 (file)
@@ -250,6 +250,8 @@ void fastDecommitAlignedMemory(void* ptr, size_t size)
     OSAllocator::decommit(ptr, size);
 }
 
+void fastEnableMiniMode() { }
+
 } // namespace WTF
 
 #else // defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC
@@ -383,6 +385,11 @@ void fastDecommitAlignedMemory(void* ptr, size_t size)
     bmalloc::api::decommitAlignedPhysical(ptr, size);
 }
 
+void fastEnableMiniMode()
+{
+    bmalloc::api::enableMiniMode();
+}
+
 } // namespace WTF
 
 #endif // defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC
index 41ef69f..9d7d7ff 100644 (file)
@@ -73,6 +73,8 @@ WTF_EXPORT_PRIVATE void releaseFastMallocFreeMemoryForThisThread();
 WTF_EXPORT_PRIVATE void fastCommitAlignedMemory(void*, size_t);
 WTF_EXPORT_PRIVATE void fastDecommitAlignedMemory(void*, size_t);
 
+WTF_EXPORT_PRIVATE void fastEnableMiniMode();
+
 struct FastMallocStatistics {
     size_t reservedVMBytes;
     size_t committedVMBytes;
index 4676531..2e9c829 100644 (file)
@@ -1,3 +1,22 @@
+2018-05-29  Saam Barati  <sbarati@apple.com>
+
+        JSC should put bmalloc's scavenger into mini mode
+        https://bugs.webkit.org/show_bug.cgi?id=185988
+
+        Reviewed by Michael Saboff.
+
+        We expose an API for putting bmalloc into mini mode. All that means now
+        is that we'll run the scavenger more aggressively.
+
+        * bmalloc/Scavenger.cpp:
+        (bmalloc::Scavenger::enableMiniMode):
+        (bmalloc::Scavenger::threadRunLoop):
+        * bmalloc/Scavenger.h:
+        * bmalloc/Sizes.h:
+        * bmalloc/bmalloc.cpp:
+        (bmalloc::api::enableMiniMode):
+        * bmalloc/bmalloc.h:
+
 2018-05-29  Geoffrey Garen  <ggaren@apple.com>
 
         Fixed the bmalloc build
index 6c2b55a..724c3f7 100644 (file)
@@ -179,6 +179,13 @@ std::chrono::milliseconds Scavenger::timeSinceLastPartialScavenge()
     return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_lastPartialScavengeTime);
 }
 
+void Scavenger::enableMiniMode()
+{
+    m_isInMiniMode = true; // We just store to this racily. The scavenger thread will eventually pick up the right value.
+    if (m_state == State::RunSoon)
+        run();
+}
+
 void Scavenger::scavenge()
 {
     std::unique_lock<Mutex> lock(m_scavengingMutex);
@@ -377,7 +384,7 @@ void Scavenger::threadRunLoop()
         
         if (m_state == State::RunSoon) {
             std::unique_lock<Mutex> lock(m_mutex);
-            m_condition.wait_for(lock, asyncTaskSleepDuration, [&]() { return m_state != State::RunSoon; });
+            m_condition.wait_for(lock, std::chrono::milliseconds(m_isInMiniMode ? 200 : 2000), [&]() { return m_state != State::RunSoon; });
         }
         
         m_state = State::Sleep;
@@ -403,11 +410,18 @@ void Scavenger::threadRunLoop()
             auto timeSinceLastFullScavenge = this->timeSinceLastFullScavenge();
             auto timeSinceLastPartialScavenge = this->timeSinceLastPartialScavenge();
             auto timeSinceLastScavenge = std::min(timeSinceLastPartialScavenge, timeSinceLastFullScavenge);
-            if (isUnderMemoryPressure() && freeableMemory > 4 * MB && timeSinceLastScavenge > std::chrono::milliseconds(5))
+
+            if (isUnderMemoryPressure() && freeableMemory > 1 * MB && timeSinceLastScavenge > std::chrono::milliseconds(5))
                 return ScavengeMode::Full;
 
             if (!m_isProbablyGrowing) {
-                if (timeSinceLastFullScavenge < std::chrono::milliseconds(1000))
+                if (timeSinceLastFullScavenge < std::chrono::milliseconds(1000) && !m_isInMiniMode)
+                    return ScavengeMode::Partial;
+                return ScavengeMode::Full;
+            }
+
+            if (m_isInMiniMode) {
+                if (timeSinceLastFullScavenge < std::chrono::milliseconds(200))
                     return ScavengeMode::Partial;
                 return ScavengeMode::Full;
             }
@@ -421,7 +435,7 @@ void Scavenger::threadRunLoop()
                 // Rate limit partial scavenges.
                 return ScavengeMode::None;
             }
-            if (freeableMemory < 50 * MB)
+            if (freeableMemory < 25 * MB)
                 return ScavengeMode::None;
             if (5 * freeableMemory < footprint())
                 return ScavengeMode::None;
index 858d66a..919f6e9 100644 (file)
@@ -72,6 +72,8 @@ public:
     // It's unlikely, but possible.
     size_t footprint();
 
+    void enableMiniMode();
+
 private:
     enum class State { Sleep, Run, RunSoon };
     
@@ -108,6 +110,8 @@ private:
 #endif
     
     Vector<DeferredDecommit> m_deferredDecommits;
+
+    bool m_isInMiniMode { false };
 };
 
 } // namespace bmalloc
index b148935..094ee2e 100644 (file)
@@ -71,8 +71,6 @@ namespace Sizes {
     static const size_t scavengerBytesPerMemoryPressureCheck = 16 * MB;
     static const double memoryPressureThreshold = 0.75;
     
-    static const std::chrono::milliseconds asyncTaskSleepDuration = std::chrono::milliseconds(2000);
-    
     static const size_t maskSizeClassCount = maskSizeClassMax / alignment;
 
     inline constexpr size_t maskSizeClass(size_t size)
index be5aca2..1e5efb9 100644 (file)
@@ -116,5 +116,10 @@ void decommitAlignedPhysical(void* object, size_t size, HeapKind kind)
     heap.externalDecommit(object, size);
 }
 
+void enableMiniMode()
+{
+    PerProcess<Scavenger>::get()->enableMiniMode();
+}
+
 } } // namespace bmalloc::api
 
index 5321c8e..a0b174e 100644 (file)
@@ -121,5 +121,7 @@ inline double percentAvailableMemoryInUse()
 BEXPORT void setScavengerThreadQOSClass(qos_class_t overrideClass);
 #endif
 
+BEXPORT void enableMiniMode();
+
 } // namespace api
 } // namespace bmalloc
index 5a25e57..c1ad3bf 100644 (file)
@@ -1,3 +1,15 @@
+2018-05-29  Saam Barati  <sbarati@apple.com>
+
+        JSC should put bmalloc's scavenger into mini mode
+        https://bugs.webkit.org/show_bug.cgi?id=185988
+
+        Reviewed by Michael Saboff.
+
+        This patch makes it so that we turn off the JIT when running run-testmem
+        that way we make JSC use its mini mode.
+
+        * Scripts/run-testmem:
+
 2018-05-29  Sihui Liu  <sihui_liu@apple.com>
 
         Unable to remove IndexedDB Databases with Cocoa API removeDataOfTypes
index ca6f120..dcb07f7 100644 (file)
@@ -133,7 +133,12 @@ end
 
 def runTest(path, iters)
     command = "#{getTestmemPath} #{path} #{iters}"
-    stdout, stderr, exitCode = Open3.capture3({"DYLD_FRAMEWORK_PATH" => getBuildDirectory}, command)
+    environment = {
+        "DYLD_FRAMEWORK_PATH" => getBuildDirectory,
+        "JSC_useJIT" => "false",
+        "JSC_useRegExpJIT" => "false",
+    }
+    stdout, stderr, exitCode = Open3.capture3(environment, command)
 
     if $verbose
         puts stdout