Title: [257436] releases/WebKitGTK/webkit-2.28/Source/WebKit
Revision
257436
Author
[email protected]
Date
2020-02-26 02:56:28 -0800 (Wed, 26 Feb 2020)

Log Message

Merge r256967 - Regression(r247567) HTTP Disk cache capacity is no longer set
https://bugs.webkit.org/show_bug.cgi?id=207959
<rdar://problem/59603972>

Reviewed by Alex Christensen.

NetworkProcess::initializeNetworkProcess() was setting the cache model, which
would iterate over all network sessions to update their network cache capacity.
The issue was that network sessions were not constructed yet at this point.
When the network session(s) would get created later on, they would construct
their NetworkCache and it would use the default capacity (i.e.
std::numeric_limits<size_t>::max()).

To make this safer, I have moved the capacity computation to the Cache::open()
method and now pass the capacity when constructing the network cache storage.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
(WebKit::NetworkProcess::setCacheModelSynchronouslyForTesting):
(WebKit::NetworkProcess::setCacheModel):
* NetworkProcess/NetworkProcess.h:
(WebKit::NetworkProcess::cacheModel const):
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::initialize):
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::computeCapacity):
(WebKit::NetworkCache::Cache::open):
(WebKit::NetworkCache::Cache::capacity const):
(WebKit::NetworkCache::Cache::updateCapacity):
(WebKit::NetworkCache::Cache::setCapacity): Deleted.
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::open):
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::setCapacity):
* NetworkProcess/cache/NetworkCacheStorage.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::setCacheModel):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/ChangeLog	2020-02-26 10:56:28 UTC (rev 257436)
@@ -1,5 +1,47 @@
 2020-02-19  Chris Dumez  <[email protected]>
 
+        Regression(r247567) HTTP Disk cache capacity is no longer set
+        https://bugs.webkit.org/show_bug.cgi?id=207959
+        <rdar://problem/59603972>
+
+        Reviewed by Alex Christensen.
+
+        NetworkProcess::initializeNetworkProcess() was setting the cache model, which
+        would iterate over all network sessions to update their network cache capacity.
+        The issue was that network sessions were not constructed yet at this point.
+        When the network session(s) would get created later on, they would construct
+        their NetworkCache and it would use the default capacity (i.e.
+        std::numeric_limits<size_t>::max()).
+
+        To make this safer, I have moved the capacity computation to the Cache::open()
+        method and now pass the capacity when constructing the network cache storage.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        (WebKit::NetworkProcess::setCacheModelSynchronouslyForTesting):
+        (WebKit::NetworkProcess::setCacheModel):
+        * NetworkProcess/NetworkProcess.h:
+        (WebKit::NetworkProcess::cacheModel const):
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::Caches::initialize):
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::computeCapacity):
+        (WebKit::NetworkCache::Cache::open):
+        (WebKit::NetworkCache::Cache::capacity const):
+        (WebKit::NetworkCache::Cache::updateCapacity):
+        (WebKit::NetworkCache::Cache::setCapacity): Deleted.
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::open):
+        (WebKit::NetworkCache::Storage::Storage):
+        (WebKit::NetworkCache::Storage::setCapacity):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::setCacheModel):
+
+2020-02-19  Chris Dumez  <[email protected]>
+
         Disable the process cache when process-per-tab is disabled in the debug menu
         https://bugs.webkit.org/show_bug.cgi?id=207949
         <rdar://problem/57094837>

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.cpp (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-26 10:56:28 UTC (rev 257436)
@@ -324,7 +324,7 @@
         memoryPressureHandler.install();
     }
 
-    setCacheModel(parameters.cacheModel, parameters.defaultDataStoreParameters.networkSessionParameters.networkCacheDirectory);
+    setCacheModel(parameters.cacheModel);
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     m_isITPDatabaseEnabled = parameters.shouldEnableITPDatabase;
@@ -2015,11 +2015,11 @@
 
 void NetworkProcess::setCacheModelSynchronouslyForTesting(CacheModel cacheModel, CompletionHandler<void()>&& completionHandler)
 {
-    setCacheModel(cacheModel, { });
+    setCacheModel(cacheModel);
     completionHandler();
 }
 
-void NetworkProcess::setCacheModel(CacheModel cacheModel, String cacheStorageDirectory)
+void NetworkProcess::setCacheModel(CacheModel cacheModel)
 {
     if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
         return;
@@ -2027,29 +2027,10 @@
     m_hasSetCacheModel = true;
     m_cacheModel = cacheModel;
 
-    unsigned urlCacheMemoryCapacity = 0;
-    uint64_t urlCacheDiskCapacity = 0;
-    uint64_t diskFreeSize = 0;
-
-    // FIXME: Move the cache model to WebsiteDataStore so we don't need to assume the first cache is on the same volume as all caches.
-    forEachNetworkSession([&](auto& session) {
-        if (!cacheStorageDirectory.isNull())
-            return;
+    forEachNetworkSession([](auto& session) {
         if (auto* cache = session.cache())
-            cacheStorageDirectory = cache->storageDirectory();
+            cache->updateCapacity();
     });
-
-    if (FileSystem::getVolumeFreeSpace(cacheStorageDirectory, diskFreeSize)) {
-        // As a fudge factor, use 1000 instead of 1024, in case the reported byte
-        // count doesn't align exactly to a megabyte boundary.
-        diskFreeSize /= KB * 1000;
-        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
-    }
-
-    forEachNetworkSession([urlCacheDiskCapacity](auto& session) {
-        if (auto* cache = session.cache())
-            cache->setCapacity(urlCacheDiskCapacity);
-    });
 }
 
 void NetworkProcess::setAllowsAnySSLCertificateForWebSocket(bool allows, CompletionHandler<void()>&& completionHandler)

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.h (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.h	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.h	2020-02-26 10:56:28 UTC (rev 257436)
@@ -180,6 +180,8 @@
     void processDidResume();
     void resume();
 
+    CacheModel cacheModel() const { return m_cacheModel; }
+
     // Diagnostic messages logging.
     void logDiagnosticMessage(WebPageProxyIdentifier, const String& message, const String& description, WebCore::ShouldSample);
     void logDiagnosticMessageWithResult(WebPageProxyIdentifier, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
@@ -411,7 +413,7 @@
     void applicationDidEnterBackground();
     void applicationWillEnterForeground();
 
-    void setCacheModel(CacheModel, String overrideCacheStorageDirectory);
+    void setCacheModel(CacheModel);
     void setCacheModelSynchronouslyForTesting(CacheModel, CompletionHandler<void()>&&);
     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
     void clearCacheForAllOrigins(uint32_t cachesToClear);

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2020-02-26 10:56:28 UTC (rev 257436)
@@ -70,7 +70,7 @@
     AllowSpecificHTTPSCertificateForHost(WebCore::CertificateInfo certificate, String host)
     
     ClearCacheForAllOrigins(uint32_t cachesToClear)
-    SetCacheModel(enum:uint8_t WebKit::CacheModel cacheModel, String overrideCacheStorageDirectory)
+    SetCacheModel(enum:uint8_t WebKit::CacheModel cacheModel)
     SetCacheModelSynchronouslyForTesting(enum:uint8_t WebKit::CacheModel cacheModel) -> () Synchronous
 
     ProcessDidTransitionToBackground()

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2020-02-26 10:56:28 UTC (rev 257436)
@@ -150,7 +150,8 @@
         return;
     }
 
-    auto storage = Storage::open(m_rootPath, Storage::Mode::AvoidRandomness);
+    size_t capacity = std::numeric_limits<size_t>::max(); // We use a per-origin quota instead of a global capacity.
+    auto storage = Storage::open(m_rootPath, Storage::Mode::AvoidRandomness, capacity);
     if (!storage) {
         RELEASE_LOG_ERROR(CacheStorage, "Caches::initialize failed opening storage");
         callback(Error::WriteDisk);

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2020-02-26 10:56:28 UTC (rev 257436)
@@ -62,9 +62,24 @@
     return resource;
 }
 
+static size_t computeCapacity(CacheModel cacheModel, const String& cachePath)
+{
+    unsigned urlCacheMemoryCapacity = 0;
+    uint64_t urlCacheDiskCapacity = 0;
+    uint64_t diskFreeSize = 0;
+    if (FileSystem::getVolumeFreeSpace(cachePath, diskFreeSize)) {
+        // As a fudge factor, use 1000 instead of 1024, in case the reported byte
+        // count doesn't align exactly to a megabyte boundary.
+        diskFreeSize /= KB * 1000;
+        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
+    }
+    return urlCacheDiskCapacity;
+}
+
 RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<CacheOption> options, PAL::SessionID sessionID)
 {
-    auto storage = Storage::open(cachePath, options.contains(CacheOption::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal);
+    auto capacity = computeCapacity(networkProcess.cacheModel(), cachePath);
+    auto storage = Storage::open(cachePath, options.contains(CacheOption::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal, capacity);
 
     LOG(NetworkCache, "(NetworkProcess) opened cache storage, success %d", !!storage);
 
@@ -125,11 +140,17 @@
 {
 }
 
-void Cache::setCapacity(size_t maximumSize)
+size_t Cache::capacity() const
 {
-    m_storage->setCapacity(maximumSize);
+    return m_storage->capacity();
 }
 
+void Cache::updateCapacity()
+{
+    auto newCapacity = computeCapacity(m_networkProcess->cacheModel(), m_storage->basePathIsolatedCopy());
+    m_storage->setCapacity(newCapacity);
+}
+
 Key Cache::makeCacheKey(const WebCore::ResourceRequest& request)
 {
     // FIXME: This implements minimal Range header disk cache support. We don't parse

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.h (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.h	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCache.h	2020-02-26 10:56:28 UTC (rev 257436)
@@ -127,7 +127,8 @@
 public:
     static RefPtr<Cache> open(NetworkProcess&, const String& cachePath, OptionSet<CacheOption>, PAL::SessionID);
 
-    void setCapacity(size_t);
+    size_t capacity() const;
+    void updateCapacity();
 
     // Completion handler may get called back synchronously on failure.
     struct RetrieveInfo {

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2020-02-26 10:56:28 UTC (rev 257436)
@@ -174,7 +174,7 @@
     return FileSystem::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), saltFileName);
 }
 
-RefPtr<Storage> Storage::open(const String& baseCachePath, Mode mode)
+RefPtr<Storage> Storage::open(const String& baseCachePath, Mode mode, size_t capacity)
 {
     ASSERT(RunLoop::isMain());
     ASSERT(!baseCachePath.isNull());
@@ -188,7 +188,7 @@
     if (!salt)
         return nullptr;
 
-    return adoptRef(new Storage(cachePath, mode, *salt));
+    return adoptRef(new Storage(cachePath, mode, *salt, capacity));
 }
 
 using RecordFileTraverseFunction = Function<void (const String& fileName, const String& hashString, const String& type, bool isBlob, const String& recordDirectoryPath)>;
@@ -238,11 +238,12 @@
     });
 }
 
-Storage::Storage(const String& baseDirectoryPath, Mode mode, Salt salt)
+Storage::Storage(const String& baseDirectoryPath, Mode mode, Salt salt, size_t capacity)
     : m_basePath(baseDirectoryPath)
     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
     , m_mode(mode)
     , m_salt(salt)
+    , m_capacity(capacity)
     , m_readOperationTimeoutTimer(*this, &Storage::cancelAllReadOperations)
     , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations)
     , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
@@ -986,6 +987,8 @@
 void Storage::setCapacity(size_t capacity)
 {
     ASSERT(RunLoop::isMain());
+    if (m_capacity == capacity)
+        return;
 
 #if ASSERT_ENABLED
     const size_t assumedAverageRecordSize = 50 << 10;

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h	2020-02-26 10:56:28 UTC (rev 257436)
@@ -48,7 +48,7 @@
 class Storage : public ThreadSafeRefCounted<Storage, WTF::DestructionThread::Main> {
 public:
     enum class Mode { Normal, AvoidRandomness };
-    static RefPtr<Storage> open(const String& cachePath, Mode);
+    static RefPtr<Storage> open(const String& cachePath, Mode, size_t capacity);
 
     struct Record {
         Key key;
@@ -120,7 +120,7 @@
     void writeWithoutWaiting() { m_initialWriteDelay = 0_s; };
 
 private:
-    Storage(const String& directoryPath, Mode, Salt);
+    Storage(const String& directoryPath, Mode, Salt, size_t capacity);
 
     String recordDirectoryPathForKey(const Key&) const;
     String recordPathForKey(const Key&) const;

Modified: releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/WebProcessPool.cpp (257435 => 257436)


--- releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-02-26 10:56:21 UTC (rev 257435)
+++ releases/WebKitGTK/webkit-2.28/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-02-26 10:56:28 UTC (rev 257436)
@@ -1613,7 +1613,7 @@
     sendToAllProcesses(Messages::WebProcess::SetCacheModel(cacheModel));
 
     if (m_networkProcess)
-        m_networkProcess->send(Messages::NetworkProcess::SetCacheModel(cacheModel, { }), 0);
+        m_networkProcess->send(Messages::NetworkProcess::SetCacheModel(cacheModel), 0);
 }
 
 void WebProcessPool::setCacheModelSynchronouslyForTesting(CacheModel cacheModel)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to