Title: [232269] trunk
Revision
232269
Author
sbar...@apple.com
Date
2018-05-29 11:56:05 -0700 (Tue, 29 May 2018)

Log Message

JSC should put bmalloc's scavenger into mini mode
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/_javascript_Core:

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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (232268 => 232269)


--- trunk/Source/_javascript_Core/ChangeLog	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-05-29 18:56:05 UTC (rev 232269)
@@ -1,3 +1,18 @@
+2018-05-29  Saam Barati  <sbar...@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  <ca...@igalia.com>
 
         [JSC] Fix Array.prototype.concat fast case when single argument is Proxy

Modified: trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp (232268 => 232269)


--- trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2018-05-29 18:56:05 UTC (rev 232269)
@@ -81,6 +81,9 @@
 #if ENABLE(WEBASSEMBLY)
         Wasm::Thunks::initialize();
 #endif
+
+        if (VM::isInMiniMode())
+            WTF::fastEnableMiniMode();
     });
 }
 

Modified: trunk/Source/WTF/ChangeLog (232268 => 232269)


--- trunk/Source/WTF/ChangeLog	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/WTF/ChangeLog	2018-05-29 18:56:05 UTC (rev 232269)
@@ -1,3 +1,14 @@
+2018-05-29  Saam Barati  <sbar...@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....@gmail.com>
 
         Unreviewed, follow-up after r232244

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (232268 => 232269)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2018-05-29 18:56:05 UTC (rev 232269)
@@ -250,6 +250,8 @@
     OSAllocator::decommit(ptr, size);
 }
 
+void fastEnableMiniMode() { }
+
 } // namespace WTF
 
 #else // defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC
@@ -383,6 +385,11 @@
     bmalloc::api::decommitAlignedPhysical(ptr, size);
 }
 
+void fastEnableMiniMode()
+{
+    bmalloc::api::enableMiniMode();
+}
+
 } // namespace WTF
 
 #endif // defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC

Modified: trunk/Source/WTF/wtf/FastMalloc.h (232268 => 232269)


--- trunk/Source/WTF/wtf/FastMalloc.h	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2018-05-29 18:56:05 UTC (rev 232269)
@@ -73,6 +73,8 @@
 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;

Modified: trunk/Source/bmalloc/ChangeLog (232268 => 232269)


--- trunk/Source/bmalloc/ChangeLog	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/ChangeLog	2018-05-29 18:56:05 UTC (rev 232269)
@@ -1,3 +1,22 @@
+2018-05-29  Saam Barati  <sbar...@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  <gga...@apple.com>
 
         Fixed the bmalloc build

Modified: trunk/Source/bmalloc/bmalloc/Scavenger.cpp (232268 => 232269)


--- trunk/Source/bmalloc/bmalloc/Scavenger.cpp	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/bmalloc/Scavenger.cpp	2018-05-29 18:56:05 UTC (rev 232269)
@@ -179,6 +179,13 @@
     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 @@
         
         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,15 +410,22 @@
             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;
+            }
+
 #if BCPU(X86_64)
             auto partialScavengeInterval = std::chrono::milliseconds(12000);
 #else
@@ -421,7 +435,7 @@
                 // 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;

Modified: trunk/Source/bmalloc/bmalloc/Scavenger.h (232268 => 232269)


--- trunk/Source/bmalloc/bmalloc/Scavenger.h	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/bmalloc/Scavenger.h	2018-05-29 18:56:05 UTC (rev 232269)
@@ -72,6 +72,8 @@
     // It's unlikely, but possible.
     size_t footprint();
 
+    void enableMiniMode();
+
 private:
     enum class State { Sleep, Run, RunSoon };
     
@@ -108,6 +110,8 @@
 #endif
     
     Vector<DeferredDecommit> m_deferredDecommits;
+
+    bool m_isInMiniMode { false };
 };
 
 } // namespace bmalloc

Modified: trunk/Source/bmalloc/bmalloc/Sizes.h (232268 => 232269)


--- trunk/Source/bmalloc/bmalloc/Sizes.h	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/bmalloc/Sizes.h	2018-05-29 18:56:05 UTC (rev 232269)
@@ -71,8 +71,6 @@
     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)

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.cpp (232268 => 232269)


--- trunk/Source/bmalloc/bmalloc/bmalloc.cpp	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.cpp	2018-05-29 18:56:05 UTC (rev 232269)
@@ -116,5 +116,10 @@
     heap.externalDecommit(object, size);
 }
 
+void enableMiniMode()
+{
+    PerProcess<Scavenger>::get()->enableMiniMode();
+}
+
 } } // namespace bmalloc::api
 

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.h (232268 => 232269)


--- trunk/Source/bmalloc/bmalloc/bmalloc.h	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.h	2018-05-29 18:56:05 UTC (rev 232269)
@@ -121,5 +121,7 @@
 BEXPORT void setScavengerThreadQOSClass(qos_class_t overrideClass);
 #endif
 
+BEXPORT void enableMiniMode();
+
 } // namespace api
 } // namespace bmalloc

Modified: trunk/Tools/ChangeLog (232268 => 232269)


--- trunk/Tools/ChangeLog	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Tools/ChangeLog	2018-05-29 18:56:05 UTC (rev 232269)
@@ -1,3 +1,15 @@
+2018-05-29  Saam Barati  <sbar...@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_...@apple.com>
 
         Unable to remove IndexedDB Databases with Cocoa API removeDataOfTypes

Modified: trunk/Tools/Scripts/run-testmem (232268 => 232269)


--- trunk/Tools/Scripts/run-testmem	2018-05-29 18:32:00 UTC (rev 232268)
+++ trunk/Tools/Scripts/run-testmem	2018-05-29 18:56:05 UTC (rev 232269)
@@ -133,7 +133,12 @@
 
 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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to