Changeset 194204 in webkit


Ignore:
Timestamp:
Dec 16, 2015 6:55:02 PM (8 years ago)
Author:
akling@apple.com
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:
Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r194183 r194204  
     12015-12-16  Andreas Kling  <akling@apple.com>
     2
     3        Give kernel VM some hints about non-live memory-cached resources.
     4        <https://webkit.org/b/152362>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add an API to OSAllocator for hinting to the OS that a range of memory
     9        is not expected to be used anytime soon.
     10
     11        * wtf/OSAllocator.h:
     12        * wtf/OSAllocatorPosix.cpp:
     13        (WTF::OSAllocator::hintMemoryNotNeededSoon):
     14        * wtf/OSAllocatorWin.cpp:
     15        (WTF::OSAllocator::hintMemoryNotNeededSoon):
     16        * wtf/Platform.h:
     17
    1182015-12-16  Alex Christensen  <achristensen@webkit.org>
    219
  • trunk/Source/WTF/wtf/OSAllocator.h

    r173949 r194204  
    7070    template<typename T>
    7171    static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = UnknownUsage, bool writable = true, bool executable = false);
     72
     73    // Hint to the OS that an address range is not expected to be accessed anytime soon.
     74    WTF_EXPORT_PRIVATE static void hintMemoryNotNeededSoon(void*, size_t);
    7275};
    7376
  • trunk/Source/WTF/wtf/OSAllocatorPosix.cpp

    r184245 r194204  
    165165}
    166166
     167void OSAllocator::hintMemoryNotNeededSoon(void* address, size_t bytes)
     168{
     169#if HAVE(MADV_DONTNEED)
     170    while (madvise(address, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
     171#else
     172    UNUSED_PARAM(address);
     173    UNUSED_PARAM(bytes);
     174#endif
     175}
     176
    167177void OSAllocator::releaseDecommitted(void* address, size_t bytes)
    168178{
  • trunk/Source/WTF/wtf/OSAllocatorWin.cpp

    r174412 r194204  
    9494}
    9595
     96void OSAllocator::hintMemoryNotNeededSoon(void*, size_t)
     97{
     98}
     99
    96100} // namespace WTF
    97101
  • trunk/Source/WTF/wtf/Platform.h

    r193873 r194204  
    631631#define HAVE_MADV_FREE 1
    632632#define HAVE_MADV_FREE_REUSE 1
     633#define HAVE_MADV_DONTNEED 1
    633634#define HAVE_MERGESORT 1
    634635#define HAVE_PTHREAD_SETNAME_NP 1
  • trunk/Source/WebCore/ChangeLog

    r194201 r194204  
     12015-12-16  Andreas Kling  <akling@apple.com>
     2
     3        Give kernel VM some hints about non-live memory-cached resources.
     4        <https://webkit.org/b/152362>
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        When a file-backed CachedResource has no live clients left, and is only being kept alive
     9        because it's cached in the MemoryCache, give the OS a hint that we probably won't need
     10        that memory very soon.
     11
     12        Normally this doesn't do anything, but in case the system comes under memory pressure,
     13        the kernel can prioritize eviction of such clean-but-unneeded pages, which prevents us
     14        from throwing other processes under the bus too soon.
     15
     16        * loader/cache/CachedResource.cpp:
     17        (WebCore::CachedResource::deleteIfPossible):
     18        * platform/SharedBuffer.cpp:
     19        (WebCore::SharedBuffer::hintMemoryNotNeededSoon):
     20        * platform/SharedBuffer.h:
     21        * platform/cf/SharedBufferCF.cpp:
     22        (WebCore::SharedBuffer::hintMemoryNotNeededSoon):
     23
    1242015-12-16  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    225
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r194017 r194204  
    505505bool CachedResource::deleteIfPossible()
    506506{
    507     if (canDelete() && !inCache()) {
    508         InspectorInstrumentation::willDestroyCachedResource(*this);
    509         delete this;
    510         return true;
     507    if (canDelete()) {
     508        if (!inCache()) {
     509            InspectorInstrumentation::willDestroyCachedResource(*this);
     510            delete this;
     511            return true;
     512        }
     513        if (m_data)
     514            m_data->hintMemoryNotNeededSoon();
    511515    }
    512516    return false;
  • trunk/Source/WebCore/platform/SharedBuffer.cpp

    r185106 r194204  
    303303}
    304304
     305#if !USE(CF)
     306void SharedBuffer::hintMemoryNotNeededSoon()
     307{
     308}
     309#endif
     310
    305311#if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
    306312
  • trunk/Source/WebCore/platform/SharedBuffer.h

    r194017 r194204  
    127127    };
    128128
     129    void hintMemoryNotNeededSoon();
     130
    129131private:
    130132    WEBCORE_EXPORT SharedBuffer();
  • trunk/Source/WebCore/platform/cf/SharedBufferCF.cpp

    r194017 r194204  
    2929#include "SharedBuffer.h"
    3030
     31#include <wtf/OSAllocator.h>
    3132#include <wtf/cf/TypeCastsCF.h>
    3233
     
    7273{
    7374    return CFDataGetLength(m_cfData.get());
     75}
     76
     77void SharedBuffer::hintMemoryNotNeededSoon()
     78{
     79    if (!hasPlatformData())
     80        return;
     81    OSAllocator::hintMemoryNotNeededSoon(const_cast<char*>(platformData()), platformDataSize());
    7482}
    7583
Note: See TracChangeset for help on using the changeset viewer.