Title: [215775] trunk/Source
Revision
215775
Author
msab...@apple.com
Date
2017-04-25 17:39:22 -0700 (Tue, 25 Apr 2017)

Log Message

Call bmalloc scavenger first when handling a memory pressure event
https://bugs.webkit.org/show_bug.cgi?id=171289

Reviewed by Geoffrey Garen.

Source/bmalloc:

Registered a critical memory pressure handler.  We add this handler in addition to the
call to release bmalloc memory in the WebCore releaseMemory handler for the case of
JSC API users that don't use WebCore.  When both handlers are in the process, it is
basically a race.  One will win, but the loser won't do any more work, so it is harmless.

* bmalloc/Heap.cpp:
(bmalloc::Heap::Heap):

Source/WebCore:

Let bmalloc free any pages to the OS that it can before doing anything else.

* page/MemoryRelease.cpp:
(WebCore::releaseMemory):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (215774 => 215775)


--- trunk/Source/WebCore/ChangeLog	2017-04-26 00:38:11 UTC (rev 215774)
+++ trunk/Source/WebCore/ChangeLog	2017-04-26 00:39:22 UTC (rev 215775)
@@ -1,3 +1,15 @@
+2017-04-25  Michael Saboff  <msab...@apple.com>
+
+        Call bmalloc scavenger first when handling a memory pressure event
+        https://bugs.webkit.org/show_bug.cgi?id=171289
+
+        Reviewed by Geoffrey Garen.
+
+        Let bmalloc free any pages to the OS that it can before doing anything else.
+
+        * page/MemoryRelease.cpp:
+        (WebCore::releaseMemory):
+
 2017-04-25  Dean Jackson  <d...@apple.com>
 
         Skip WebKitAdditions for Safari Technology Preview media controls

Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (215774 => 215775)


--- trunk/Source/WebCore/page/MemoryRelease.cpp	2017-04-26 00:38:11 UTC (rev 215774)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp	2017-04-26 00:39:22 UTC (rev 215775)
@@ -110,6 +110,9 @@
 {
     TraceScope scope(MemoryPressureHandlerStart, MemoryPressureHandlerEnd, static_cast<uint64_t>(critical), static_cast<uint64_t>(synchronous));
 
+    // Return unused pages back to the OS now as this will likely give us a little memory to work with.
+    WTF::releaseFastMallocFreeMemory();
+
     if (critical == Critical::Yes)
         releaseCriticalMemory(synchronous);
 

Modified: trunk/Source/bmalloc/ChangeLog (215774 => 215775)


--- trunk/Source/bmalloc/ChangeLog	2017-04-26 00:38:11 UTC (rev 215774)
+++ trunk/Source/bmalloc/ChangeLog	2017-04-26 00:39:22 UTC (rev 215775)
@@ -1,3 +1,18 @@
+2017-04-25  Michael Saboff  <msab...@apple.com>
+
+        Call bmalloc scavenger first when handling a memory pressure event
+        https://bugs.webkit.org/show_bug.cgi?id=171289
+
+        Reviewed by Geoffrey Garen.
+
+        Registered a critical memory pressure handler.  We add this handler in addition to the
+        call to release bmalloc memory in the WebCore releaseMemory handler for the case of
+        JSC API users that don't use WebCore.  When both handlers are in the process, it is
+        basically a race.  One will win, but the loser won't do any more work, so it is harmless.
+
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::Heap):
+
 2017-04-14  Mark Lam  <mark....@apple.com>
 
         Update architectures in xcconfig files.

Modified: trunk/Source/bmalloc/bmalloc/Heap.cpp (215774 => 215775)


--- trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-04-26 00:38:11 UTC (rev 215774)
+++ trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-04-26 00:39:22 UTC (rev 215775)
@@ -30,6 +30,10 @@
 #include "PerProcess.h"
 #include "SmallLine.h"
 #include "SmallPage.h"
+#if BOS(DARWIN)
+#include "bmalloc.h"
+#include <dispatch/dispatch.h>
+#endif
 #include <thread>
 
 namespace bmalloc {
@@ -48,6 +52,15 @@
     
     if (m_environment.isDebugHeapEnabled())
         m_debugHeap = PerProcess<DebugHeap>::get();
+
+#if BOS(DARWIN)
+    auto queue = dispatch_queue_create("WebKit Malloc Memory Pressure Handler", DISPATCH_QUEUE_SERIAL);
+    auto source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_CRITICAL, queue);
+    dispatch_source_set_event_handler(source, ^{
+        api::scavenge();
+    });
+    dispatch_resume(source);
+#endif
 }
 
 void Heap::initializeLineMetadata()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to