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

Side by Side Diff: base/memory/low_memory_observer_chromeos.cc

Issue 2783613002: WIP: memory coordinator: Check /dev/chromeos-low-mem to determine memory condition
Patch Set: Created 3 years, 8 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 2017 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 "base/memory/low_memory_observer_chromeos.h"
6
7 #include <fcntl.h>
8 #include <sys/select.h>
9 #include <sys/time.h>
10
11 #include "base/posix/eintr_wrapper.h"
12 #include "base/sys_info.h"
13
14 namespace base {
15 namespace chromeos {
16
17 namespace {
18
19 // This is the file that will exist if low memory notification is available
20 // on the device. Whenever it becomes readable, it signals a low memory
21 // condition.
22 const char kLowMemFile[] = "/dev/chromeos-low-mem";
23
24 } // namespace
25
26 LowMemoryObserver::LowMemoryObserver()
27 : low_mem_file_(HANDLE_EINTR(::open(kLowMemFile, O_RDONLY))) {
28 LOG_IF(ERROR,
29 base::SysInfo::IsRunningOnChromeOS() && !low_mem_file_.is_valid())
30 << "Cannot open kernel listener";
31 }
32
33 LowMemoryObserver::~LowMemoryObserver() {}
34
35 bool LowMemoryObserver::IsLowMemoryCondition() const {
36 if (!is_valid())
37 return false;
38
39 int fd = low_mem_file_.get();
40 fd_set fds;
41 struct timeval tv;
42
43 FD_ZERO(&fds);
44 FD_SET(fd, &fds);
45
46 tv.tv_sec = 0;
47 tv.tv_usec = 0;
48
49 return HANDLE_EINTR(select(fd + 1, &fds, NULL, NULL, &tv)) > 0;
50 }
51
52 } // namespace chromeos
53 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/low_memory_observer_chromeos.h ('k') | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698