- Revision
- 119965
- Author
- [email protected]
- Date
- 2012-06-11 02:17:07 -0700 (Mon, 11 Jun 2012)
Log 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 <[email protected]> on 2012-06-11
Reviewed by Kenneth Rohde Christiansen.
Source/WebCore:
No new tests needed / applicable (using operating system functionality).
Added method to read free file system space for a path to support cache model
implementation in Qt WK 2.
* platform/FileSystem.h:
(WebCore):
* platform/qt/FileSystemQt.cpp:
(WebCore::getVolumeFreeSizeForPath): Added for Qt ports.
(WebCore):
Source/WebKit2:
Added implementation of cache model for Qt WK 2 port including supporting
functionality such as WebProcess creation parameters and default values
for disk cache directories.
* 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::WebProcess::platformSetCacheModel):
(WebKit::WebProcess::platformInitializeWebProcess):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (119964 => 119965)
--- trunk/Source/WebCore/ChangeLog 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebCore/ChangeLog 2012-06-11 09:17:07 UTC (rev 119965)
@@ -1,3 +1,21 @@
+2012-06-11 Michael Brüning <[email protected]>
+
+ [Qt][WK2] Compute and set cache capacities using the current CacheModel
+ https://bugs.webkit.org/show_bug.cgi?id=73918
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ No new tests needed / applicable (using operating system functionality).
+
+ Added method to read free file system space for a path to support cache model
+ implementation in Qt WK 2.
+
+ * platform/FileSystem.h:
+ (WebCore):
+ * platform/qt/FileSystemQt.cpp:
+ (WebCore::getVolumeFreeSizeForPath): Added for Qt ports.
+ (WebCore):
+
2012-06-11 Peter Wang <[email protected]>
[JSC] Web Inspector: implement breaking from native callback
Modified: trunk/Source/WebCore/platform/FileSystem.h (119964 => 119965)
--- trunk/Source/WebCore/platform/FileSystem.h 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebCore/platform/FileSystem.h 2012-06-11 09:17:07 UTC (rev 119965)
@@ -205,6 +205,8 @@
String filenameForDisplay(const String&);
CString applicationDirectoryPath();
CString sharedResourcesPath();
+#endif
+#if PLATFORM(GTK) || PLATFORM(QT)
uint64_t getVolumeFreeSizeForPath(const char*);
#endif
Modified: trunk/Source/WebCore/platform/qt/FileSystemQt.cpp (119964 => 119965)
--- trunk/Source/WebCore/platform/qt/FileSystemQt.cpp 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebCore/platform/qt/FileSystemQt.cpp 2012-06-11 09:17:07 UTC (rev 119965)
@@ -40,6 +40,9 @@
#include <QFile>
#include <QFileInfo>
#include <QTemporaryFile>
+#if !defined(Q_OS_WINDOWS)
+#include <sys/statvfs.h>
+#endif
#include <wtf/text/CString.h>
namespace WebCore {
@@ -202,6 +205,24 @@
return -1;
}
+uint64_t getVolumeFreeSizeForPath(const char* path)
+{
+#if defined(Q_OS_WIN)
+ ULARGE_INTEGER freeBytesToCaller;
+ BOOL result = GetDiskFreeSpaceExW((LPCWSTR)path, &freeBytesToCaller, 0, 0);
+ if (!result)
+ return 0;
+ return static_cast<uint64_t>(freeBytesToCaller.QuadPart);
+#else
+ struct statvfs volumeInfo;
+ if (statvfs(path, &volumeInfo))
+ return 0;
+
+ return static_cast<uint64_t>(volumeInfo.f_bavail) * static_cast<uint64_t>(volumeInfo.f_frsize);
+#endif
+}
+
+
int writeToFile(PlatformFileHandle handle, const char* data, int length)
{
if (handle && handle->exists() && handle->isWritable())
Modified: trunk/Source/WebKit2/ChangeLog (119964 => 119965)
--- trunk/Source/WebKit2/ChangeLog 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebKit2/ChangeLog 2012-06-11 09:17:07 UTC (rev 119965)
@@ -1,3 +1,28 @@
+2012-06-11 Michael Brüning <[email protected]>
+
+ [Qt][WK2] Compute and set cache capacities using the current CacheModel
+ https://bugs.webkit.org/show_bug.cgi?id=73918
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Added implementation of cache model for Qt WK 2 port including supporting
+ functionality such as WebProcess creation parameters and default values
+ for disk cache directories.
+
+ * 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::WebProcess::platformSetCacheModel):
+ (WebKit::WebProcess::platformInitializeWebProcess):
+
2012-06-10 Darin Adler <[email protected]>
Remove unneeded callRemovedLastRef function from TreeShared refactoring
Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp (119964 => 119965)
--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp 2012-06-11 09:17:07 UTC (rev 119965)
@@ -97,6 +97,7 @@
#endif
#if PLATFORM(QT)
encoder->encode(cookieStorageDirectory);
+ encoder->encode(diskCacheDirectory);
#endif
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -192,6 +193,8 @@
#if PLATFORM(QT)
if (!decoder->decode(parameters.cookieStorageDirectory))
return false;
+ if (!decoder->decode(parameters.diskCacheDirectory))
+ return false;
#endif
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h (119964 => 119965)
--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h 2012-06-11 09:17:07 UTC (rev 119965)
@@ -120,6 +120,7 @@
#endif // PLATFORM(WIN)
#if PLATFORM(QT)
String cookieStorageDirectory;
+ String diskCacheDirectory;
#endif
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
Modified: trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp (119964 => 119965)
--- trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp 2012-06-11 09:17:07 UTC (rev 119965)
@@ -59,6 +59,18 @@
static QString s_defaultDatabaseDirectory;
static QString s_defaultLocalStorageDirectory;
+static String defaultDiskCacheDirectory()
+{
+ static String s_defaultDiskCacheDirectory;
+
+ if (!s_defaultDiskCacheDirectory.isEmpty())
+ return s_defaultDiskCacheDirectory;
+
+ s_defaultDiskCacheDirectory = WebCore::pathByAppendingComponent(defaultDataLocation(), "cache/");
+ WebCore::makeAllDirectories(s_defaultDiskCacheDirectory);
+ return s_defaultDiskCacheDirectory;
+}
+
String WebContext::applicationCacheDirectory()
{
return WebCore::cacheStorage().cacheDirectory();
@@ -68,6 +80,7 @@
{
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
parameters.cookieStorageDirectory = defaultDataLocation();
+ parameters.diskCacheDirectory = defaultDiskCacheDirectory();
#if ENABLE(GEOLOCATION)
static WebGeolocationProviderQt* location = WebGeolocationProviderQt::create(toAPI(geolocationManagerProxy()));
WKGeolocationManagerSetProvider(toAPI(geolocationManagerProxy()), WebGeolocationProviderQt::provider(location));
Modified: trunk/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp (119964 => 119965)
--- trunk/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp 2012-06-11 09:00:40 UTC (rev 119964)
+++ trunk/Source/WebKit2/WebProcess/qt/WebProcessQt.cpp 2012-06-11 09:17:07 UTC (rev 119965)
@@ -35,24 +35,93 @@
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkCookieJar>
+#include <QNetworkDiskCache>
#include <WebCore/CookieJarQt.h>
+#include <WebCore/FileSystem.h>
+#include <WebCore/MemoryCache.h>
#include <WebCore/PageCache.h>
#include <WebCore/RuntimeEnabledFeatures.h>
#if defined(Q_OS_MACX)
#include <dispatch/dispatch.h>
+#include <mach/host_info.h>
+#include <mach/mach.h>
+#include <mach/mach_error.h>
+#elif !defined(Q_OS_WIN)
+#include <unistd.h>
#endif
using namespace WebCore;
namespace WebKit {
-static const int DefaultPageCacheCapacity = 20;
+static uint64_t physicalMemorySizeInBytes()
+{
+ static uint64_t physicalMemorySize = 0;
-void WebProcess::platformSetCacheModel(CacheModel)
+ if (!physicalMemorySize) {
+#if defined(Q_OS_MACX)
+ host_basic_info_data_t hostInfo;
+ mach_port_t host = mach_host_self();
+ mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
+ kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&hostInfo, &count);
+ mach_port_deallocate(mach_task_self(), host);
+
+ if (r == KERN_SUCCESS)
+ physicalMemorySize = hostInfo.max_mem;
+
+#elif defined(Q_OS_WIN)
+ MEMORYSTATUSEX statex;
+ statex.dwLength = sizeof(statex);
+ GlobalMemoryStatusEx(&statex);
+ physicalMemorySize = static_cast<uint64_t>(statex.ullTotalPhys);
+
+#else
+ long pageSize = sysconf(_SC_PAGESIZE);
+ long numberOfPages = sysconf(_SC_PHYS_PAGES);
+
+ if (pageSize > 0 && numberOfPages > 0)
+ physicalMemorySize = static_cast<uint64_t>(pageSize) * static_cast<uint64_t>(numberOfPages);
+
+#endif
+ }
+ return physicalMemorySize;
+}
+
+void WebProcess::platformSetCacheModel(CacheModel cacheModel)
{
- // FIXME: see bug 73918
- pageCache()->setCapacity(DefaultPageCacheCapacity);
+ QNetworkDiskCache* diskCache = qobject_cast<QNetworkDiskCache*>(m_networkAccessManager->cache());
+ ASSERT(diskCache);
+
+ uint64_t physicalMemorySizeInMegabytes = physicalMemorySizeInBytes() / 1024 / 1024;
+
+ // The Mac port of WebKit2 uses a fudge factor of 1000 here to account for misalignment, however,
+ // that tends to overestimate the memory quite a bit (1 byte misalignment ~ 48 MiB misestimation).
+ // We use 1024 * 1023 for now to keep the estimation error down to +/- ~1 MiB.
+ uint64_t freeVolumeSpace = WebCore::getVolumeFreeSizeForPath(diskCache->cacheDirectory().toAscii().constData()) / 1024 / 1023;
+
+ // The following variables are initialised to 0 because WebProcess::calculateCacheSizes might not
+ // set them in some rare cases.
+ unsigned cacheTotalCapacity = 0;
+ unsigned cacheMinDeadCapacity = 0;
+ unsigned cacheMaxDeadCapacity = 0;
+ double deadDecodedDataDeletionInterval = 0;
+ unsigned pageCacheCapacity = 0;
+ unsigned long urlCacheMemoryCapacity = 0;
+ unsigned long urlCacheDiskCapacity = 0;
+
+ calculateCacheSizes(cacheModel, physicalMemorySizeInMegabytes, freeVolumeSpace,
+ cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
+ pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
+
+ diskCache->setMaximumCacheSize(urlCacheDiskCapacity);
+
+ memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+ memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+
+ pageCache()->setCapacity(pageCacheCapacity);
+
+ // FIXME: Implement hybrid in-memory- and disk-caching as e.g. the Mac port does.
}
void WebProcess::platformClearResourceCaches(ResourceCachesToClear)
@@ -75,6 +144,12 @@
// Do not let QNetworkAccessManager delete the jar.
jar->setParent(0);
+ ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull());
+ QNetworkDiskCache* diskCache = new QNetworkDiskCache();
+ diskCache->setCacheDirectory(parameters.diskCacheDirectory);
+ // The m_networkAccessManager takes ownership of the diskCache object upon the following call.
+ m_networkAccessManager->setCache(diskCache);
+
#if defined(Q_OS_MACX)
pid_t ppid = getppid();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);