Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: storage/browser/quota/quota_settings.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "storage/browser/quota/quota_settings.h"
6
7 #include <algorithm>
8
9 #include "base/metrics/histogram_macros.h"
10 #include "base/sys_info.h"
11
12 #define UMA_HISTOGRAM_MBYTES(name, sample) \
13 UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \
14 10 * 1024 * 1024 /* 10TB */, 100)
15
16 namespace storage {
17
18 base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings(
19 const base::FilePath& partition_path,
20 bool is_incognito) {
21 const int64_t kMBytes = 1024 * 1024;
22
23 if (is_incognito) {
24 storage::QuotaSettings settings;
25 settings.pool_size =
26 std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10);
27 settings.per_host_quota = settings.pool_size / 3;
28 settings.refresh_interval = base::TimeDelta::Max();
29 return settings;
30 }
31
32 // The fraction of the device's storage the browser is willing to
33 // use for temporary storage, this is applied after adjusting the
34 // total to take os_accomodation into account.
35 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
36
37 // The fraction of the device's storage the browser attempts to
38 // keep free.
39 const double kShouldRemainAvailableRatio = 0.1; // 10%
40
41 // The fraction of the device's storage the browser attempts to
42 // keep free at all costs.
43 const double kMustRemainAvailableRatio = 0.01; // 1%
44
45 // Determines the portion of the temp pool that can be
46 // utilized by a single host (ie. 5 for 20%).
47 const int kPerHostTemporaryPortion = 5;
48
49 // os_accomodation is an estimate of how much storage is needed for
50 // the os and essential application code outside of the browser.
51 const int64_t kDefaultOSAccomodation =
52 #if defined(OS_ANDROID)
53 1000 * kMBytes;
54 #elif defined(OS_CHROMEOS)
55 1000 * kMBytes;
56 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
57 10000 * kMBytes;
58 #else
59 #error "Port: Need to define an OS accomodation value for unknown OS."
60 #endif
61
62 storage::QuotaSettings settings;
63
64 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path);
65 if (total == -1) {
66 LOG(ERROR) << "Unable to compute QuotaSettings.";
67 return base::nullopt;
68 }
69
70 // If our hardcoded OS accomodation is too large for the volume size, define
71 // the value as a fraction of the total volume size instead.
72 int64_t os_accomodation =
73 std::min(kDefaultOSAccomodation, static_cast<int64_t>(total * 0.8));
74 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta",
75 kDefaultOSAccomodation - os_accomodation);
76
77 int64_t adjusted_total = total - os_accomodation;
78 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio;
79
80 settings.pool_size = pool_size;
81 settings.should_remain_available = total * kShouldRemainAvailableRatio;
82 settings.must_remain_available = total * kMustRemainAvailableRatio;
83 settings.per_host_quota = pool_size / kPerHostTemporaryPortion;
84 settings.refresh_interval = base::TimeDelta::FromSeconds(60);
85 return settings;
86 }
87
88 } // namespace
OLDNEW
« no previous file with comments | « storage/browser/quota/quota_settings.h ('k') | storage/browser/quota/quota_temporary_storage_evictor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698