Skip to content

Commit

Permalink
Don't expire history immediately on waking from sleep.
Browse files Browse the repository at this point in the history
History expiration is very disk intensive. When the machine wakes from sleep, it
potentially also needs to read its memory from disk, thus causing heavy
contention.

Bug: 808031
Change-Id: If9a4cfac8a0b323489364fc5c9ad7d72bafb0333
Reviewed-on: https://chromium-review.googlesource.com/1024290
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552947}
  • Loading branch information
erikchen authored and Commit Bot committed Apr 24, 2018
1 parent f7adb4d commit f227db3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions components/history/core/browser/expire_history_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const int kExpirationDelaySec = 30;
// iteration, so we want to wait longer before checking to avoid wasting CPU.
const int kExpirationEmptyDelayMin = 5;

// If the expiration timer is delayed by over an hour, then assume that the
// machine went to sleep.
constexpr base::TimeDelta kExpirationSleepWakeupThreshold =
base::TimeDelta::FromHours(1);

// The minimum number of hours between checking for old on-demand favicons that
// should be cleared.
const int kClearOnDemandFaviconsIntervalHours = 24;
Expand Down Expand Up @@ -524,6 +529,7 @@ void ExpireHistoryBackend::ScheduleExpire() {
delay = base::TimeDelta::FromSeconds(kExpirationDelaySec);
}

expected_expiration_time_ = base::Time::Now() + delay;
task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&ExpireHistoryBackend::DoExpireIteration,
Expand All @@ -534,6 +540,21 @@ void ExpireHistoryBackend::ScheduleExpire() {
void ExpireHistoryBackend::DoExpireIteration() {
DCHECK(!work_queue_.empty()) << "queue has to be non-empty";

// If the timer is firing more than an hour later than expected, than the
// machine likely just woke from sleep/hibernation. There is potentially a lot
// of expiring that needs to happen. Wait for 5 minutes before starting to do
// any expiry, to avoid conflicting with other work that happens on waking
// from sleep.
if (base::Time::Now() - expected_expiration_time_ >
kExpirationSleepWakeupThreshold) {
task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&ExpireHistoryBackend::ScheduleExpire,
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMinutes(kExpirationEmptyDelayMin));
return;
}

const ExpiringVisitsReader* reader = work_queue_.front();
bool more_to_expire = ExpireSomeOldHistory(
GetCurrentExpirationTime(), reader, kNumExpirePerIteration);
Expand Down
3 changes: 3 additions & 0 deletions components/history/core/browser/expire_history_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class ExpireHistoryBackend {
// The threshold for "old" history where we will automatically delete it.
base::TimeDelta expiration_threshold_;

// The time at which we expect the expiration code to run.
base::Time expected_expiration_time_;

// The lastly used threshold for "old" on-demand favicons.
base::Time last_on_demand_expiration_threshold_;

Expand Down

0 comments on commit f227db3

Please sign in to comment.