Bug 1294183 - Make HTTP cache write leader-class resources with more priority, r=michal
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 12 Oct 2016 10:32:00 +0200
changeset 362863 c09788a9b52bbed072ba9c4714f36c777d489ed1
parent 362862 ba66a8bb5b3da146e65251bc2d2771c87f4d593c
child 362864 d9dd5cab64b250cb706e4eb3b1cc8179bb65eb8f
push id1369
push userjlorenzo@mozilla.com
push dateMon, 27 Feb 2017 14:59:41 +0000
treeherdermozilla-release@d75a1dba431f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs1294183
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1294183 - Make HTTP cache write leader-class resources with more priority, r=michal
netwerk/cache2/CacheFileIOManager.cpp
netwerk/cache2/CacheIOThread.cpp
netwerk/cache2/CacheIOThread.h
netwerk/cache2/CacheStorageService.cpp
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/histogram-whitelists.json
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -568,17 +568,17 @@ public:
   }
 
   void PostAndWait()
   {
     MonitorAutoLock mon(mMonitor);
 
     DebugOnly<nsresult> rv;
     rv = CacheFileIOManager::gInstance->mIOThread->Dispatch(
-      this, CacheIOThread::CLOSE);
+      this, CacheIOThread::WRITE); // When writes and closing of handles is done
     MOZ_ASSERT(NS_SUCCEEDED(rv));
 
     PRIntervalTime const waitTime = PR_MillisecondsToInterval(1000);
     while (!mNotified) {
       mon.Wait(waitTime);
       if (!mNotified) {
         // If there is any IO blocking on the IO thread, this will
         // try to cancel it.  Returns no later than after two seconds.
@@ -1921,17 +1921,19 @@ CacheFileIOManager::Write(CacheFileHandl
       // releasing the buffer. We must release it even in case of failure.
       free(const_cast<char *>(aBuf));
     }
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<WriteEvent> ev = new WriteEvent(aHandle, aOffset, aBuf, aCount,
                                            aValidate, aTruncate, aCallback);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::WRITE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 static nsresult
 TruncFile(PRFileDesc *aFD, int64_t aEOF)
 {
@@ -2283,17 +2285,19 @@ CacheFileIOManager::ReleaseNSPRHandle(Ca
   nsresult rv;
   RefPtr<CacheFileIOManager> ioMan = gInstance;
 
   if (aHandle->IsClosed() || !ioMan) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<ReleaseNSPRHandleEvent> ev = new ReleaseNSPRHandleEvent(aHandle);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::CLOSE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 CacheFileIOManager::MaybeReleaseNSPRHandleInternal(CacheFileHandle *aHandle,
                                                    bool aIgnoreShutdownLag)
@@ -2365,17 +2369,19 @@ CacheFileIOManager::TruncateSeekSetEOF(C
 
   if (aHandle->IsClosed() || (aCallback && aCallback->IsKilled()) || !ioMan) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<TruncateSeekSetEOFEvent> ev = new TruncateSeekSetEOFEvent(
                                            aHandle, aTruncatePos, aEOFPos,
                                            aCallback);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::WRITE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 // static
 void CacheFileIOManager::GetCacheDirectory(nsIFile** result)
 {
@@ -2594,17 +2600,19 @@ CacheFileIOManager::RenameFile(CacheFile
   }
 
   if (!aHandle->IsSpecialFile()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<RenameFileEvent> ev = new RenameFileEvent(aHandle, aNewName,
                                                      aCallback);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::WRITE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 CacheFileIOManager::RenameFileInternal(CacheFileHandle *aHandle,
                                        const nsACString &aNewName)
@@ -3498,17 +3506,19 @@ CacheFileIOManager::InitIndexEntry(Cache
   }
 
   if (aHandle->IsSpecialFile()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<InitIndexEntryEvent> ev =
     new InitIndexEntryEvent(aHandle, aAppId, aAnonymous, aInIsolatedMozBrowser, aPinning);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::WRITE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 // static
 nsresult
 CacheFileIOManager::UpdateIndexEntry(CacheFileHandle *aHandle,
@@ -3528,17 +3538,19 @@ CacheFileIOManager::UpdateIndexEntry(Cac
   }
 
   if (aHandle->IsSpecialFile()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<UpdateIndexEntryEvent> ev =
     new UpdateIndexEntryEvent(aHandle, aFrecency, aExpirationTime);
-  rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::WRITE);
+  rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
+                                  ? CacheIOThread::WRITE_PRIORITY
+                                  : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 CacheFileIOManager::CreateFile(CacheFileHandle *aHandle)
 {
--- a/netwerk/cache2/CacheIOThread.cpp
+++ b/netwerk/cache2/CacheIOThread.cpp
@@ -39,24 +39,25 @@ CacheIOTelemetry::mMinLengthToReport[Cac
 // static
 void CacheIOTelemetry::Report(uint32_t aLevel, CacheIOTelemetry::size_type aLength)
 {
   if (mMinLengthToReport[aLevel] > aLength) {
     return;
   }
 
   static Telemetry::ID telemetryID[] = {
-    Telemetry::HTTP_CACHE_IO_QUEUE_OPEN_PRIORITY,
-    Telemetry::HTTP_CACHE_IO_QUEUE_READ_PRIORITY,
-    Telemetry::HTTP_CACHE_IO_QUEUE_OPEN,
-    Telemetry::HTTP_CACHE_IO_QUEUE_READ,
-    Telemetry::HTTP_CACHE_IO_QUEUE_MANAGEMENT,
-    Telemetry::HTTP_CACHE_IO_QUEUE_WRITE,
-    Telemetry::HTTP_CACHE_IO_QUEUE_INDEX,
-    Telemetry::HTTP_CACHE_IO_QUEUE_EVICT
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN_PRIORITY,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_READ_PRIORITY,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_MANAGEMENT,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_OPEN,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_READ,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE_PRIORITY,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_WRITE,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_INDEX,
+    Telemetry::HTTP_CACHE_IO_QUEUE_2_EVICT
   };
 
   // Each bucket is a multiply of kGranularity (30, 60, 90..., 300+)
   aLength = (aLength / kGranularity);
   // Next time report only when over the current length + kGranularity
   mMinLengthToReport[aLevel] = (aLength + 1) * kGranularity;
 
   // 10 is number of buckets we have in each probe
--- a/netwerk/cache2/CacheIOThread.h
+++ b/netwerk/cache2/CacheIOThread.h
@@ -38,21 +38,21 @@ public:
 
   CacheIOThread();
 
   typedef nsTArray<nsCOMPtr<nsIRunnable>> EventQueue;
 
   enum ELevel : uint32_t {
     OPEN_PRIORITY,
     READ_PRIORITY,
+    MANAGEMENT, // Doesn't do any actual I/O
     OPEN,
     READ,
-    MANAGEMENT,
+    WRITE_PRIORITY,
     WRITE,
-    CLOSE = WRITE,
     INDEX,
     EVICT,
     LAST_LEVEL,
 
     // This is actually executed as the first level, but we want this enum
     // value merely as an indicator while other values are used as indexes
     // to the queue array.  Hence put at end and not as the first.
     XPCOM_LEVEL
--- a/netwerk/cache2/CacheStorageService.cpp
+++ b/netwerk/cache2/CacheStorageService.cpp
@@ -2270,13 +2270,13 @@ CacheStorageService::Flush(nsIObserver* 
   observerService->AddObserver(aObserver, "cacheservice:purge-memory-pools", false);
 
   // This runnable will do the purging and when done, notifies the above observer.
   // We dispatch it to the CLOSE level, so all data writes scheduled up to this time
   // will be done before this purging happens.
   RefPtr<CacheStorageService::PurgeFromMemoryRunnable> r =
     new CacheStorageService::PurgeFromMemoryRunnable(this, CacheEntry::PURGE_WHOLE);
 
-  return thread->Dispatch(r, CacheIOThread::CLOSE);
+  return thread->Dispatch(r, CacheIOThread::WRITE);
 }
 
 } // namespace net
 } // namespace mozilla
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -2166,60 +2166,84 @@
     "n_values": 5,
     "description": "HTTP Offline Cache Hit, Reval, Failed-Reval, Miss"
   },
   "HTTP_OFFLINE_CACHE_DOCUMENT_LOAD": {
     "expires_in_version": "never",
     "kind": "boolean",
     "description": "Rate of page load from offline cache"
   },
-  "HTTP_CACHE_IO_QUEUE_OPEN_PRIORITY": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_OPEN_PRIORITY": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_READ_PRIORITY": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_READ_PRIORITY": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_OPEN": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_MANAGEMENT": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
+    "kind": "enumerated",
+    "n_values": 10,
+    "description": "HTTP Cache IO queue length"
+  },
+  "HTTP_CACHE_IO_QUEUE_2_OPEN": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_READ": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_READ": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_MANAGEMENT": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_WRITE": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_WRITE": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_WRITE_PRIORITY": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_INDEX": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_INDEX": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
-  "HTTP_CACHE_IO_QUEUE_EVICT": {
-    "expires_in_version": "54",
+  "HTTP_CACHE_IO_QUEUE_2_EVICT": {
+    "alert_emails": ["hbambas@mozilla.com"],
+    "bug_numbers": [1294183],
+    "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "HTTP Cache IO queue length"
   },
   "CACHE_DEVICE_SEARCH_2": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 10000,
--- a/toolkit/components/telemetry/histogram-whitelists.json
+++ b/toolkit/components/telemetry/histogram-whitelists.json
@@ -311,24 +311,16 @@
     "HTTP_CONNECTION_ENTRY_CACHE_HIT_1",
     "HTTP_CONTENT_ENCODING",
     "HTTP_DISK_CACHE_DISPOSITION_2",
     "HTTP_DISK_CACHE_OVERHEAD",
     "HTTP_KBREAD_PER_CONN",
     "HTTP_MEMORY_CACHE_DISPOSITION_2",
     "HTTP_OFFLINE_CACHE_DISPOSITION_2",
     "HTTP_OFFLINE_CACHE_DOCUMENT_LOAD",
-    "HTTP_CACHE_IO_QUEUE_OPEN_PRIORITY",
-    "HTTP_CACHE_IO_QUEUE_READ_PRIORITY",
-    "HTTP_CACHE_IO_QUEUE_OPEN",
-    "HTTP_CACHE_IO_QUEUE_READ",
-    "HTTP_CACHE_IO_QUEUE_MANAGEMENT",
-    "HTTP_CACHE_IO_QUEUE_WRITE",
-    "HTTP_CACHE_IO_QUEUE_INDEX",
-    "HTTP_CACHE_IO_QUEUE_EVICT",
     "HTTP_PAGELOAD_IS_SSL",
     "HTTP_PAGE_CACHE_READ_TIME",
     "HTTP_PAGE_CACHE_READ_TIME_V2",
     "HTTP_PAGE_COMPLETE_LOAD",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED_V2",
     "HTTP_PAGE_COMPLETE_LOAD_NET",
     "HTTP_PAGE_COMPLETE_LOAD_NET_V2",
@@ -1155,24 +1147,16 @@
     "HTTP_CONNECTION_ENTRY_CACHE_HIT_1",
     "HTTP_CONTENT_ENCODING",
     "HTTP_DISK_CACHE_DISPOSITION_2",
     "HTTP_DISK_CACHE_OVERHEAD",
     "HTTP_KBREAD_PER_CONN",
     "HTTP_MEMORY_CACHE_DISPOSITION_2",
     "HTTP_OFFLINE_CACHE_DISPOSITION_2",
     "HTTP_OFFLINE_CACHE_DOCUMENT_LOAD",
-    "HTTP_CACHE_IO_QUEUE_OPEN_PRIORITY",
-    "HTTP_CACHE_IO_QUEUE_READ_PRIORITY",
-    "HTTP_CACHE_IO_QUEUE_OPEN",
-    "HTTP_CACHE_IO_QUEUE_READ",
-    "HTTP_CACHE_IO_QUEUE_MANAGEMENT",
-    "HTTP_CACHE_IO_QUEUE_WRITE",
-    "HTTP_CACHE_IO_QUEUE_INDEX",
-    "HTTP_CACHE_IO_QUEUE_EVICT",
     "HTTP_PAGELOAD_IS_SSL",
     "HTTP_PAGE_CACHE_READ_TIME",
     "HTTP_PAGE_CACHE_READ_TIME_V2",
     "HTTP_PAGE_COMPLETE_LOAD",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED",
     "HTTP_PAGE_COMPLETE_LOAD_CACHED_V2",
     "HTTP_PAGE_COMPLETE_LOAD_NET",
     "HTTP_PAGE_COMPLETE_LOAD_NET_V2",