Commit fb11bbe1 authored by shrike's avatar shrike Committed by Commit bot

[Mac] Fix race condition in memory pressure level reporting.

The change in https://codereview.chromium.org/2743253006 stops the Mac
memory pressure monitor from checking the current pressure level
directly on each call to GetCurrentPressureLevel(). However, if the OS
sends a pressure change notification, callers of
GetCurrentPressureLevel() may receive the old pressure level. This cl
fixes the race condition by forcing an internal pressure level update
upon receiving a pressure level change notification from the OS.

R=brettw@chromium.org,mark@chromium.org
BUG=720924

Review-Url: https://codereview.chromium.org/2877573002
Cr-Commit-Position: refs/heads/master@{#472171}
parent 80101fbd
...@@ -168,26 +168,17 @@ MemoryPressureMonitor::GetCurrentPressureLevel() { ...@@ -168,26 +168,17 @@ MemoryPressureMonitor::GetCurrentPressureLevel() {
void MemoryPressureMonitor::OnMemoryPressureChanged( void MemoryPressureMonitor::OnMemoryPressureChanged(
dispatch_source_s* event_source, dispatch_source_s* event_source,
const MemoryPressureMonitor::DispatchCallback& dispatch_callback) { const MemoryPressureMonitor::DispatchCallback& dispatch_callback) {
// Get the Chrome-equvialent memory pressure level. // The OS has sent a notification that the memory pressure level has changed.
int mac_memory_pressure_level = dispatch_source_get_data(event_source); // Go through the normal memory pressure level checking mechanism so that
MemoryPressureListener::MemoryPressureLevel memory_pressure_level = // last_pressure_level_ and UMA get updated to the current value.
MemoryPressureLevelForMacMemoryPressureLevel(mac_memory_pressure_level); UpdatePressureLevel();
// Run the callback that's waiting on memory pressure change notifications. // Run the callback that's waiting on memory pressure change notifications.
// Note that we don't bother with updating |last_pressure_level_| or // The convention is to not send notifiations on memory pressure returning to
// causing memory pressure stats to be sent to UMA. Memory pressure change // normal.
// notifications are delayed on the Mac, so the current actual memory pressure if (last_pressure_level_ !=
// level may be different than the incoming pressure level from the event.
//
// In general we don't want to take action (such as freeing memory) on
// memory pressure change events, but that's how the current system is
// designed. Given that it's incorrect to act on either stale or current
// pressure level info, it's not clear which level is better to send. For
// now stick with how it's been implemented to date, which is to send the
// stale value.
if (memory_pressure_level !=
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE)
dispatch_callback.Run(memory_pressure_level); dispatch_callback.Run(last_pressure_level_);
} }
void MemoryPressureMonitor::SetDispatchCallback( void MemoryPressureMonitor::SetDispatchCallback(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment