Changeset 87228 in webkit


Ignore:
Timestamp:
May 24, 2011 4:43:15 PM (13 years ago)
Author:
msaboff@apple.com
Message:

2011-05-24 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Improve handling in WebCore of low memory situations
https://bugs.webkit.org/show_bug.cgi?id=61222

Added call to enable memory pressure handling.

  • WebView/WebView.mm: (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]):
  • WebView/WebViewInternal.h:

2011-05-24 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Improve handling in WebCore of low memory situations
https://bugs.webkit.org/show_bug.cgi?id=61222

Added new class, MemoryPressureHandler, to platform to respond to low
system memory events. Added Mac specific implementation that reduces the
page cache, NSURL cache, WebCore cache by half their current usage
and then garbage collects. This can allow Safari to continue operating
in a low memory situation with minimal paging.
Split up prune operations in MemoryCache to allow for pruning to a
specific actual size to support this change.

No tests added as the functionality of WebKit wasn't changed.

  • GNUmakefile.list.am:
  • WebCore.exp.in:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::pruneLiveResources): (WebCore::MemoryCache::forcePruneLiveResources): (WebCore::MemoryCache::pruneLiveResourcesToTarget): (WebCore::MemoryCache::pruneDeadResources): (WebCore::MemoryCache::forcePruneDeadResources): (WebCore::MemoryCache::pruneDeadResourcesToTarget):
  • loader/cache/MemoryCache.h: (WebCore::MemoryCache::forcePrune):
  • platform/MemoryPressureHandler.cpp: Added. (WebCore::memoryPressureHandler): (WebCore::MemoryPressureHandler::MemoryPressureHandler): (WebCore::MemoryPressureHandler::install): (WebCore::MemoryPressureHandler::respondToMemoryPressure):
  • platform/MemoryPressureHandler.h: Added.
  • platform/mac/MemoryPressureHandler.mm: Added. (WebCore::MemoryPressureHandler::install): (WebCore::MemoryPressureHandler::respondToMemoryPressure):

2011-05-24 Michael Saboff <msaboff@apple.com>

Reviewed by Geoffrey Garen.

Improve handling in WebCore of low memory situations
https://bugs.webkit.org/show_bug.cgi?id=61222

Added call to enable memory pressure handling for Mac case.

  • WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess):
  • WebProcess/WebProcess.h:
  • WebProcess/mac/WebProcessMac.mm: (WebKit::WebProcess::platformInitializeWebProcess):
Location:
trunk/Source
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87227 r87228  
     12011-05-24  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Improve handling in WebCore of low memory situations
     6        https://bugs.webkit.org/show_bug.cgi?id=61222
     7
     8        Added new class, MemoryPressureHandler, to platform to respond to low
     9        system memory events. Added Mac specific implementation that reduces the
     10        page cache, NSURL cache, WebCore cache by half their current usage
     11        and then garbage collects.  This can allow Safari to continue operating
     12        in a low memory situation with minimal paging.
     13        Split up prune operations in MemoryCache to allow for pruning to a
     14        specific actual size to support this change.
     15
     16        No tests added as the functionality of WebKit wasn't changed.
     17
     18        * GNUmakefile.list.am:
     19        * WebCore.exp.in:
     20        * WebCore.gypi:
     21        * WebCore.pro:
     22        * WebCore.vcproj/WebCore.vcproj:
     23        * WebCore.xcodeproj/project.pbxproj:
     24        * loader/cache/MemoryCache.cpp:
     25        (WebCore::MemoryCache::pruneLiveResources):
     26        (WebCore::MemoryCache::forcePruneLiveResources):
     27        (WebCore::MemoryCache::pruneLiveResourcesToTarget):
     28        (WebCore::MemoryCache::pruneDeadResources):
     29        (WebCore::MemoryCache::forcePruneDeadResources):
     30        (WebCore::MemoryCache::pruneDeadResourcesToTarget):
     31        * loader/cache/MemoryCache.h:
     32        (WebCore::MemoryCache::forcePrune):
     33        * platform/MemoryPressureHandler.cpp: Added.
     34        (WebCore::memoryPressureHandler):
     35        (WebCore::MemoryPressureHandler::MemoryPressureHandler):
     36        (WebCore::MemoryPressureHandler::install):
     37        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
     38        * platform/MemoryPressureHandler.h: Added.
     39        * platform/mac/MemoryPressureHandler.mm: Added.
     40        (WebCore::MemoryPressureHandler::install):
     41        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
     42
    1432011-05-24  Kent Tamura  <tkent@chromium.org>
    244
  • trunk/Source/WebCore/GNUmakefile.list.am

    r87197 r87228  
    25402540        Source/WebCore/platform/MIMETypeRegistry.cpp \
    25412541        Source/WebCore/platform/MIMETypeRegistry.h \
     2542        Source/WebCore/platform/MemoryPressureHandler.cpp \
     2543        Source/WebCore/platform/MemoryPressureHandler.h \
    25422544        Source/WebCore/platform/mock/DeviceOrientationClientMock.cpp \
    25432545        Source/WebCore/platform/mock/DeviceOrientationClientMock.h \
  • trunk/Source/WebCore/WebCore.exp.in

    r87102 r87228  
    546546__ZN7WebCore20protocolIsJavaScriptERKN3WTF6StringE
    547547__ZN7WebCore21BackForwardController11itemAtIndexEi
     548__ZN7WebCore21memoryPressureHandlerEv
     549__ZN7WebCore21MemoryPressureHandler7installEv
    548550__ZN7WebCore21PlatformKeyboardEvent24disambiguateKeyDownEventENS0_4TypeEb
    549551__ZN7WebCore21PlatformKeyboardEventC1EP7NSEvent
  • trunk/Source/WebCore/WebCore.gypi

    r87197 r87228  
    764764            'platform/LocalizedStrings.h',
    765765            'platform/Logging.h',
     766            'platform/MemoryPressureHandler.h',
    766767            'platform/MIMETypeRegistry.h',
    767768            'platform/NotImplemented.h',
     
    35843585            'platform/LocalizedStrings.cpp',
    35853586            'platform/Logging.cpp',
     3587            'platform/MemoryPressureHandler.cpp',
    35863588            'platform/MIMETypeRegistry.cpp',
    35873589            'platform/Pasteboard.h',
  • trunk/Source/WebCore/WebCore.pro

    r87197 r87228  
    10221022    platform/LinkHash.cpp \
    10231023    platform/Logging.cpp \
     1024    platform/MemoryPressureHandler.cpp \
    10241025    platform/MIMETypeRegistry.cpp \
    10251026    platform/mock/DeviceOrientationClientMock.cpp \
     
    19981999    platform/Logging.h \
    19992000    platform/Language.h \
     2001    platfory/MemoryPressureHandler.h \
    20002002    platform/MIMETypeRegistry.h \
    20012003    platform/network/AuthenticationChallengeBase.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r87197 r87228  
    2609526095                        </File>
    2609626096                        <File
     26097                                RelativePath="..\platform\MemoryPressureHandler.cpp"
     26098                                >
     26099                        </File>
     26100                        <File
     26101                                RelativePath="..\platform\MemoryPressureHandler.h"
     26102                                >
     26103                        </File>
     26104                        <File
    2609726105                                RelativePath="..\platform\NotImplemented.h"
    2609826106                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r87197 r87228  
    14911491                656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14921492                656D37480ADBA5DE00A4554D /* SubresourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 656D37300ADBA5DE00A4554D /* SubresourceLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1493                6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 657EDA071385CB97004E0645 /* MemoryPressureHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1494                657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */; };
     1495                657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */; };
    14931496                6582A16309999D6D00BEEB6D /* SystemTimeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */; };
    14941497                658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53753 /* FrameLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    80698072                656D372B0ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NetscapePlugInStreamLoader.h; sourceTree = "<group>"; };
    80708073                656D37300ADBA5DE00A4554D /* SubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SubresourceLoader.h; sourceTree = "<group>"; };
     8074                657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryPressureHandler.cpp; sourceTree = "<group>"; };
     8075                657EDA071385CB97004E0645 /* MemoryPressureHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryPressureHandler.h; sourceTree = "<group>"; };
     8076                657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandlerMac.mm; sourceTree = "<group>"; };
    80718077                6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SystemTimeMac.cpp; sourceTree = "<group>"; };
    80728078                658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
     
    1415014156                                BC25B528131C6D3900180E10 /* LocalizedStringsMac.mm */,
    1415114157                                1402645D0AFDC19B005919E2 /* LoggingMac.mm */,
     14158                                657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */,
    1415214159                                BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
    1415314160                                A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */,
     
    1863418641                                A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
    1863518642                                A8239DFF09B3CF8A00B60641 /* Logging.h */,
     18643                                657EDA061385CB97004E0645 /* MemoryPressureHandler.cpp */,
     18644                                657EDA071385CB97004E0645 /* MemoryPressureHandler.h */,
    1863618645                                BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */,
    1863718646                                BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */,
     
    2292122930                                977E2E0F12F0FC9C00C13379 /* XSSFilter.h in Headers */,
    2292222931                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
     22932                                6571DCC81385E6A400702DD0 /* MemoryPressureHandler.h in Headers */,
    2292322933                                598365DD1355F557001B185D /* JSPositionCallback.h in Headers */,
    2292422934                                598365DF1355F562001B185D /* JSPositionErrorCallback.h in Headers */,
     
    2560525615                                977E2E0E12F0FC9C00C13379 /* XSSFilter.cpp in Sources */,
    2560625616                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
     25617                                657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */,
     25618                                657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */,
    2560725619                                598365E41355F604001B185D /* JSPositionCallback.cpp in Sources */,
    2560825620                                598365E61355F60D001B185D /* JSPositionErrorCallback.cpp in Sources */,
  • trunk/Source/WebCore/loader/cache/MemoryCache.cpp

    r84930 r87228  
    173173
    174174    unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
     175
     176    pruneLiveResourcesToSize(targetSize);
     177}
     178
     179void MemoryCache::PruneLiveResourcesToPercentage(float prunePercentage)
     180{
     181    if (!m_pruneEnabled)
     182        return;
     183
     184    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
     185        return;
     186
     187    unsigned currentSize = m_liveSize + m_deadSize;
     188    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
     189
     190    pruneLiveResourcesToSize(targetSize);
     191}
     192
     193void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize)
     194{
    175195    double currentTime = FrameView::currentPaintTimeStamp();
    176196    if (!currentTime) // In case prune is called directly, outside of a Frame paint.
     
    217237
    218238    unsigned targetSize = static_cast<unsigned>(capacity * cTargetPrunePercentage); // Cut by a percentage to avoid immediately pruning again.
     239    pruneDeadResourcesToSize(targetSize);
     240}
     241
     242void MemoryCache::PruneDeadResourcesToPercentage(float prunePercentage)
     243{
     244    if (!m_pruneEnabled)
     245        return;
     246
     247    if (prunePercentage < 0.0f  || prunePercentage > 0.95f)
     248        return;
     249
     250    unsigned currentSize = m_liveSize + m_deadSize;
     251    unsigned targetSize = static_cast<unsigned>(currentSize * prunePercentage);
     252
     253    pruneDeadResourcesToSize(targetSize);
     254}
     255
     256void MemoryCache::pruneDeadResourcesToSize(unsigned targetSize)
     257{
    219258    int size = m_allResources.size();
    220     
     259 
    221260    if (!m_inPruneDeadResources) {
    222261        // See if we have any purged resources we can evict.
  • trunk/Source/WebCore/loader/cache/MemoryCache.h

    r86325 r87228  
    140140    }
    141141
     142    void pruneToPercentage(float targetPercentLive)
     143    {
     144        PruneDeadResourcesToPercentage(targetPercentLive); // Prune dead first, in case it was "borrowing" capacity from live.
     145        PruneLiveResourcesToPercentage(targetPercentLive);
     146    }
     147
    142148    void setDeadDecodedDataDeletionInterval(double interval) { m_deadDecodedDataDeletionInterval = interval; }
    143149    double deadDecodedDataDeletionInterval() const { return m_deadDecodedDataDeletionInterval; }
     
    183189    unsigned liveCapacity() const;
    184190    unsigned deadCapacity() const;
    185    
    186     void pruneDeadResources(); // Flush decoded and encoded data from resources not referenced by Web pages.
    187     void pruneLiveResources(); // Flush decoded data from resources still referenced by Web pages.
     191
     192    // pruneDead*() - Flush decoded and encoded data from resources not referenced by Web pages.
     193    // pruneLive*() - Flush decoded data from resources still referenced by Web pages.
     194    void pruneDeadResources(); // Automatically decide how much to prune.
     195    void pruneLiveResources();
     196    void PruneDeadResourcesToPercentage(float prunePercentage);
     197    void PruneLiveResourcesToPercentage(float prunePercentage);
     198    void pruneDeadResourcesToSize(unsigned targetSize);
     199    void pruneLiveResourcesToSize(unsigned targetSize);
    188200
    189201    bool makeResourcePurgeable(CachedResource*);
  • trunk/Source/WebKit/mac/ChangeLog

    r87213 r87228  
     12011-05-24  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Improve handling in WebCore of low memory situations
     6        https://bugs.webkit.org/show_bug.cgi?id=61222
     7
     8        Added call to enable memory pressure handling.
     9
     10        * WebView/WebView.mm:
     11        (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]):
     12        * WebView/WebViewInternal.h:
     13
    1142011-05-24  Jay Civelli  <jcivelli@chromium.org>
    215
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r86415 r87228  
    139139#import <WebCore/JSNodeList.h>
    140140#import <WebCore/Logging.h>
     141#import <WebCore/MemoryPressureHandler.h>
    141142#import <WebCore/MIMETypeRegistry.h>
    142143#import <WebCore/NodeList.h>
     
    799800    [[self preferences] _postPreferencesChangedAPINotification];
    800801
     802    memoryPressureHandler().install();
     803
    801804    if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION)) {
    802805        // Originally, we allowed all local loads.
  • trunk/Source/WebKit2/ChangeLog

    r87221 r87228  
     12011-05-24  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Improve handling in WebCore of low memory situations
     6        https://bugs.webkit.org/show_bug.cgi?id=61222
     7
     8        Added call to enable memory pressure handling for Mac case.
     9
     10        * WebProcess/WebProcess.cpp:
     11        (WebKit::WebProcess::initializeWebProcess):
     12        * WebProcess/WebProcess.h:
     13        * WebProcess/mac/WebProcessMac.mm:
     14        (WebKit::WebProcess::platformInitializeWebProcess):
     15
    1162011-05-24  Brady Eidson  <beidson@apple.com>
    217
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r86967 r87228  
    5959#include <WebCore/Logging.h>
    6060#include <WebCore/MemoryCache.h>
     61#include <WebCore/MemoryPressureHandler.h>
    6162#include <WebCore/Page.h>
    6263#include <WebCore/PageCache.h>
     
    164165
    165166    platformInitializeWebProcess(parameters, arguments);
     167
     168    memoryPressureHandler().install();
    166169
    167170    RefPtr<APIObject> injectedBundleInitializationUserData;
Note: See TracChangeset for help on using the changeset viewer.