Title: [194204] trunk/Source
Revision
194204
Author
[email protected]
Date
2015-12-16 18:55:02 -0800 (Wed, 16 Dec 2015)

Log Message

Give kernel VM some hints about non-live memory-cached resources.
<https://webkit.org/b/152362>

Reviewed by Geoffrey Garen.

Source/WebCore:

When a file-backed CachedResource has no live clients left, and is only being kept alive
because it's cached in the MemoryCache, give the OS a hint that we probably won't need
that memory very soon.

Normally this doesn't do anything, but in case the system comes under memory pressure,
the kernel can prioritize eviction of such clean-but-unneeded pages, which prevents us
from throwing other processes under the bus too soon.

* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::deleteIfPossible):
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::hintMemoryNotNeededSoon):
* platform/SharedBuffer.h:
* platform/cf/SharedBufferCF.cpp:
(WebCore::SharedBuffer::hintMemoryNotNeededSoon):

Source/WTF:

Add an API to OSAllocator for hinting to the OS that a range of memory
is not expected to be used anytime soon.

* wtf/OSAllocator.h:
* wtf/OSAllocatorPosix.cpp:
(WTF::OSAllocator::hintMemoryNotNeededSoon):
* wtf/OSAllocatorWin.cpp:
(WTF::OSAllocator::hintMemoryNotNeededSoon):
* wtf/Platform.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (194203 => 194204)


--- trunk/Source/WTF/ChangeLog	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WTF/ChangeLog	2015-12-17 02:55:02 UTC (rev 194204)
@@ -1,3 +1,20 @@
+2015-12-16  Andreas Kling  <[email protected]>
+
+        Give kernel VM some hints about non-live memory-cached resources.
+        <https://webkit.org/b/152362>
+
+        Reviewed by Geoffrey Garen.
+
+        Add an API to OSAllocator for hinting to the OS that a range of memory
+        is not expected to be used anytime soon.
+
+        * wtf/OSAllocator.h:
+        * wtf/OSAllocatorPosix.cpp:
+        (WTF::OSAllocator::hintMemoryNotNeededSoon):
+        * wtf/OSAllocatorWin.cpp:
+        (WTF::OSAllocator::hintMemoryNotNeededSoon):
+        * wtf/Platform.h:
+
 2015-12-16  Alex Christensen  <[email protected]>
 
         Fix internal Windows build

Modified: trunk/Source/WTF/wtf/OSAllocator.h (194203 => 194204)


--- trunk/Source/WTF/wtf/OSAllocator.h	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WTF/wtf/OSAllocator.h	2015-12-17 02:55:02 UTC (rev 194204)
@@ -69,6 +69,9 @@
     // This interface is provided since it may be possible to optimize this operation on some platforms.
     template<typename T>
     static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = UnknownUsage, bool writable = true, bool executable = false);
+
+    // Hint to the OS that an address range is not expected to be accessed anytime soon.
+    WTF_EXPORT_PRIVATE static void hintMemoryNotNeededSoon(void*, size_t);
 };
 
 inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize, Usage usage, bool writable, bool executable)

Modified: trunk/Source/WTF/wtf/OSAllocatorPosix.cpp (194203 => 194204)


--- trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WTF/wtf/OSAllocatorPosix.cpp	2015-12-17 02:55:02 UTC (rev 194204)
@@ -164,6 +164,16 @@
 #endif
 }
 
+void OSAllocator::hintMemoryNotNeededSoon(void* address, size_t bytes)
+{
+#if HAVE(MADV_DONTNEED)
+    while (madvise(address, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
+#else
+    UNUSED_PARAM(address);
+    UNUSED_PARAM(bytes);
+#endif
+}
+
 void OSAllocator::releaseDecommitted(void* address, size_t bytes)
 {
     int result = munmap(address, bytes);

Modified: trunk/Source/WTF/wtf/OSAllocatorWin.cpp (194203 => 194204)


--- trunk/Source/WTF/wtf/OSAllocatorWin.cpp	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WTF/wtf/OSAllocatorWin.cpp	2015-12-17 02:55:02 UTC (rev 194204)
@@ -93,6 +93,10 @@
         CRASH();
 }
 
+void OSAllocator::hintMemoryNotNeededSoon(void*, size_t)
+{
+}
+
 } // namespace WTF
 
 #endif // OS(WINDOWS)

Modified: trunk/Source/WTF/wtf/Platform.h (194203 => 194204)


--- trunk/Source/WTF/wtf/Platform.h	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WTF/wtf/Platform.h	2015-12-17 02:55:02 UTC (rev 194204)
@@ -630,6 +630,7 @@
 #define HAVE_DISPATCH_H 1
 #define HAVE_MADV_FREE 1
 #define HAVE_MADV_FREE_REUSE 1
+#define HAVE_MADV_DONTNEED 1
 #define HAVE_MERGESORT 1
 #define HAVE_PTHREAD_SETNAME_NP 1
 #define HAVE_READLINE 1

Modified: trunk/Source/WebCore/ChangeLog (194203 => 194204)


--- trunk/Source/WebCore/ChangeLog	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WebCore/ChangeLog	2015-12-17 02:55:02 UTC (rev 194204)
@@ -1,3 +1,26 @@
+2015-12-16  Andreas Kling  <[email protected]>
+
+        Give kernel VM some hints about non-live memory-cached resources.
+        <https://webkit.org/b/152362>
+
+        Reviewed by Geoffrey Garen.
+
+        When a file-backed CachedResource has no live clients left, and is only being kept alive
+        because it's cached in the MemoryCache, give the OS a hint that we probably won't need
+        that memory very soon.
+
+        Normally this doesn't do anything, but in case the system comes under memory pressure,
+        the kernel can prioritize eviction of such clean-but-unneeded pages, which prevents us
+        from throwing other processes under the bus too soon.
+
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::deleteIfPossible):
+        * platform/SharedBuffer.cpp:
+        (WebCore::SharedBuffer::hintMemoryNotNeededSoon):
+        * platform/SharedBuffer.h:
+        * platform/cf/SharedBufferCF.cpp:
+        (WebCore::SharedBuffer::hintMemoryNotNeededSoon):
+
 2015-12-16  Gyuyoung Kim  <[email protected]>
 
         Reduce PassRefPtr uses in dom - 2

Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (194203 => 194204)


--- trunk/Source/WebCore/loader/cache/CachedResource.cpp	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp	2015-12-17 02:55:02 UTC (rev 194204)
@@ -504,10 +504,14 @@
 
 bool CachedResource::deleteIfPossible()
 {
-    if (canDelete() && !inCache()) {
-        InspectorInstrumentation::willDestroyCachedResource(*this);
-        delete this;
-        return true;
+    if (canDelete()) {
+        if (!inCache()) {
+            InspectorInstrumentation::willDestroyCachedResource(*this);
+            delete this;
+            return true;
+        }
+        if (m_data)
+            m_data->hintMemoryNotNeededSoon();
     }
     return false;
 }

Modified: trunk/Source/WebCore/platform/SharedBuffer.cpp (194203 => 194204)


--- trunk/Source/WebCore/platform/SharedBuffer.cpp	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WebCore/platform/SharedBuffer.cpp	2015-12-17 02:55:02 UTC (rev 194204)
@@ -302,6 +302,12 @@
         m_buffer->data.clear();
 }
 
+#if !USE(CF)
+void SharedBuffer::hintMemoryNotNeededSoon()
+{
+}
+#endif
+
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
 
 void SharedBuffer::copyBufferAndClear(char* destination, unsigned bytesToCopy) const

Modified: trunk/Source/WebCore/platform/SharedBuffer.h (194203 => 194204)


--- trunk/Source/WebCore/platform/SharedBuffer.h	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WebCore/platform/SharedBuffer.h	2015-12-17 02:55:02 UTC (rev 194204)
@@ -126,6 +126,8 @@
         Vector<char> data;
     };
 
+    void hintMemoryNotNeededSoon();
+
 private:
     WEBCORE_EXPORT SharedBuffer();
     explicit SharedBuffer(unsigned);

Modified: trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp (194203 => 194204)


--- trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp	2015-12-17 02:26:06 UTC (rev 194203)
+++ trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp	2015-12-17 02:55:02 UTC (rev 194204)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "SharedBuffer.h"
 
+#include <wtf/OSAllocator.h>
 #include <wtf/cf/TypeCastsCF.h>
 
 namespace WebCore {
@@ -73,6 +74,13 @@
     return CFDataGetLength(m_cfData.get());
 }
 
+void SharedBuffer::hintMemoryNotNeededSoon()
+{
+    if (!hasPlatformData())
+        return;
+    OSAllocator::hintMemoryNotNeededSoon(const_cast<char*>(platformData()), platformDataSize());
+}
+
 void SharedBuffer::maybeTransferPlatformData()
 {
     if (!m_cfData)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to