Changeset 106920 in webkit


Ignore:
Timestamp:
Feb 7, 2012 3:42:39 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[Qt][WK2] Compute and set cache capacities using the current CacheModel
https://bugs.webkit.org/show_bug.cgi?id=73918

Patch by Michael Brüning <michael.bruning@nokia.com> on 2012-02-07
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

No new tests. (Not applicable)

Added OS-specific implementation for retrieving the free disk space.

  • platform/FileSystem.h:

(WebCore):

  • platform/qt/FileSystemQt.cpp:

(WebCore::getVolumeFreeSizeForPath):
(WebCore):

Source/WebKit2:

First part of the implementation. The next steps are the implementation
of the API for the Qt WebKit 2 port and the hybrid memory and disk cache.

  • Shared/WebProcessCreationParameters.cpp:

(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):

  • Shared/WebProcessCreationParameters.h:

(WebProcessCreationParameters):

  • UIProcess/qt/WebContextQt.cpp:

(WebKit::defaultDiskCacheDirectory):
(WebKit):
(WebKit::WebContext::platformInitializeWebProcess):

  • WebProcess/qt/WebProcessQt.cpp:

(WebKit::physicalMemorySizeInBytes):
(WebKit):
(WebKit::WebProcess::platformSetCacheModel):
(WebKit::WebProcess::platformInitializeWebProcess):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106917 r106920  
     12012-02-07  Michael Brüning  <michael.bruning@nokia.com>
     2
     3        [Qt][WK2] Compute and set cache capacities using the current CacheModel
     4        https://bugs.webkit.org/show_bug.cgi?id=73918
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        No new tests. (Not applicable)
     9
     10        Added OS-specific implementation for retrieving the free disk space.
     11
     12        * platform/FileSystem.h:
     13        (WebCore):
     14        * platform/qt/FileSystemQt.cpp:
     15        (WebCore::getVolumeFreeSizeForPath):
     16        (WebCore):
     17
    1182012-02-07  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    219
  • trunk/Source/WebCore/platform/FileSystem.h

    r96829 r106920  
    199199String filenameForDisplay(const String&);
    200200CString applicationDirectoryPath();
     201#endif
     202#if PLATFORM(GTK) || PLATFORM(QT)
    201203uint64_t getVolumeFreeSizeForPath(const char*);
    202204#endif
  • trunk/Source/WebCore/platform/qt/FileSystemQt.cpp

    r82193 r106920  
    4040#include <QFileInfo>
    4141#include <QTemporaryFile>
     42#include <sys/statvfs.h>
    4243#include <wtf/text/CString.h>
    4344
     
    191192}
    192193
     194uint64_t getVolumeFreeSizeForPath(const char* path)
     195{
     196#if defined(Q_OS_WIN)
     197    ULARGE_INTEGER freeBytesToCaller;
     198    BOOL result = GetDiskFreeSpaceExW((LPCWSTR)path, &freeBytesToCaller, 0, 0);
     199    if (!result)
     200        return 0;
     201    return static_cast<uint64_t>freeBytesToCaller.QuadPart;
     202#else
     203    struct statvfs volumeInfo;
     204    if (statvfs(path, &volumeInfo))
     205        return 0;
     206
     207    return static_cast<uint64_t>(volumeInfo.f_bavail) * static_cast<uint64_t>(volumeInfo.f_frsize);
     208#endif
     209}
     210
    193211int writeToFile(PlatformFileHandle handle, const char* data, int length)
    194212{
  • trunk/Source/WebKit2/ChangeLog

    r106907 r106920  
     12012-02-07  Michael Brüning  <michael.bruning@nokia.com>
     2
     3        [Qt][WK2] Compute and set cache capacities using the current CacheModel
     4        https://bugs.webkit.org/show_bug.cgi?id=73918
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        First part of the implementation. The next steps are the implementation
     9        of the API for the Qt WebKit 2 port and the hybrid memory and disk cache.
     10
     11        * Shared/WebProcessCreationParameters.cpp:
     12        (WebKit::WebProcessCreationParameters::encode):
     13        (WebKit::WebProcessCreationParameters::decode):
     14        * Shared/WebProcessCreationParameters.h:
     15        (WebProcessCreationParameters):
     16        * UIProcess/qt/WebContextQt.cpp:
     17        (WebKit::defaultDiskCacheDirectory):
     18        (WebKit):
     19        (WebKit::WebContext::platformInitializeWebProcess):
     20        * WebProcess/qt/WebProcessQt.cpp:
     21        (WebKit::physicalMemorySizeInBytes):
     22        (WebKit):
     23        (WebKit::WebProcess::platformSetCacheModel):
     24        (WebKit::WebProcess::platformInitializeWebProcess):
     25
    1262012-02-06  Shinya Kawanaka  <shinyak@google.com>
    227
  • trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp

    r105364 r106920  
    9999#if PLATFORM(QT)
    100100    encoder->encode(cookieStorageDirectory);
     101    encoder->encode(diskCacheDirectory);
    101102#endif
    102103
     
    196197    if (!decoder->decode(parameters.cookieStorageDirectory))
    197198        return false;
     199    if (!decoder->decode(parameters.diskCacheDirectory))
     200        return false;
    198201#endif
    199202
  • trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h

    r105364 r106920  
    122122#if PLATFORM(QT)
    123123    String cookieStorageDirectory;
     124    String diskCacheDirectory;
    124125#endif
    125126
  • trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp

    r98721 r106920  
    5858}
    5959
     60static String defaultDiskCacheDirectory()
     61{
     62    static String s_defaultDiskCacheDirectory;
     63
     64    if (!s_defaultDiskCacheDirectory.isEmpty())
     65        return s_defaultDiskCacheDirectory;
     66
     67    s_defaultDiskCacheDirectory = WebCore::pathByAppendingComponent(defaultDataLocation(), "cache/");
     68    WebCore::makeAllDirectories(s_defaultDiskCacheDirectory);
     69    return s_defaultDiskCacheDirectory;
     70}
     71
    6072static QString s_defaultDatabaseDirectory;
    6173static QString s_defaultLocalStorageDirectory;
     
    7082    qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
    7183    parameters.cookieStorageDirectory = defaultDataLocation();
     84    parameters.diskCacheDirectory = defaultDiskCacheDirectory();
     85
    7286#if ENABLE(GEOLOCATION)
    7387    static WebGeolocationProviderQt* location = WebGeolocationProviderQt::create(toAPI(geolocationManagerProxy()));
  • trunk/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp

    r104193 r106920  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011, 2012 Nokia Corporation and/or its subsidiary(-ies)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3637#include <QNetworkAccessManager>
    3738#include <QNetworkCookieJar>
     39#include <QNetworkDiskCache>
    3840#include <WebCore/CookieJarQt.h>
     41#include <WebCore/FileSystem.h>
     42#include <WebCore/MemoryCache.h>
    3943#include <WebCore/PageCache.h>
    4044#include <WebCore/RuntimeEnabledFeatures.h>
     
    4246#if defined(Q_OS_MACX)
    4347#include <dispatch/dispatch.h>
     48#include <mach/host_info.h>
     49#include <mach/mach.h>
     50#include <mach/mach_error.h>
     51#elif defined(Q_OS_WIN)
     52
     53#else
     54#include <unistd.h>
    4455#endif
    4556
     
    4859namespace WebKit {
    4960
    50 static const int DefaultPageCacheCapacity = 20;
     61static uint64_t physicalMemorySizeInBytes()
     62{
     63    static uint64_t physicalMemorySize = 0;
    5164
    52 void WebProcess::platformSetCacheModel(CacheModel)
     65    if (!physicalMemorySize) {
     66#if defined(Q_OS_MACX)
     67        host_basic_info_data_t hostInfo;
     68        mach_port_t host = mach_host_self();
     69        mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
     70        kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&hostInfo, &count);
     71        mach_port_deallocate(mach_task_self(), host);
     72
     73        if (r == KERN_SUCCESS)
     74            physicalMemorySize = hostInfo.max_mem;
     75
     76#elif defined(Q_OS_WIN)
     77        MEMORYSTATUSEX statex;
     78        statex.dwLength = sizeof(statex);
     79        GlobalMemoryStatusEx(&statex);
     80        physicalMemorySize = static_cast<uint64_t>(statex.ullTotalPhys);
     81
     82#else
     83        long pageSize = sysconf(_SC_PAGESIZE);
     84        long numberOfPages = sysconf(_SC_PHYS_PAGES);
     85
     86        if (pageSize > 0 && numberOfPages > 0)
     87            physicalMemorySize = static_cast<uint64_t>(pageSize) * static_cast<uint64_t>(numberOfPages);
     88
     89#endif
     90    }
     91    return physicalMemorySize;
     92}
     93
     94void WebProcess::platformSetCacheModel(CacheModel cacheModel)
    5395{
    54     // FIXME: see bug 73918
    55     pageCache()->setCapacity(DefaultPageCacheCapacity);
     96    QNetworkDiskCache* diskCache = qobject_cast<QNetworkDiskCache*>(m_networkAccessManager->cache());
     97    ASSERT(diskCache);
     98
     99    ASSERT(WebCore::platformInfo());
     100    uint64_t physicalMemorySizeInMegabytes = physicalMemorySizeInBytes() / 1024 / 1024;
     101
     102    // The Mac port of WebKit2 uses a fudge factor of 1000 here to account for misalignment, however,
     103    // that tends to overestimate the memory quite a bit (1 byte misalignment ~ 48 MiB misestimation).
     104    // We use 1024 * 1023 for now to keep the estimation error down to +/- ~1 MiB.
     105    uint64_t freeVolumeSpace = WebCore::getVolumeFreeSizeForPath(diskCache->cacheDirectory().toAscii().constData()) / 1024 / 1023;
     106
     107    // The following variables are initialised to 0 because WebProcess::calculateCacheSizes might not
     108    // set them in some rare cases.
     109    unsigned cacheTotalCapacity = 0;
     110    unsigned cacheMinDeadCapacity = 0;
     111    unsigned cacheMaxDeadCapacity = 0;
     112    double deadDecodedDataDeletionInterval = 0;
     113    unsigned pageCacheCapacity = 0;
     114    unsigned long urlCacheMemoryCapacity = 0;
     115    unsigned long urlCacheDiskCapacity = 0;
     116
     117    calculateCacheSizes(cacheModel, physicalMemorySizeInMegabytes, freeVolumeSpace,
     118        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
     119        pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
     120
     121    memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
     122    memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
     123    pageCache()->setCapacity(pageCacheCapacity);
     124
     125    // FIXME: Implement hybrid in-memory- and disk-caching as e.g. the Mac port does.
     126    diskCache->setMaximumCacheSize(static_cast<qint64>(urlCacheDiskCapacity));
    56127}
    57128
     
    70141{
    71142    m_networkAccessManager = new QtNetworkAccessManager(this);
     143
     144    ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull());
     145    QNetworkDiskCache* diskCache = new QNetworkDiskCache();
     146    diskCache->setCacheDirectory(parameters.diskCacheDirectory);
     147    // The m_networkAccessManager takes ownership of the diskCache object upon the following call.
     148    m_networkAccessManager->setCache(diskCache);
     149
    72150    ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull());
    73151    WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory);
Note: See TracChangeset for help on using the changeset viewer.