[go: nahoru, domu]

Quota: Revert "should/must remain available" changes on low-end devices

Chrome has a "should remain available" disk space threshold; when less
than this amount is free, the effective quota for each origin drops to
0 so new writes will fail. This is present to avoid Chrome being
responsible for filling the disk which generally makes devices
unhappy. Similarly, Chrome has a "must remain available" threshold at
which point data starts being evicted - keeping the device functional,
but potentially losing user data.

In r538818 and r539735 in M66 the thresholds were changed from 10% and
1% to a fixed 2GB and 1GB respectively, to reduce the amount reserved
on high-end devices - 10% of a 1TB machine is a lot! But this did not
account for the impact on low end devices, e.g. 16GB or even 8GB,
where the reserve substantially increased, reducing the usability of
Chrome.

Change the algorithm to use min(fixed, ratio) where fixed values
remain 2GB/1GB and the ratios revert back to 10%/1%, restoring the
previous availability on storage on low end devices.

Bug: 838816
Change-Id: I7d60ae614d6be7a99cfaaa29f2aac9ce25ce861e
Reviewed-on: https://chromium-review.googlesource.com/1039879
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555600}
diff --git a/storage/browser/quota/quota_settings.cc b/storage/browser/quota/quota_settings.cc
index a3310fc..393dcd5b 100644
--- a/storage/browser/quota/quota_settings.cc
+++ b/storage/browser/quota/quota_settings.cc
@@ -68,14 +68,32 @@
   // keep free. If there is less than this amount of storage free
   // on the device, Chrome will grant 0 quota to origins.
   //
-  // Prior to M66, this was 10% of total storage instead of a fixed value.
-  const int64_t kShouldRemainAvailable = 2048 * kMBytes;  // 2GB
+  // Prior to M66, this was 10% of total storage instead of a fixed value on
+  // all devices. Now the minimum of a fixed value (2GB) and 10% is used to
+  // limit the reserve on devices with plenty of storage, but scale down for
+  // devices with extremely limited storage.
+  // *   1TB storage -- min(100GB,2GB) = 2GB
+  // * 500GB storage -- min(50GB,2GB) = 2GB
+  // *  64GB storage -- min(6GB,2GB) = 2GB
+  // *  16GB storage -- min(1.6GB,2GB) = 1.6GB
+  // *   8GB storage -- min(800MB,2GB) = 800MB
+  const int64_t kShouldRemainAvailableFixed = 2048 * kMBytes;  // 2GB
+  const double kShouldRemainAvailableRatio = 0.1;              // 10%
 
   // The amount of the device's storage the browser attempts to
   // keep free at all costs. Data will be aggressively evicted.
   //
-  // Prior to M66, this was 1% of total storage instead of a fixed value.
-  const int64_t kMustRemainAvailable = 1024 * kMBytes;  // 1GB
+  // Prior to M66, this was 1% of total storage instead of a fixed value on
+  // all devices. Now the minimum of a fixed value (1GB) and 1% is used to
+  // limit the reserve on devices with plenty of storage, but scale down for
+  // devices with extremely limited storage.
+  // *   1TB storage -- min(10GB,1GB) = 1GB
+  // * 500GB storage -- min(5GB,1GB) = 1GB
+  // *  64GB storage -- min(640MB,1GB) = 640MB
+  // *  16GB storage -- min(160MB,1GB) = 160MB
+  // *   8GB storage -- min(80MB,1GB) = 80MB
+  const int64_t kMustRemainAvailableFixed = 1024 * kMBytes;  // 1GB
+  const double kMustRemainAvailableRatio = 0.01;             // 1%
 
   // Determines the portion of the temp pool that can be
   // utilized by a single host (ie. 5 for 20%).
@@ -97,8 +115,12 @@
   int64_t pool_size = total * kTemporaryPoolSizeRatio;
 
   settings.pool_size = pool_size;
-  settings.should_remain_available = kShouldRemainAvailable;
-  settings.must_remain_available = kMustRemainAvailable;
+  settings.should_remain_available =
+      std::min(kShouldRemainAvailableFixed,
+               static_cast<int64_t>(total * kShouldRemainAvailableRatio));
+  settings.must_remain_available =
+      std::min(kMustRemainAvailableFixed,
+               static_cast<int64_t>(total * kMustRemainAvailableRatio));
   settings.per_host_quota = pool_size / kPerHostTemporaryPortion;
   settings.session_only_per_host_quota = std::min(
       RandomizeByPercent(kMaxSessionOnlyHostQuota, kRandomizedPercentage),