Title: [256967] trunk/Source/WebKit
Revision
256967
Author
cdu...@apple.com
Date
2020-02-19 15:33:56 -0800 (Wed, 19 Feb 2020)

Log Message

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: trunk/Source/WebKit/ChangeLog (256966 => 256967)


--- trunk/Source/WebKit/ChangeLog	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/ChangeLog	2020-02-19 23:33:56 UTC (rev 256967)
@@ -1,3 +1,45 @@
+2020-02-19  Chris Dumez  <cdu...@apple.com>
+
+        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  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] fast/dom/focus-shift-crash.html and editing/selection/selection-change-in-disconnected-frame-crash.html crash after r256864

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2020-02-19 23:33:56 UTC (rev 256967)
@@ -326,7 +326,7 @@
         memoryPressureHandler.install();
     }
 
-    setCacheModel(parameters.cacheModel, parameters.defaultDataStoreParameters.networkSessionParameters.networkCacheDirectory);
+    setCacheModel(parameters.cacheModel);
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     m_isITPDatabaseEnabled = parameters.shouldEnableITPDatabase;
@@ -2038,11 +2038,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;
@@ -2050,29 +2050,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: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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);
@@ -408,7 +410,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: trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h (256966 => 256967)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (256966 => 256967)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-02-19 23:24:57 UTC (rev 256966)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-02-19 23:33:56 UTC (rev 256967)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to