summaryrefslogtreecommitdiffstats
path: root/storage/browser
diff options
context:
space:
mode:
authormichaeln <michaeln@chromium.org>2016-03-03 15:35:53 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-03 23:36:55 +0000
commitfcc8de1ae61555aae1c50c2caf8667ca7d451440 (patch)
tree94baa59cced2986f816997aee31b2ea880feae3e /storage/browser
parentb6748984a312cb2decbf3c220548fea11d8763d0 (diff)
downloadchromium_src-fcc8de1ae61555aae1c50c2caf8667ca7d451440.zip
chromium_src-fcc8de1ae61555aae1c50c2caf8667ca7d451440.tar.gz
chromium_src-fcc8de1ae61555aae1c50c2caf8667ca7d451440.tar.bz2
QuotaManager: Add a trigger to start eviction solely on the basis of low disk space.
If available space is less than 10% of the total size of the volume, we consider evicting something. This is being done in preparation of changing the basis of quota calculations to be more focused on the size of the drive and remaining space available. Currently the calculations are mostly based on how much chrome is using compared to the amount of free space. BUG=520318 Review URL: https://codereview.chromium.org/1705793003 Cr-Commit-Position: refs/heads/master@{#379134}
Diffstat (limited to 'storage/browser')
-rw-r--r--storage/browser/quota/quota_manager.cc49
-rw-r--r--storage/browser/quota/quota_manager.h34
-rw-r--r--storage/browser/quota/quota_temporary_storage_evictor.cc44
-rw-r--r--storage/browser/quota/quota_temporary_storage_evictor.h17
4 files changed, 104 insertions, 40 deletions
diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc
index 59cb6fb..5000061 100644
--- a/storage/browser/quota/quota_manager.cc
+++ b/storage/browser/quota/quota_manager.cc
@@ -886,9 +886,8 @@ QuotaManager::QuotaManager(
is_getting_eviction_origin_(false),
temporary_quota_initialized_(false),
temporary_quota_override_(-1),
- desired_available_space_(-1),
special_storage_policy_(special_storage_policy),
- get_disk_space_fn_(&QuotaManager::CallSystemGetAmountOfFreeDiskSpace),
+ get_volume_info_fn_(&QuotaManager::GetVolumeInfo),
storage_monitor_(new StorageMonitor(this)),
weak_factory_(this) {}
@@ -922,7 +921,6 @@ void QuotaManager::GetUsageAndQuotaForWebApps(
UsageAndQuotaCallbackDispatcher* dispatcher =
new UsageAndQuotaCallbackDispatcher(this);
- UsageAndQuota usage_and_quota;
if (unlimited) {
dispatcher->set_quota(kNoLimit);
} else {
@@ -1036,11 +1034,13 @@ void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
// crbug.com/349708
TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace");
- PostTaskAndReplyWithResult(db_thread_.get(),
- FROM_HERE,
- base::Bind(get_disk_space_fn_, profile_path_),
- base::Bind(&QuotaManager::DidGetAvailableSpace,
- weak_factory_.GetWeakPtr()));
+ PostTaskAndReplyWithResult(
+ db_thread_.get(),
+ FROM_HERE,
+ base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace,
+ get_volume_info_fn_, profile_path_),
+ base::Bind(&QuotaManager::DidGetAvailableSpace,
+ weak_factory_.GetWeakPtr()));
}
void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
@@ -1626,6 +1626,32 @@ void QuotaManager::GetUsageAndQuotaForEviction(
dispatcher->WaitForResults(callback);
}
+void QuotaManager::AsyncGetVolumeInfo(
+ const VolumeInfoCallback& callback) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+ uint64_t* available_space = new uint64_t(0);
+ uint64_t* total_space = new uint64_t(0);
+ PostTaskAndReplyWithResult(
+ db_thread_.get(),
+ FROM_HERE,
+ base::Bind(get_volume_info_fn_,
+ profile_path_,
+ base::Unretained(available_space),
+ base::Unretained(total_space)),
+ base::Bind(&QuotaManager::DidGetVolumeInfo,
+ weak_factory_.GetWeakPtr(),
+ callback,
+ base::Owned(available_space),
+ base::Owned(total_space)));
+}
+
+void QuotaManager::DidGetVolumeInfo(
+ const VolumeInfoCallback& callback,
+ uint64_t* available_space, uint64_t* total_space, bool success) {
+ DCHECK(io_thread_->BelongsToCurrentThread());
+ callback.Run(success, *available_space, *total_space);
+}
+
void QuotaManager::GetLRUOrigin(StorageType type,
const GetOriginCallback& callback) {
LazyInitialize();
@@ -1769,8 +1795,9 @@ void QuotaManager::PostTaskAndReplyWithResultForDBThread(
reply);
}
-//static
-int64_t QuotaManager::CallSystemGetAmountOfFreeDiskSpace(
+// static
+int64_t QuotaManager::CallGetAmountOfFreeDiskSpace(
+ GetVolumeInfoFn get_volume_info_fn,
const base::FilePath& profile_path) {
// crbug.com/349708
TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace");
@@ -1779,7 +1806,7 @@ int64_t QuotaManager::CallSystemGetAmountOfFreeDiskSpace(
return 0;
}
uint64_t available, total;
- if (!QuotaManager::GetVolumeInfo(profile_path, &available, &total)) {
+ if (!get_volume_info_fn(profile_path, &available, &total)) {
return 0;
}
UMA_HISTOGRAM_MBYTES("Quota.AvailableDiskSpace", available);
diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h
index 16e3527..d3f3a3f 100644
--- a/storage/browser/quota/quota_manager.h
+++ b/storage/browser/quota/quota_manager.h
@@ -93,10 +93,11 @@ class STORAGE_EXPORT QuotaEvictionPolicy {
// An interface called by QuotaTemporaryStorageEvictor.
class STORAGE_EXPORT QuotaEvictionHandler {
public:
- typedef StatusCallback EvictOriginDataCallback;
- typedef base::Callback<void(QuotaStatusCode status,
- const UsageAndQuota& usage_and_quota)>
- UsageAndQuotaCallback;
+ using EvictOriginDataCallback = StatusCallback;
+ using UsageAndQuotaCallback = base::Callback<
+ void(QuotaStatusCode status, const UsageAndQuota& usage_and_quota)>;
+ using VolumeInfoCallback = base::Callback<
+ void(bool success, uint64_t available_space, uint64_t total_space)>;
// Returns next origin to evict. It might return an empty GURL when there are
// no evictable origins.
@@ -110,6 +111,7 @@ class STORAGE_EXPORT QuotaEvictionHandler {
StorageType type,
const EvictOriginDataCallback& callback) = 0;
+ virtual void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) = 0;
virtual void GetUsageAndQuotaForEviction(
const UsageAndQuotaCallback& callback) = 0;
@@ -316,9 +318,10 @@ class STORAGE_EXPORT QuotaManager
typedef std::vector<QuotaTableEntry> QuotaTableEntries;
typedef std::vector<OriginInfoTableEntry> OriginInfoTableEntries;
- // Function pointer type used to store the function which returns the
- // available disk space for the disk containing the given FilePath.
- typedef int64_t (*GetAvailableDiskSpaceFn)(const base::FilePath&);
+ // Function pointer type used to store the function which returns
+ // information about the volume containing the given FilePath.
+ using GetVolumeInfoFn = bool(*)(const base::FilePath&,
+ uint64_t* available, uint64_t* total);
typedef base::Callback<void(const QuotaTableEntries&)>
DumpQuotaTableCallback;
@@ -410,6 +413,11 @@ class STORAGE_EXPORT QuotaManager
const EvictOriginDataCallback& callback) override;
void GetUsageAndQuotaForEviction(
const UsageAndQuotaCallback& callback) override;
+ void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override;
+
+ void DidGetVolumeInfo(
+ const VolumeInfoCallback& callback,
+ uint64_t* available_space, uint64_t* total_space, bool success);
void GetLRUOrigin(StorageType type, const GetOriginCallback& callback);
@@ -442,7 +450,8 @@ class STORAGE_EXPORT QuotaManager
const base::Callback<bool(QuotaDatabase*)>& task,
const base::Callback<void(bool)>& reply);
- static int64_t CallSystemGetAmountOfFreeDiskSpace(
+ static int64_t CallGetAmountOfFreeDiskSpace(
+ GetVolumeInfoFn get_vol_info_fn,
const base::FilePath& profile_path);
static bool GetVolumeInfo(const base::FilePath& path,
uint64_t* available_space,
@@ -480,7 +489,6 @@ class STORAGE_EXPORT QuotaManager
bool temporary_quota_initialized_;
int64_t temporary_quota_override_;
-
int64_t desired_available_space_;
// Map from origin to count.
@@ -492,10 +500,10 @@ class STORAGE_EXPORT QuotaManager
base::RepeatingTimer histogram_timer_;
- // Pointer to the function used to get the available disk space. This is
- // overwritten by QuotaManagerTest in order to attain a deterministic reported
- // value. The default value points to base::SysInfo::AmountOfFreeDiskSpace.
- GetAvailableDiskSpaceFn get_disk_space_fn_;
+ // Pointer to the function used to get volume information. This is
+ // overwritten by QuotaManagerTest in order to attain deterministic reported
+ // values. The default value points to QuotaManager::GetVolumeInfo.
+ GetVolumeInfoFn get_volume_info_fn_;
scoped_ptr<StorageMonitor> storage_monitor_;
diff --git a/storage/browser/quota/quota_temporary_storage_evictor.cc b/storage/browser/quota/quota_temporary_storage_evictor.cc
index 0fdc49a..9174377 100644
--- a/storage/browser/quota/quota_temporary_storage_evictor.cc
+++ b/storage/browser/quota/quota_temporary_storage_evictor.cc
@@ -29,12 +29,15 @@ const int64_t kMBytes = 1024 * 1024;
const double kUsageRatioToStartEviction = 0.7;
const int kThresholdOfErrorsToStopEviction = 5;
const int kHistogramReportIntervalMinutes = 60;
+const double kMustRemainAvailableRatio = 0.1;
+const int64_t kDefaultMustRemainAvailableSpace = 1024 * kMBytes;
+const double kDiskSpaceShortageAllowanceRatio = 0.5;
}
namespace storage {
const int QuotaTemporaryStorageEvictor::
- kMinAvailableDiskSpaceToStartEvictionNotSpecified = -1;
+ kMinAvailableToStartEvictionNotSpecified = -1;
QuotaTemporaryStorageEvictor::EvictionRoundStatistics::EvictionRoundStatistics()
: in_round(false),
@@ -49,8 +52,8 @@ QuotaTemporaryStorageEvictor::EvictionRoundStatistics::EvictionRoundStatistics()
QuotaTemporaryStorageEvictor::QuotaTemporaryStorageEvictor(
QuotaEvictionHandler* quota_eviction_handler,
int64_t interval_ms)
- : min_available_disk_space_to_start_eviction_(
- kMinAvailableDiskSpaceToStartEvictionNotSpecified),
+ : min_available_to_start_eviction_(
+ kMinAvailableToStartEvictionNotSpecified),
quota_eviction_handler_(quota_eviction_handler),
interval_ms_(interval_ms),
repeated_eviction_(true),
@@ -159,13 +162,33 @@ void QuotaTemporaryStorageEvictor::StartEvictionTimerWithDelay(int delay_ms) {
void QuotaTemporaryStorageEvictor::ConsiderEviction() {
OnEvictionRoundStarted();
- // Get usage and disk space, then continue.
+ if (min_available_to_start_eviction_ ==
+ kMinAvailableToStartEvictionNotSpecified) {
+ quota_eviction_handler_->AsyncGetVolumeInfo(
+ base::Bind(&QuotaTemporaryStorageEvictor::OnGotVolumeInfo,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ quota_eviction_handler_->GetUsageAndQuotaForEviction(
+ base::Bind(&QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction,
+ weak_factory_.GetWeakPtr(),
+ min_available_to_start_eviction_));
+ }
+}
+
+void QuotaTemporaryStorageEvictor::OnGotVolumeInfo(
+ bool success, uint64_t available_space, uint64_t total_size) {
+ // Compute how much to keep free as a function of total disk size.
+ int64_t must_remain_available_space = success ?
+ static_cast<int64_t>(total_size * kMustRemainAvailableRatio) :
+ kDefaultMustRemainAvailableSpace;
+
quota_eviction_handler_->GetUsageAndQuotaForEviction(
base::Bind(&QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction,
- weak_factory_.GetWeakPtr()));
+ weak_factory_.GetWeakPtr(), must_remain_available_space));
}
void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction(
+ int64_t must_remain_available_space,
QuotaStatusCode status,
const UsageAndQuota& qau) {
DCHECK(CalledOnValidThread());
@@ -180,11 +203,16 @@ void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction(
static_cast<int64_t>(0),
usage - static_cast<int64_t>(qau.quota * kUsageRatioToStartEviction));
- // min_available_disk_space_to_start_eviction_ might be < 0 if no value
- // is explicitly configured yet.
int64_t diskspace_shortage = std::max(
static_cast<int64_t>(0),
- min_available_disk_space_to_start_eviction_ - qau.available_disk_space);
+ must_remain_available_space - qau.available_disk_space);
+
+ // If we're using so little that freeing all of it wouldn't help,
+ // don't let the low space condition cause us to delete it all.
+ if (usage < static_cast<int64_t>(diskspace_shortage *
+ kDiskSpaceShortageAllowanceRatio)) {
+ diskspace_shortage = 0;
+ }
if (!round_statistics_.is_initialized) {
round_statistics_.usage_overage_at_round = usage_overage;
diff --git a/storage/browser/quota/quota_temporary_storage_evictor.h b/storage/browser/quota/quota_temporary_storage_evictor.h
index f3cdf3a..8039426 100644
--- a/storage/browser/quota/quota_temporary_storage_evictor.h
+++ b/storage/browser/quota/quota_temporary_storage_evictor.h
@@ -78,15 +78,12 @@ class STORAGE_EXPORT QuotaTemporaryStorageEvictor : public base::NonThreadSafe {
void ReportPerHourHistogram();
void Start();
- int64_t min_available_disk_space_to_start_eviction() {
- return min_available_disk_space_to_start_eviction_;
- }
void reset_min_available_disk_space_to_start_eviction() {
- min_available_disk_space_to_start_eviction_ =
- kMinAvailableDiskSpaceToStartEvictionNotSpecified;
+ min_available_to_start_eviction_ =
+ kMinAvailableToStartEvictionNotSpecified;
}
void set_min_available_disk_space_to_start_eviction(int64_t value) {
- min_available_disk_space_to_start_eviction_ = value;
+ min_available_to_start_eviction_ = value;
}
private:
@@ -94,7 +91,11 @@ class STORAGE_EXPORT QuotaTemporaryStorageEvictor : public base::NonThreadSafe {
void StartEvictionTimerWithDelay(int delay_ms);
void ConsiderEviction();
+ void OnGotVolumeInfo(bool success,
+ uint64_t available_space,
+ uint64_t total_size);
void OnGotUsageAndQuotaForEviction(
+ int64_t must_remain_available_space,
QuotaStatusCode status,
const UsageAndQuota& quota_and_usage);
void OnGotEvictionOrigin(const GURL& origin);
@@ -108,9 +109,9 @@ class STORAGE_EXPORT QuotaTemporaryStorageEvictor : public base::NonThreadSafe {
repeated_eviction_ = repeated_eviction;
}
- static const int kMinAvailableDiskSpaceToStartEvictionNotSpecified;
+ static const int kMinAvailableToStartEvictionNotSpecified;
- int64_t min_available_disk_space_to_start_eviction_;
+ int64_t min_available_to_start_eviction_;
// Not owned; quota_eviction_handler owns us.
QuotaEvictionHandler* quota_eviction_handler_;