Title: [185452] trunk/Source/WebKit2
Revision
185452
Author
[email protected]
Date
2015-06-11 05:05:25 -0700 (Thu, 11 Jun 2015)

Log Message

3% cold PLT regression from network cache on iOS
https://bugs.webkit.org/show_bug.cgi?id=145694
rdar://problem/21158245

Reviewed by Chris Dumez.

Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.

* NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
(WebKit::NetworkCache::IOChannel::IOChannel):
(WebKit::NetworkCache::IOChannel::open):

    Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.

* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
(WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):

    Only write one file at a time instead of maximum of three.

(WebKit::NetworkCache::Storage::retrieve):

    For consistency with store prepend new entries here too.

(WebKit::NetworkCache::Storage::store):

    Delay start of the first write operation by 1s.
    Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates

(WebKit::NetworkCache::Storage::traverse):
* NetworkProcess/cache/NetworkCacheStorage.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (185451 => 185452)


--- trunk/Source/WebKit2/ChangeLog	2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/ChangeLog	2015-06-11 12:05:25 UTC (rev 185452)
@@ -1,3 +1,38 @@
+2015-06-11  Antti Koivisto  <[email protected]>
+
+        3% cold PLT regression from network cache on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=145694
+        rdar://problem/21158245
+
+        Reviewed by Chris Dumez.
+
+        Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.
+
+        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+        (WebKit::NetworkCache::IOChannel::IOChannel):
+        (WebKit::NetworkCache::IOChannel::open):
+
+            Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.
+
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::Storage):
+        (WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
+        (WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):
+
+            Only write one file at a time instead of maximum of three.
+
+        (WebKit::NetworkCache::Storage::retrieve):
+
+            For consistency with store prepend new entries here too.
+
+        (WebKit::NetworkCache::Storage::store):
+
+            Delay start of the first write operation by 1s.
+            Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates
+
+        (WebKit::NetworkCache::Storage::traverse):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+
 2015-06-10  Yongjun Zhang  <[email protected]>
 
         Don't send touch events on link preview.

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm (185451 => 185452)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2015-06-11 12:05:25 UTC (rev 185452)
@@ -46,6 +46,7 @@
     auto path = WebCore::fileSystemRepresentation(filePath);
     int oflag;
     mode_t mode;
+    bool useLowIOPriority = false;
 
     switch (m_type) {
     case Type::Create:
@@ -53,10 +54,12 @@
         unlink(path.data());
         oflag = O_RDWR | O_CREAT | O_NONBLOCK;
         mode = S_IRUSR | S_IWUSR;
+        useLowIOPriority = true;
         break;
     case Type::Write:
         oflag = O_WRONLY | O_NONBLOCK;
         mode = S_IRUSR | S_IWUSR;
+        useLowIOPriority = true;
         break;
     case Type::Read:
         oflag = O_RDONLY | O_NONBLOCK;
@@ -70,8 +73,14 @@
         close(fd);
     }));
     ASSERT(m_dispatchIO.get());
+
     // This makes the channel read/write all data before invoking the handlers.
     dispatch_io_set_low_water(m_dispatchIO.get(), std::numeric_limits<size_t>::max());
+
+    if (useLowIOPriority) {
+        // The target queue of a dispatch I/O channel specifies the priority of the global queue where its I/O operations are executed.
+        dispatch_set_target_queue(m_dispatchIO.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
+    }
 }
 
 Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (185451 => 185452)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-06-11 12:05:25 UTC (rev 185452)
@@ -126,6 +126,7 @@
 Storage::Storage(const String& baseDirectoryPath)
     : m_basePath(baseDirectoryPath)
     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
+    , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations)
     , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
     , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
     , m_serialBackgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background))
@@ -543,7 +544,7 @@
         auto& pendingRetrieveQueue = m_pendingReadOperationsByPriority[priority];
         if (pendingRetrieveQueue.isEmpty())
             continue;
-        auto readOperation = pendingRetrieveQueue.takeFirst();
+        auto readOperation = pendingRetrieveQueue.takeLast();
         auto& read = *readOperation;
         m_activeReadOperations.add(WTF::move(readOperation));
         dispatchReadOperation(read);
@@ -569,14 +570,14 @@
 {
     ASSERT(RunLoop::isMain());
 
-    const int maximumActiveWriteOperationCount { 3 };
+    const int maximumActiveWriteOperationCount { 1 };
 
     while (!m_pendingWriteOperations.isEmpty()) {
         if (m_activeWriteOperations.size() >= maximumActiveWriteOperationCount) {
             LOG(NetworkCacheStorage, "(NetworkProcess) limiting parallel writes");
             return;
         }
-        auto writeOperation = m_pendingWriteOperations.takeFirst();
+        auto writeOperation = m_pendingWriteOperations.takeLast();
         auto& write = *writeOperation;
         m_activeWriteOperations.add(WTF::move(writeOperation));
 
@@ -659,7 +660,7 @@
     if (retrieveFromMemory(m_activeWriteOperations, key, completionHandler))
         return;
 
-    m_pendingReadOperationsByPriority[priority].append(new ReadOperation { key, WTF::move(completionHandler) } );
+    m_pendingReadOperationsByPriority[priority].prepend(new ReadOperation { key, WTF::move(completionHandler) } );
     dispatchPendingReadOperations();
 }
 
@@ -671,12 +672,19 @@
     if (!m_capacity)
         return;
 
-    m_pendingWriteOperations.append(new WriteOperation { record, WTF::move(mappedBodyHandler) });
+    m_pendingWriteOperations.prepend(new WriteOperation { record, WTF::move(mappedBodyHandler) });
 
     // Add key to the filter already here as we do lookups from the pending operations too.
     addToRecordFilter(record.key);
 
-    dispatchPendingWriteOperations();
+    bool isInitialWrite = m_pendingWriteOperations.size() == 1;
+    if (!isInitialWrite)
+        return;
+
+    // Delay the start of writes a bit to avoid affecting early page load.
+    // Completing writes will dispatch more writes without delay.
+    static const auto initialWriteDelay = 1_s;
+    m_writeOperationDispatchTimer.startOneShot(initialWriteDelay);
 }
 
 void Storage::traverse(TraverseFlags flags, TraverseHandler&& traverseHandler)

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (185451 => 185452)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-06-11 12:05:25 UTC (rev 185452)
@@ -31,6 +31,7 @@
 #include "NetworkCacheBlobStorage.h"
 #include "NetworkCacheData.h"
 #include "NetworkCacheKey.h"
+#include <WebCore/Timer.h>
 #include <wtf/BloomFilter.h>
 #include <wtf/Deque.h>
 #include <wtf/HashSet.h>
@@ -150,6 +151,7 @@
 
     Deque<std::unique_ptr<WriteOperation>> m_pendingWriteOperations;
     HashSet<std::unique_ptr<WriteOperation>> m_activeWriteOperations;
+    WebCore::Timer m_writeOperationDispatchTimer;
 
     Ref<WorkQueue> m_ioQueue;
     Ref<WorkQueue> m_backgroundIOQueue;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to