| Index: base/memory/memory_pressure_monitor_chromeos.cc
|
| diff --git a/base/memory/memory_pressure_monitor_chromeos.cc b/base/memory/memory_pressure_monitor_chromeos.cc
|
| index 05fcc9e1511acf80fbcc4611309ca214473e120c..120cd6be1c8d3f02c59cd700901fe7a528d00388 100644
|
| --- a/base/memory/memory_pressure_monitor_chromeos.cc
|
| +++ b/base/memory/memory_pressure_monitor_chromeos.cc
|
| @@ -4,14 +4,10 @@
|
|
|
| #include "base/memory/memory_pressure_monitor_chromeos.h"
|
|
|
| -#include <fcntl.h>
|
| -#include <sys/select.h>
|
| -
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/metrics/histogram_macros.h"
|
| -#include "base/posix/eintr_wrapper.h"
|
| #include "base/process/process_metrics.h"
|
| #include "base/single_thread_task_runner.h"
|
| -#include "base/sys_info.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "base/time/time.h"
|
|
|
| @@ -47,11 +43,6 @@ enum MemoryPressureLevelUMA {
|
| NUM_MEMORY_PRESSURE_LEVELS
|
| };
|
|
|
| -// This is the file that will exist if low memory notification is available
|
| -// on the device. Whenever it becomes readable, it signals a low memory
|
| -// condition.
|
| -const char kLowMemFile[] = "/dev/chromeos-low-mem";
|
| -
|
| // Converts a |MemoryPressureThreshold| value into a used memory percentage for
|
| // the moderate pressure event.
|
| int GetModerateMemoryThresholdInPercent(
|
| @@ -86,21 +77,6 @@ MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevelFromFillLevel(
|
| : MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
|
| }
|
|
|
| -// This function will be called less than once a second. It will check if
|
| -// the kernel has detected a low memory situation.
|
| -bool IsLowMemoryCondition(int file_descriptor) {
|
| - fd_set fds;
|
| - struct timeval tv;
|
| -
|
| - FD_ZERO(&fds);
|
| - FD_SET(file_descriptor, &fds);
|
| -
|
| - tv.tv_sec = 0;
|
| - tv.tv_usec = 0;
|
| -
|
| - return HANDLE_EINTR(select(file_descriptor + 1, &fds, NULL, NULL, &tv)) > 0;
|
| -}
|
| -
|
| } // namespace
|
|
|
| MemoryPressureMonitor::MemoryPressureMonitor(
|
| @@ -113,14 +89,11 @@ MemoryPressureMonitor::MemoryPressureMonitor(
|
| GetModerateMemoryThresholdInPercent(thresholds)),
|
| critical_pressure_threshold_percent_(
|
| GetCriticalMemoryThresholdInPercent(thresholds)),
|
| - low_mem_file_(HANDLE_EINTR(::open(kLowMemFile, O_RDONLY))),
|
| + low_mem_observer_(base::MakeUnique<LowMemoryObserver>()),
|
| dispatch_callback_(
|
| base::Bind(&MemoryPressureListener::NotifyMemoryPressure)),
|
| weak_ptr_factory_(this) {
|
| StartObserving();
|
| - LOG_IF(ERROR,
|
| - base::SysInfo::IsRunningOnChromeOS() && !low_mem_file_.is_valid())
|
| - << "Cannot open kernel listener";
|
| }
|
|
|
| MemoryPressureMonitor::~MemoryPressureMonitor() {
|
| @@ -194,7 +167,7 @@ void MemoryPressureMonitor::CheckMemoryPressure() {
|
| // computation come to similar results and then remove this override again.
|
| // TODO(skuhne): Add some testing framework here to see how close the kernel
|
| // and the internal functions are.
|
| - if (low_mem_file_.is_valid() && IsLowMemoryCondition(low_mem_file_.get())) {
|
| + if (low_mem_observer_->IsLowMemoryCondition()) {
|
| current_memory_pressure_level_ =
|
| MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL;
|
| } else {
|
| @@ -205,9 +178,9 @@ void MemoryPressureMonitor::CheckMemoryPressure() {
|
|
|
| // When listening to the kernel, we ignore the reported memory pressure
|
| // level from our own computation and reduce critical to moderate.
|
| - if (low_mem_file_.is_valid() &&
|
| + if (low_mem_observer_->is_valid() &&
|
| current_memory_pressure_level_ ==
|
| - MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
|
| + MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
|
| current_memory_pressure_level_ =
|
| MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
|
| }
|
|
|