Bug 1456871 - Consider increasing disk cache size, r=mayhemer
authorMichal Novotny <michal.novotny>
Tue, 22 May 2018 14:14:00 +0300
changeset 419616 b6657c5618f0c1ad287f8448301ba6131a795c15
parent 419615 8922dd89a156e93bbf3995c77db55d391502d5c2
child 419617 10f52bc1b0a47a7f0ca708d0f78e2b4d03e438c6
push id103563
push userapavel@mozilla.com
push dateWed, 23 May 2018 22:34:25 +0000
treeherdermozilla-inbound@b6657c5618f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1456871, 1356853
milestone62.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 1456871 - Consider increasing disk cache size, r=mayhemer The patch changes default cache size on desktop and mobile. The smart cache size calculation is changed to grow faster. It also introduces a cache size limit for users who have enabled clearing cache on shutdown, which should reduce number of shutdown crashes (bug 1356853).
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -47,20 +47,21 @@ namespace mozilla {
 namespace net {
 
 #define kOpenHandlesLimit        128
 #define kMetadataWriteDelay      5000
 #define kRemoveTrashStartDelay   60000 // in milliseconds
 #define kSmartSizeUpdateInterval 60000 // in milliseconds
 
 #ifdef ANDROID
-const uint32_t kMaxCacheSizeKB = 200*1024; // 200 MB
+const uint32_t kMaxCacheSizeKB = 512*1024; // 512 MB
 #else
-const uint32_t kMaxCacheSizeKB = 350*1024; // 350 MB
+const uint32_t kMaxCacheSizeKB = 1024*1024; // 1 GB
 #endif
+const uint32_t kMaxClearOnShutdownCacheSizeKB = 150*1024; // 150 MB
 
 bool
 CacheFileHandle::DispatchRelease()
 {
   if (CacheFileIOManager::IsOnIOThreadOrCeased()) {
     return false;
   }
 
@@ -4163,54 +4164,55 @@ CacheFileIOManager::SyncRemoveAllCacheFi
   }
 }
 
 // Returns default ("smart") size (in KB) of cache, given available disk space
 // (also in KB)
 static uint32_t
 SmartCacheSize(const uint32_t availKB)
 {
-  uint32_t maxSize = kMaxCacheSizeKB;
-
-  if (availKB > 100 * 1024 * 1024) {
-    return maxSize;  // skip computing if we're over 100 GB
+  uint32_t maxSize;
+
+  if (CacheObserver::ClearCacheOnShutdown()) {
+    maxSize = kMaxClearOnShutdownCacheSizeKB;
+  } else {
+    maxSize = kMaxCacheSizeKB;
+  }
+
+  if (availKB > 25 * 1024 * 1024) {
+    return maxSize;  // skip computing if we're over 25 GB
   }
 
   // Grow/shrink in 10 MB units, deliberately, so that in the common case we
   // don't shrink cache and evict items every time we startup (it's important
   // that we don't slow down startup benchmarks).
   uint32_t sz10MBs = 0;
   uint32_t avail10MBs = availKB / (1024*10);
 
-  // .5% of space above 25 GB
-  if (avail10MBs > 2500) {
-    sz10MBs += static_cast<uint32_t>((avail10MBs - 2500)*.005);
-    avail10MBs = 2500;
-  }
-  // 1% of space between 7GB -> 25 GB
+  // 2.5% of space above 7GB
   if (avail10MBs > 700) {
-    sz10MBs += static_cast<uint32_t>((avail10MBs - 700)*.01);
+    sz10MBs += static_cast<uint32_t>((avail10MBs - 700)*.025);
     avail10MBs = 700;
   }
-  // 5% of space between 500 MB -> 7 GB
+  // 7.5% of space between 500 MB -> 7 GB
   if (avail10MBs > 50) {
-    sz10MBs += static_cast<uint32_t>((avail10MBs - 50)*.05);
+    sz10MBs += static_cast<uint32_t>((avail10MBs - 50)*.075);
     avail10MBs = 50;
   }
 
 #ifdef ANDROID
   // On Android, smaller/older devices may have very little storage and
   // device owners may be sensitive to storage footprint: Use a smaller
   // percentage of available space and a smaller minimum.
 
-  // 20% of space up to 500 MB (10 MB min)
-  sz10MBs += std::max<uint32_t>(1, static_cast<uint32_t>(avail10MBs * .2));
+  // 16% of space up to 500 MB (10 MB min)
+  sz10MBs += std::max<uint32_t>(1, static_cast<uint32_t>(avail10MBs * .16));
 #else
-  // 40% of space up to 500 MB (50 MB min)
-  sz10MBs += std::max<uint32_t>(5, static_cast<uint32_t>(avail10MBs * .4));
+  // 30% of space up to 500 MB (50 MB min)
+  sz10MBs += std::max<uint32_t>(5, static_cast<uint32_t>(avail10MBs * .3));
 #endif
 
   return std::min<uint32_t>(maxSize, sz10MBs * 10 * 1024);
 }
 
 nsresult
 CacheFileIOManager::UpdateSmartCacheSize(int64_t aFreeSpace)
 {