Bump the priority of CacheStorageEngine write operations
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Dec 2019 11:50:27 +0000 (11:50 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Dec 2019 11:50:27 +0000 (11:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=205329

Reviewed by Antti Koivisto.

Source/WebKit:

Introduce an IOChannel extra optional parameter to set the QOS.
Use this parameter for IOChannels created by CacheStorageEngine when writing files to increase the priority to default.
Increase the priority of the CacheStorageEngine background queue to default.
No observable change of behavior except potential speed increase.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::Engine):
(WebKit::CacheStorage::Engine::writeFile):
* NetworkProcess/cache/NetworkCacheIOChannel.h:
(WebKit::NetworkCache::IOChannel::open):
* NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
(WebKit::NetworkCache::dispatchQueueFromPriority):
(WebKit::NetworkCache::IOChannel::IOChannel):
(WebKit::NetworkCache::IOChannel::open):
* NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
(WebKit::NetworkCache::IOChannel::open):
* NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
(WebKit::NetworkCache::IOChannel::open):

LayoutTests:

* http/tests/cache-storage/page-cache-domcachestorage-pending-promise.html:
Increase timer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253621 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/cache-storage/page-cache-domcachestorage-pending-promise.html
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h
Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm
Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp

index 9dcf2f6..9274275 100644 (file)
@@ -1,3 +1,13 @@
+2019-12-17  youenn fablet  <youenn@apple.com>
+
+        Bump the priority of CacheStorageEngine write operations
+        https://bugs.webkit.org/show_bug.cgi?id=205329
+
+        Reviewed by Antti Koivisto.
+
+        * http/tests/cache-storage/page-cache-domcachestorage-pending-promise.html:
+        Increase timer.
+
 2019-12-17  Thibault Saunier  <tsaunier@igalia.com>
 
         [GStreamer][WPE] Fix regressions related to our 'Fix GStreamer capturer mock' patch
index 60d82bd..6d902ba 100644 (file)
@@ -30,7 +30,7 @@ window.addEventListener("pagehide", function(event) {
         if (window.internals)
             console.log(await internals.cacheStorageEngineRepresentation());
         finishJSTest();
-    }, 10000);
+    }, 20000);
 
     caches.open('test').then(() => {
        clearTimeout(handle1);
index 2d7bb74..bc21b2c 100644 (file)
@@ -1,5 +1,31 @@
 2019-12-17  youenn fablet  <youenn@apple.com>
 
+        Bump the priority of CacheStorageEngine write operations
+        https://bugs.webkit.org/show_bug.cgi?id=205329
+
+        Reviewed by Antti Koivisto.
+
+        Introduce an IOChannel extra optional parameter to set the QOS.
+        Use this parameter for IOChannels created by CacheStorageEngine when writing files to increase the priority to default.
+        Increase the priority of the CacheStorageEngine background queue to default.
+        No observable change of behavior except potential speed increase.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::Engine):
+        (WebKit::CacheStorage::Engine::writeFile):
+        * NetworkProcess/cache/NetworkCacheIOChannel.h:
+        (WebKit::NetworkCache::IOChannel::open):
+        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+        (WebKit::NetworkCache::dispatchQueueFromPriority):
+        (WebKit::NetworkCache::IOChannel::IOChannel):
+        (WebKit::NetworkCache::IOChannel::open):
+        * NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
+        (WebKit::NetworkCache::IOChannel::open):
+        * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
+        (WebKit::NetworkCache::IOChannel::open):
+
+2019-12-17  youenn fablet  <youenn@apple.com>
+
         WebKitTestRunner should report service worker process crashes
         https://bugs.webkit.org/show_bug.cgi?id=205267
 
index e49c415..6dabc54 100644 (file)
@@ -266,7 +266,7 @@ Engine::Engine(PAL::SessionID sessionID, NetworkProcess& process, String&& rootP
     , m_rootPath(WTFMove(rootPath))
 {
     if (!m_rootPath.isNull())
-        m_ioQueue = WorkQueue::create("com.apple.WebKit.CacheStorageEngine.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background);
+        m_ioQueue = WorkQueue::create("com.apple.WebKit.CacheStorageEngine.serial.default", WorkQueue::Type::Serial, WorkQueue::QOS::Default);
 }
 
 void Engine::open(const WebCore::ClientOrigin& origin, const String& cacheName, CacheIdentifierCallback&& callback)
@@ -466,7 +466,7 @@ void Engine::writeFile(const String& filename, NetworkCache::Data&& data, WebCor
         if (!FileSystem::fileExists(directoryPath))
             FileSystem::makeAllDirectories(directoryPath);
 
-        auto channel = IOChannel::open(filename, IOChannel::Type::Create);
+        auto channel = IOChannel::open(filename, IOChannel::Type::Create, WorkQueue::QOS::Default);
         channel->write(0, data, nullptr, [this, weakThis = WTFMove(weakThis), identifier](int error) mutable {
             ASSERT(RunLoop::isMain());
             if (!weakThis)
index 5767f93..6398700 100644 (file)
@@ -42,7 +42,7 @@ namespace NetworkCache {
 class IOChannel : public ThreadSafeRefCounted<IOChannel> {
 public:
     enum class Type { Read, Write, Create };
-    static Ref<IOChannel> open(const String& file, Type);
+    static Ref<IOChannel> open(const String& file, Type type, Optional<WorkQueue::QOS> qos = { }) { return adoptRef(*new IOChannel(file, type, qos)); }
 
     // Using nullptr as queue submits the result to the main queue.
     // FIXME: We should add WorkQueue::main() instead.
@@ -61,7 +61,7 @@ public:
     ~IOChannel();
 
 private:
-    IOChannel(const String& filePath, IOChannel::Type);
+    IOChannel(const String& filePath, IOChannel::Type, Optional<WorkQueue::QOS>);
 
 #if USE(SOUP)
     void readSyncInThread(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
index c652164..350cd2e 100644 (file)
 namespace WebKit {
 namespace NetworkCache {
 
-IOChannel::IOChannel(const String& filePath, Type type)
+static long dispatchQueueIdentifier(WorkQueue::QOS qos)
+{
+    switch (qos) {
+    case WorkQueue::QOS::UserInteractive:
+    case WorkQueue::QOS::UserInitiated:
+    case WorkQueue::QOS::Default:
+        return DISPATCH_QUEUE_PRIORITY_DEFAULT;
+    case WorkQueue::QOS::Utility:
+        return DISPATCH_QUEUE_PRIORITY_LOW;
+    case WorkQueue::QOS::Background:
+        return DISPATCH_QUEUE_PRIORITY_BACKGROUND;
+    }
+}
+
+IOChannel::IOChannel(const String& filePath, Type type, Optional<WorkQueue::QOS> qos)
     : m_path(filePath)
     , m_type(type)
 {
     auto path = FileSystem::fileSystemRepresentation(filePath);
     int oflag;
     mode_t mode;
-    bool useLowIOPriority = false;
+    WorkQueue::QOS dispatchQOS;
 
     switch (m_type) {
     case Type::Create:
@@ -52,22 +66,23 @@ IOChannel::IOChannel(const String& filePath, Type type)
         unlink(path.data());
         oflag = O_RDWR | O_CREAT | O_NONBLOCK;
         mode = S_IRUSR | S_IWUSR;
-        useLowIOPriority = true;
+        dispatchQOS = qos.valueOr(WorkQueue::QOS::Background);
         break;
     case Type::Write:
         oflag = O_WRONLY | O_NONBLOCK;
         mode = S_IRUSR | S_IWUSR;
-        useLowIOPriority = true;
+        dispatchQOS = qos.valueOr(WorkQueue::QOS::Background);
         break;
     case Type::Read:
         oflag = O_RDONLY | O_NONBLOCK;
         mode = 0;
+        dispatchQOS = qos.valueOr(WorkQueue::QOS::Default);
     }
 
     int fd = ::open(path.data(), oflag, mode);
     m_fileDescriptor = fd;
 
-    m_dispatchIO = adoptOSObject(dispatch_io_create(DISPATCH_IO_RANDOM, fd, dispatch_get_global_queue(useLowIOPriority ? DISPATCH_QUEUE_PRIORITY_BACKGROUND : DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [fd](int) {
+    m_dispatchIO = adoptOSObject(dispatch_io_create(DISPATCH_IO_RANDOM, fd, dispatch_get_global_queue(dispatchQueueIdentifier(dispatchQOS), 0), [fd](int) {
         close(fd);
     }));
     ASSERT(m_dispatchIO.get());
@@ -81,11 +96,6 @@ IOChannel::~IOChannel()
     RELEASE_ASSERT(!m_wasDeleted.exchange(true));
 }
 
-Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)
-{
-    return adoptRef(*new IOChannel(filePath, type));
-}
-
 void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
 {
     RefPtr<IOChannel> channel(this);
index 03ee1b0..2fb3e71 100644 (file)
@@ -31,7 +31,7 @@
 namespace WebKit {
 namespace NetworkCache {
 
-IOChannel::IOChannel(const String& filePath, Type type)
+IOChannel::IOChannel(const String& filePath, Type type, Optional<WorkQueue::QOS>)
     : m_path(filePath)
     , m_type(type)
 {
@@ -55,11 +55,6 @@ IOChannel::~IOChannel()
     FileSystem::closeFile(m_fileDescriptor);
 }
 
-Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)
-{
-    return adoptRef(*new IOChannel(filePath, type));
-}
-
 static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
 {
     if (queue) {
index b56f965..09309bc 100644 (file)
@@ -37,7 +37,7 @@ namespace NetworkCache {
 
 static const size_t gDefaultReadBufferSize = 4096;
 
-IOChannel::IOChannel(const String& filePath, Type type)
+IOChannel::IOChannel(const String& filePath, Type type, Optional<WorkQueue::QOS>)
     : m_path(filePath)
     , m_type(type)
 {
@@ -68,11 +68,6 @@ IOChannel::~IOChannel()
     RELEASE_ASSERT(!m_wasDeleted.exchange(true));
 }
 
-Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)
-{
-    return adoptRef(*new IOChannel(filePath, type));
-}
-
 static inline void runTaskInQueue(Function<void ()>&& task, WorkQueue* queue)
 {
     if (queue) {