Changeset 203857 in webkit


Ignore:
Timestamp:
Jul 28, 2016 10:22:14 PM (8 years ago)
Author:
Carlos Garcia Campos
Message:

Split calculateCacheSizes in two methods
https://bugs.webkit.org/show_bug.cgi?id=160237

Reviewed by Darin Adler.

Source/WebCore:

Rename getVolumeFreeSizeForPath as volumeFreeSizeForPath and make it available to all platforms adding an
implementation for mac.

  • platform/FileSystem.h:
  • platform/efl/FileSystemEfl.cpp:

(WebCore::volumeFreeSizeForPath):
(WebCore::getVolumeFreeSizeForPath): Deleted.

  • platform/glib/FileSystemGlib.cpp:

(WebCore::volumeFreeSizeForPath):
(WebCore::getVolumeFreeSizeForPath): Deleted.

  • platform/mac/FileSystemMac.mm:

(WebCore::volumeFreeSizeForPath):

  • platform/win/FileSystemWin.cpp:

(WebCore::volumeFreeSizeForPath):

Source/WebKit2:

It's used to calculate memory and disk cache sizes, but only the web process is interested in memory caches, and
the network process in disk cache. We can also avoid a lot of duplicated code between ports to set the cache model.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::setCacheModel): Use calculateURLCacheSizes to set the disk cache size and call
platformSetURLCacheSize if not set to allow ports to setup platform specific cache.

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/cocoa/NetworkProcessCocoa.mm:

(WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
(WebKit::volumeFreeSize): Deleted.
(WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().

  • NetworkProcess/soup/NetworkProcessSoup.cpp:

(WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
(WebKit::getCacheDiskFreeSize): Deleted.
(WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().

  • Shared/CacheModel.cpp:

(WebKit::calculateMemoryCacheSizes): Calculate the memory and page cache sizes.
(WebKit::calculateURLCacheSizes): Calculate the disk cache size.
(WebKit::calculateCacheSizes): Deleted.

  • Shared/CacheModel.h:
  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess): Tell the page cache to clear backing stores for GTK+ port too. This was done before when
setting the cache model.
(WebKit::WebProcess::setCacheModel): Use calculateMemoryCacheSizes to setup memory caches and call
platformSetCacheModel to allow ports do more setup according to the cache model.
(WebKit::WebProcess::clearResourceCaches): Deleted.

  • WebProcess/WebProcess.h:
  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
(WebKit::volumeFreeSize): Deleted.
(WebKit::WebProcess::platformClearResourceCaches): Deleted.

  • WebProcess/soup/WebProcessSoup.cpp:

(WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
(WebKit::WebProcess::platformInitializeWebProcess):
(WebKit::WebProcess::platformClearResourceCaches): Deleted.

Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r203855 r203857  
     12016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Split calculateCacheSizes in two methods
     4        https://bugs.webkit.org/show_bug.cgi?id=160237
     5
     6        Reviewed by Darin Adler.
     7
     8        Rename getVolumeFreeSizeForPath as volumeFreeSizeForPath and make it available to all platforms adding an
     9        implementation for mac.
     10
     11        * platform/FileSystem.h:
     12        * platform/efl/FileSystemEfl.cpp:
     13        (WebCore::volumeFreeSizeForPath):
     14        (WebCore::getVolumeFreeSizeForPath): Deleted.
     15        * platform/glib/FileSystemGlib.cpp:
     16        (WebCore::volumeFreeSizeForPath):
     17        (WebCore::getVolumeFreeSizeForPath): Deleted.
     18        * platform/mac/FileSystemMac.mm:
     19        (WebCore::volumeFreeSizeForPath):
     20        * platform/win/FileSystemWin.cpp:
     21        (WebCore::volumeFreeSizeForPath):
     22
    1232016-07-28  Myles C. Maxfield  <mmaxfield@apple.com>
    224
  • trunk/Source/WebCore/platform/FileSystem.h

    r202190 r203857  
    146146WEBCORE_EXPORT String pathGetFileName(const String&);
    147147WEBCORE_EXPORT String directoryName(const String&);
     148WEBCORE_EXPORT bool getVolumeFreeSpace(const String&, uint64_t&);
    148149
    149150WEBCORE_EXPORT void setMetadataURL(String& URLString, const String& referrer, const String& path);
     
    203204CString sharedResourcesPath();
    204205#endif
    205 #if USE(SOUP)
    206 uint64_t getVolumeFreeSizeForPath(const char*);
    207 #endif
    208206
    209207#if PLATFORM(WIN)
  • trunk/Source/WebCore/platform/efl/FileSystemEfl.cpp

    r200168 r203857  
    8989}
    9090
    91 uint64_t getVolumeFreeSizeForPath(const char* path)
     91bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
    9292{
     93    CString fsRep = fileSystemRepresentation(path);
     94    if (!fsRep.data() || fsRep.data()[0] == '\0')
     95        return false;
     96
    9397    struct statvfs buf;
    94     if (statvfs(path, &buf) < 0)
    95         return 0;
     98    if (statvfs(fsRep.data(), &buf) < 0)
     99        return false;
    96100
    97     return static_cast<uint64_t>(buf.f_bavail) * buf.f_bsize;
     101    freeSpace = static_cast<uint64_t>(buf.f_bavail) * buf.f_bsize;
     102    return true;
    98103}
    99104
  • trunk/Source/WebCore/platform/glib/FileSystemGlib.cpp

    r201796 r203857  
    233233}
    234234
    235 uint64_t getVolumeFreeSizeForPath(const char* path)
    236 {
    237     GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path));
     235bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
     236{
     237    GUniquePtr<gchar> filename = unescapedFilename(path);
     238    if (!filename)
     239        return false;
     240
     241    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(filename.get()));
    238242    GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_filesystem_info(file.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE, 0, 0));
    239243    if (!fileInfo)
    240         return 0;
    241 
    242     return g_file_info_get_attribute_uint64(fileInfo.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
     244        return false;
     245
     246    freeSpace = g_file_info_get_attribute_uint64(fileInfo.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
     247    return !!freeSpace;
    243248}
    244249
  • trunk/Source/WebCore/platform/mac/FileSystemMac.mm

    r192583 r203857  
    9999}
    100100
     101bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace)
     102{
     103    NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:(NSString *)path error:NULL];
     104    if (!fileSystemAttributesDictionary)
     105        return false;
     106    freeSpace = [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
     107    return true;
     108}
     109
    101110#if !PLATFORM(IOS)
    102111bool deleteEmptyDirectory(const String& path)
  • trunk/Source/WebCore/platform/win/FileSystemWin.cpp

    r200036 r203857  
    448448}
    449449
     450bool getVolumeFreeSpace(const String&, uint64_t&)
     451{
     452    notImplemented();
     453    return false;
     454}
     455
    450456} // namespace WebCore
  • trunk/Source/WebKit2/ChangeLog

    r203856 r203857  
     12016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Split calculateCacheSizes in two methods
     4        https://bugs.webkit.org/show_bug.cgi?id=160237
     5
     6        Reviewed by Darin Adler.
     7
     8        It's used to calculate memory and disk cache sizes, but only the web process is interested in memory caches, and
     9        the network process in disk cache. We can also avoid a lot of duplicated code between ports to set the cache model.
     10
     11        * NetworkProcess/NetworkProcess.cpp:
     12        (WebKit::NetworkProcess::setCacheModel): Use calculateURLCacheSizes to set the disk cache size and call
     13        platformSetURLCacheSize if not set to allow ports to setup platform specific cache.
     14        * NetworkProcess/NetworkProcess.h:
     15        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
     16        (WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
     17        (WebKit::volumeFreeSize): Deleted.
     18        (WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
     19        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     20        (WebKit::NetworkProcess::platformSetURLCacheSize): Remove common code that is now in cross-platform file.
     21        (WebKit::getCacheDiskFreeSize): Deleted.
     22        (WebKit::NetworkProcess::platformSetCacheModel): Renamed to platformSetURLCacheSize().
     23        * Shared/CacheModel.cpp:
     24        (WebKit::calculateMemoryCacheSizes): Calculate the memory and page cache sizes.
     25        (WebKit::calculateURLCacheSizes): Calculate the disk cache size.
     26        (WebKit::calculateCacheSizes): Deleted.
     27        * Shared/CacheModel.h:
     28        * WebProcess/WebProcess.cpp:
     29        (WebKit::WebProcess): Tell the page cache to clear backing stores for GTK+ port too. This was done before when
     30        setting the cache model.
     31        (WebKit::WebProcess::setCacheModel): Use calculateMemoryCacheSizes to setup memory caches and call
     32        platformSetCacheModel to allow ports do more setup according to the cache model.
     33        (WebKit::WebProcess::clearResourceCaches): Deleted.
     34        * WebProcess/WebProcess.h:
     35        * WebProcess/cocoa/WebProcessCocoa.mm:
     36        (WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
     37        (WebKit::volumeFreeSize): Deleted.
     38        (WebKit::WebProcess::platformClearResourceCaches): Deleted.
     39        * WebProcess/soup/WebProcessSoup.cpp:
     40        (WebKit::WebProcess::platformSetCacheModel): Remove common code that is now in cross-platform file.
     41        (WebKit::WebProcess::platformInitializeWebProcess):
     42        (WebKit::WebProcess::platformClearResourceCaches): Deleted.
     43
    1442016-07-28  Carlos Garcia Campos  <cgarcia@igalia.com>
    245
  • trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp

    r203749 r203857  
    539539    CacheModel cacheModel = static_cast<CacheModel>(cm);
    540540
    541     if (!m_hasSetCacheModel || cacheModel != m_cacheModel) {
    542         m_hasSetCacheModel = true;
    543         m_cacheModel = cacheModel;
    544         platformSetCacheModel(cacheModel);
    545     }
     541    if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
     542        return;
     543
     544    m_hasSetCacheModel = true;
     545    m_cacheModel = cacheModel;
     546
     547    unsigned urlCacheMemoryCapacity = 0;
     548    uint64_t urlCacheDiskCapacity = 0;
     549    uint64_t diskFreeSize = 0;
     550    if (WebCore::getVolumeFreeSpace(m_diskCacheDirectory, diskFreeSize)) {
     551        // As a fudge factor, use 1000 instead of 1024, in case the reported byte
     552        // count doesn't align exactly to a megabyte boundary.
     553        diskFreeSize /= KB * 1000;
     554        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     555    }
     556
     557    if (m_diskCacheSizeOverride >= 0)
     558        urlCacheDiskCapacity = m_diskCacheSizeOverride;
     559
     560#if ENABLE(NETWORK_CACHE)
     561    auto& networkCache = NetworkCache::singleton();
     562    if (networkCache.isEnabled()) {
     563        networkCache.setCapacity(urlCacheDiskCapacity);
     564        return;
     565    }
     566#endif
     567
     568    platformSetURLCacheSize(urlCacheMemoryCapacity, urlCacheDiskCapacity);
    546569}
    547570
  • trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h

    r203342 r203857  
    198198
    199199    // Platform Helpers
    200     void platformSetCacheModel(CacheModel);
     200    void platformSetURLCacheSize(unsigned urlCacheMemoryCapacity, uint64_t urlCacheDiskCapacity);
    201201
    202202    // Connections to WebProcesses.
  • trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r198457 r203857  
    3939#import <WebCore/SecurityOriginData.h>
    4040#import <WebKitSystemInterface.h>
    41 #import <wtf/RAMSize.h>
    4241
    4342namespace WebKit {
     
    125124}
    126125
    127 static uint64_t volumeFreeSize(const String& path)
    128 {
    129     NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:(NSString *)path error:NULL];
    130     return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
    131 }
    132 
    133 void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
    134 {
    135     uint64_t memSize = ramSize() / 1024 / 1024;
    136 
    137     // As a fudge factor, use 1000 instead of 1024, in case the reported byte
    138     // count doesn't align exactly to a megabyte boundary.
    139     uint64_t diskFreeSize = volumeFreeSize(m_diskCacheDirectory) / 1024 / 1000;
    140 
    141     unsigned cacheTotalCapacity = 0;
    142     unsigned cacheMinDeadCapacity = 0;
    143     unsigned cacheMaxDeadCapacity = 0;
    144     auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    145     unsigned pageCacheCapacity = 0;
    146     unsigned long urlCacheMemoryCapacity = 0;
    147     unsigned long urlCacheDiskCapacity = 0;
    148 
    149     calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    150         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    151         pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    152 
    153     if (m_diskCacheSizeOverride >= 0)
    154         urlCacheDiskCapacity = m_diskCacheSizeOverride;
    155 
    156 #if ENABLE(NETWORK_CACHE)
    157     auto& networkCache = NetworkCache::singleton();
    158     if (networkCache.isEnabled()) {
    159         networkCache.setCapacity(urlCacheDiskCapacity);
    160         return;
    161     }
    162 #endif
     126void NetworkProcess::platformSetURLCacheSize(unsigned urlCacheMemoryCapacity, uint64_t urlCacheDiskCapacity)
     127{
    163128    NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
    164129    [nsurlCache setMemoryCapacity:urlCacheMemoryCapacity];
    165130    if (!m_diskCacheIsDisabledForTesting)
    166         [nsurlCache setDiskCapacity:std::max<unsigned long>(urlCacheDiskCapacity, [nsurlCache diskCapacity])]; // Don't shrink a big disk cache, since that would cause churn.
     131        [nsurlCache setDiskCapacity:std::max<uint64_t>(urlCacheDiskCapacity, [nsurlCache diskCapacity])]; // Don't shrink a big disk cache, since that would cause churn.
    167132}
    168133
  • trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

    r201267 r203857  
    4545
    4646namespace WebKit {
    47 
    48 #if !ENABLE(NETWORK_CACHE)
    49 static uint64_t getCacheDiskFreeSize(SoupCache* cache)
    50 {
    51     ASSERT(cache);
    52 
    53     GUniqueOutPtr<char> cacheDir;
    54     g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
    55     if (!cacheDir)
    56         return 0;
    57 
    58     return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
    59 }
    60 #endif
    6147
    6248void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
     
    10894}
    10995
    110 void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
     96void NetworkProcess::platformSetURLCacheSize(unsigned /*urlCacheMemoryCapacity*/, uint64_t urlCacheDiskCapacity)
    11197{
    112     unsigned cacheTotalCapacity = 0;
    113     unsigned cacheMinDeadCapacity = 0;
    114     unsigned cacheMaxDeadCapacity = 0;
    115     auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    116     unsigned pageCacheCapacity = 0;
    117 
    118     unsigned long urlCacheMemoryCapacity = 0;
    119     unsigned long urlCacheDiskCapacity = 0;
    120 
    121 #if ENABLE(NETWORK_CACHE)
    122     uint64_t diskFreeSize = WebCore::getVolumeFreeSizeForPath(m_diskCacheDirectory.utf8().data()) / WTF::MB;
    123 #else
     98#if !ENABLE(NETWORK_CACHE)
    12499    SoupCache* cache = SoupNetworkSession::defaultSession().cache();
    125     uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / WTF::MB;
    126 #endif
    127 
    128     uint64_t memSize = WTF::ramSize() / WTF::MB;
    129     calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    130         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    131         pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    132 
    133 #if ENABLE(NETWORK_CACHE)
    134     auto& networkCache = NetworkCache::singleton();
    135     if (networkCache.isEnabled())
    136         networkCache.setCapacity(urlCacheDiskCapacity);
    137 #else
    138100    if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
    139101        soup_cache_set_max_size(cache, urlCacheDiskCapacity);
     102#else
     103    UNUSED_PARAM(urlCacheDiskCapacity);
    140104#endif
    141105}
  • trunk/Source/WebKit2/Shared/CacheModel.cpp

    r201857 r203857  
    2828
    2929#include <algorithm>
     30#include <wtf/RAMSize.h>
     31#include <wtf/StdLibExtras.h>
    3032
    3133namespace WebKit {
    3234
    33 void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
    34     unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval,
    35     unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity)
     35void calculateMemoryCacheSizes(CacheModel cacheModel, unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval, unsigned& pageCacheCapacity)
    3636{
     37    uint64_t memorySize = ramSize() / MB;
     38
    3739    switch (cacheModel) {
    3840    case CacheModelDocumentViewer: {
     
    4244        // Object cache capacities (in bytes)
    4345        if (memorySize >= 2048)
    44             cacheTotalCapacity = 96 * 1024 * 1024;
     46            cacheTotalCapacity = 96 * MB;
    4547        else if (memorySize >= 1536)
    46             cacheTotalCapacity = 64 * 1024 * 1024;
    47         else if (memorySize >= 1024)
    48             cacheTotalCapacity = 32 * 1024 * 1024;
    49         else if (memorySize >= 512)
    50             cacheTotalCapacity = 16 * 1024 * 1024;
     48            cacheTotalCapacity = 64 * MB;
     49        else if (memorySize >= 1024)
     50            cacheTotalCapacity = 32 * MB;
     51        else if (memorySize >= 512)
     52            cacheTotalCapacity = 16 * MB;
    5153
    5254        cacheMinDeadCapacity = 0;
    5355        cacheMaxDeadCapacity = 0;
    54 
    55         // Foundation memory cache capacity (in bytes)
    56         urlCacheMemoryCapacity = 0;
    57 
    58         // Disk cache capacity (in bytes)
    59         urlCacheDiskCapacity = 0;
    6056
    6157        break;
     
    7268        // Object cache capacities (in bytes)
    7369        if (memorySize >= 2048)
    74             cacheTotalCapacity = 96 * 1024 * 1024;
     70            cacheTotalCapacity = 96 * MB;
    7571        else if (memorySize >= 1536)
    76             cacheTotalCapacity = 64 * 1024 * 1024;
    77         else if (memorySize >= 1024)
    78             cacheTotalCapacity = 32 * 1024 * 1024;
    79         else if (memorySize >= 512)
    80             cacheTotalCapacity = 16 * 1024 * 1024;
     72            cacheTotalCapacity = 64 * MB;
     73        else if (memorySize >= 1024)
     74            cacheTotalCapacity = 32 * MB;
     75        else if (memorySize >= 512)
     76            cacheTotalCapacity = 16 * MB;
    8177
    8278        cacheMinDeadCapacity = cacheTotalCapacity / 8;
    8379        cacheMaxDeadCapacity = cacheTotalCapacity / 4;
    84 
    85         // Foundation memory cache capacity (in bytes)
    86         if (memorySize >= 2048)
    87             urlCacheMemoryCapacity = 4 * 1024 * 1024;
    88         else if (memorySize >= 1024)
    89             urlCacheMemoryCapacity = 2 * 1024 * 1024;
    90         else if (memorySize >= 512)
    91             urlCacheMemoryCapacity = 1 * 1024 * 1024;
    92         else
    93             urlCacheMemoryCapacity =      512 * 1024;
    94 
    95         // Disk cache capacity (in bytes)
    96         if (diskFreeSize >= 16384)
    97             urlCacheDiskCapacity = 75 * 1024 * 1024;
    98         else if (diskFreeSize >= 8192)
    99             urlCacheDiskCapacity = 40 * 1024 * 1024;
    100         else if (diskFreeSize >= 4096)
    101             urlCacheDiskCapacity = 30 * 1024 * 1024;
    102         else
    103             urlCacheDiskCapacity = 20 * 1024 * 1024;
    10480
    10581        break;
     
    11692        // Object cache capacities (in bytes)
    11793        // (Testing indicates that value / MB depends heavily on content and
    118         // browsing pattern. Even growth above 128MB can have substantial 
     94        // browsing pattern. Even growth above 128MB can have substantial
    11995        // value / MB for some content / browsing patterns.)
    12096        if (memorySize >= 2048)
    121             cacheTotalCapacity = 128 * 1024 * 1024;
     97            cacheTotalCapacity = 128 * MB;
    12298        else if (memorySize >= 1536)
    123             cacheTotalCapacity = 96 * 1024 * 1024;
    124         else if (memorySize >= 1024)
    125             cacheTotalCapacity = 64 * 1024 * 1024;
    126         else if (memorySize >= 512)
    127             cacheTotalCapacity = 32 * 1024 * 1024;
     99            cacheTotalCapacity = 96 * MB;
     100        else if (memorySize >= 1024)
     101            cacheTotalCapacity = 64 * MB;
     102        else if (memorySize >= 512)
     103            cacheTotalCapacity = 32 * MB;
    128104
    129105        cacheMinDeadCapacity = cacheTotalCapacity / 4;
     
    136112        deadDecodedDataDeletionInterval = std::chrono::seconds { 60 };
    137113
     114        break;
     115    }
     116    default:
     117        ASSERT_NOT_REACHED();
     118    };
     119}
     120
     121void calculateURLCacheSizes(CacheModel cacheModel, uint64_t diskFreeSize, unsigned& urlCacheMemoryCapacity, uint64_t& urlCacheDiskCapacity)
     122{
     123    switch (cacheModel) {
     124    case CacheModelDocumentViewer: {
     125        // Foundation memory cache capacity (in bytes)
     126        urlCacheMemoryCapacity = 0;
     127
     128        // Disk cache capacity (in bytes)
     129        urlCacheDiskCapacity = 0;
     130
     131        break;
     132    }
     133    case CacheModelDocumentBrowser: {
     134        uint64_t memorySize = ramSize() / MB;
     135
     136        // Foundation memory cache capacity (in bytes)
     137        if (memorySize >= 2048)
     138            urlCacheMemoryCapacity = 4 * MB;
     139        else if (memorySize >= 1024)
     140            urlCacheMemoryCapacity = 2 * MB;
     141        else if (memorySize >= 512)
     142            urlCacheMemoryCapacity = 1 * MB;
     143        else
     144            urlCacheMemoryCapacity = 512 * KB;
     145
     146        // Disk cache capacity (in bytes)
     147        if (diskFreeSize >= 16384)
     148            urlCacheDiskCapacity = 75 * MB;
     149        else if (diskFreeSize >= 8192)
     150            urlCacheDiskCapacity = 40 * MB;
     151        else if (diskFreeSize >= 4096)
     152            urlCacheDiskCapacity = 30 * MB;
     153        else
     154            urlCacheDiskCapacity = 20 * MB;
     155
     156        break;
     157    }
     158    case CacheModelPrimaryWebBrowser: {
     159        uint64_t memorySize = ramSize() / MB;
     160
    138161#if PLATFORM(IOS)
    139162        if (memorySize >= 1024)
    140             urlCacheMemoryCapacity = 16 * 1024 * 1024;
    141         else
    142             urlCacheMemoryCapacity = 8 * 1024 * 1024;
     163            urlCacheMemoryCapacity = 16 * MB;
     164        else
     165            urlCacheMemoryCapacity = 8 * MB;
    143166#else
    144167        // Foundation memory cache capacity (in bytes)
    145168        // (These values are small because WebCore does most caching itself.)
    146169        if (memorySize >= 1024)
    147             urlCacheMemoryCapacity = 4 * 1024 * 1024;
    148         else if (memorySize >= 512)
    149             urlCacheMemoryCapacity = 2 * 1024 * 1024;
     170            urlCacheMemoryCapacity = 4 * MB;
     171        else if (memorySize >= 512)
     172            urlCacheMemoryCapacity = 2 * MB;
    150173        else if (memorySize >= 256)
    151             urlCacheMemoryCapacity = 1 * 1024 * 1024;
    152         else
    153             urlCacheMemoryCapacity =      512 * 1024;
     174            urlCacheMemoryCapacity = 1 * MB;
     175        else
     176            urlCacheMemoryCapacity = 512 * KB;
    154177#endif
    155178
    156179        // Disk cache capacity (in bytes)
    157180        if (diskFreeSize >= 16384)
    158             urlCacheDiskCapacity = 500 * 1024 * 1024;
     181            urlCacheDiskCapacity = 500 * MB;
    159182        else if (diskFreeSize >= 8192)
    160             urlCacheDiskCapacity = 250 * 1024 * 1024;
     183            urlCacheDiskCapacity = 250 * MB;
    161184        else if (diskFreeSize >= 4096)
    162             urlCacheDiskCapacity = 125 * 1024 * 1024;
     185            urlCacheDiskCapacity = 125 * MB;
    163186        else if (diskFreeSize >= 2048)
    164             urlCacheDiskCapacity = 100 * 1024 * 1024;
     187            urlCacheDiskCapacity = 100 * MB;
    165188        else if (diskFreeSize >= 1024)
    166             urlCacheDiskCapacity = 75 * 1024 * 1024;
    167         else
    168             urlCacheDiskCapacity = 50 * 1024 * 1024;
     189            urlCacheDiskCapacity = 75 * MB;
     190        else
     191            urlCacheDiskCapacity = 50 * MB;
    169192
    170193        break;
  • trunk/Source/WebKit2/Shared/CacheModel.h

    r169550 r203857  
    3838};
    3939
    40 void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
    41     unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval,
    42     unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
     40void calculateMemoryCacheSizes(CacheModel, unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, std::chrono::seconds& deadDecodedDataDeletionInterval, unsigned& pageCacheCapacity);
     41void calculateURLCacheSizes(CacheModel, uint64_t diskFreeSize, unsigned& urlCacheMemoryCapacity, uint64_t& urlCacheDiskCapacity);
    4342
    4443} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r203342 r203857  
    206206#endif
    207207
    208 #if PLATFORM(IOS)
     208#if PLATFORM(IOS) || PLATFORM(GTK)
    209209    PageCache::singleton().setShouldClearBackingStores(true);
    210210#endif
     
    530530    CacheModel cacheModel = static_cast<CacheModel>(cm);
    531531
    532     if (!m_hasSetCacheModel || cacheModel != m_cacheModel) {
    533         m_hasSetCacheModel = true;
    534         m_cacheModel = cacheModel;
    535         platformSetCacheModel(cacheModel);
    536     }
     532    if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
     533        return;
     534
     535    m_hasSetCacheModel = true;
     536    m_cacheModel = cacheModel;
     537
     538    unsigned cacheTotalCapacity = 0;
     539    unsigned cacheMinDeadCapacity = 0;
     540    unsigned cacheMaxDeadCapacity = 0;
     541    auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
     542    unsigned pageCacheSize = 0;
     543    calculateMemoryCacheSizes(cacheModel, cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval, pageCacheSize);
     544
     545    auto& memoryCache = MemoryCache::singleton();
     546    memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
     547    memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
     548    PageCache::singleton().setMaxSize(pageCacheSize);
     549
     550    platformSetCacheModel(cacheModel);
    537551}
    538552
     
    752766void WebProcess::clearResourceCaches(ResourceCachesToClear resourceCachesToClear)
    753767{
    754     platformClearResourceCaches(resourceCachesToClear);
    755 
    756768    // Toggling the cache model like this forces the cache to evict all its in-memory resources.
    757769    // FIXME: We need a better way to do this.
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r203338 r203857  
    262262
    263263    void platformSetCacheModel(CacheModel);
    264     void platformClearResourceCaches(ResourceCachesToClear);
    265264
    266265    void setEnhancedAccessibility(bool);
  • trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm

    r201612 r203857  
    4949#import <WebCore/FontCascade.h>
    5050#import <WebCore/LocalizedStrings.h>
    51 #import <WebCore/MemoryCache.h>
    5251#import <WebCore/MemoryPressureHandler.h>
    5352#import <WebCore/NSAccessibilitySPI.h>
    54 #import <WebCore/PageCache.h>
    5553#import <WebCore/RuntimeApplicationChecks.h>
    5654#import <WebCore/pthreadSPI.h>
     
    6260#import <objc/runtime.h>
    6361#import <stdio.h>
    64 #import <wtf/RAMSize.h>
    6562
    6663#if PLATFORM(IOS)
     
    7673namespace WebKit {
    7774
    78 static uint64_t volumeFreeSize(NSString *path)
    79 {
    80     NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:NULL];
    81     return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
    82 }
    83 
    84 void WebProcess::platformSetCacheModel(CacheModel cacheModel)
    85 {
    86     RetainPtr<NSString> nsurlCacheDirectory = adoptNS((NSString *)WKCopyFoundationCacheDirectory());
    87     if (!nsurlCacheDirectory)
    88         nsurlCacheDirectory = NSHomeDirectory();
    89 
    90     uint64_t memSize = ramSize() / 1024 / 1024;
    91 
    92     // As a fudge factor, use 1000 instead of 1024, in case the reported byte
    93     // count doesn't align exactly to a megabyte boundary.
    94     uint64_t diskFreeSize = volumeFreeSize(nsurlCacheDirectory.get()) / 1024 / 1000;
    95 
    96     unsigned cacheTotalCapacity = 0;
    97     unsigned cacheMinDeadCapacity = 0;
    98     unsigned cacheMaxDeadCapacity = 0;
    99     auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    100     unsigned pageCacheSize = 0;
    101     unsigned long urlCacheMemoryCapacity = 0;
    102     unsigned long urlCacheDiskCapacity = 0;
    103 
    104     calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    105         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    106         pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    107 
    108     auto& memoryCache = MemoryCache::singleton();
    109     memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    110     memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    111     PageCache::singleton().setMaxSize(pageCacheSize);
    112 }
    113 
    114 void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear)
    115 {
    116     // FIXME: Remove this.
     75void WebProcess::platformSetCacheModel(CacheModel)
     76{
    11777}
    11878
  • trunk/Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

    r200621 r203857  
    2828#include "WebProcess.h"
    2929
    30 #include "CertificateInfo.h"
    31 #include "WebCookieManager.h"
    3230#include "WebProcessCreationParameters.h"
    33 #include <WebCore/FileSystem.h>
    34 #include <WebCore/Language.h>
    3531#include <WebCore/MemoryCache.h>
    36 #include <WebCore/PageCache.h>
    37 #include <WebCore/ResourceHandle.h>
    38 #include <WebCore/SoupNetworkSession.h>
    39 #include <libsoup/soup.h>
    40 #include <wtf/RAMSize.h>
    41 #include <wtf/glib/GRefPtr.h>
    42 #include <wtf/glib/GUniquePtr.h>
    4332
    4433namespace WebKit {
     
    4635void WebProcess::platformSetCacheModel(CacheModel cacheModel)
    4736{
    48     unsigned cacheTotalCapacity = 0;
    49     unsigned cacheMinDeadCapacity = 0;
    50     unsigned cacheMaxDeadCapacity = 0;
    51     auto deadDecodedDataDeletionInterval = std::chrono::seconds { 0 };
    52     unsigned pageCacheSize = 0;
    53 
    54     unsigned long urlCacheMemoryCapacity = 0;
    55     unsigned long urlCacheDiskCapacity = 0;
    56 
    57     uint64_t diskFreeSize = 0;
    58 
    59     uint64_t memSize = WTF::ramSize() / WTF::MB;
    60     calculateCacheSizes(cacheModel, memSize, diskFreeSize,
    61                         cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
    62                         pageCacheSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    63 
    64     auto& memoryCache = WebCore::MemoryCache::singleton();
    65     memoryCache.setDisabled(cacheModel == CacheModelDocumentViewer);
    66     memoryCache.setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    67     memoryCache.setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
    68     WebCore::PageCache::singleton().setMaxSize(pageCacheSize);
    69 
    70 #if PLATFORM(GTK)
    71     WebCore::PageCache::singleton().setShouldClearBackingStores(true);
    72 #endif
     37    // FIXME: this is no longer soup specific, this file should be renamed.
     38    WebCore::MemoryCache::singleton().setDisabled(cacheModel == CacheModelDocumentViewer);
    7339}
    7440
    75 void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear)
    76 {
    77 }
    78 
    79 void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& parameters)
     41void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&&)
    8042{
    8143}
Note: See TracChangeset for help on using the changeset viewer.