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

Side by Side Diff: base/memory/memory_pressure_monitor_linux.h

Issue 1250093006: Added memory pressure monitor for linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-upload with less restrictive copy detection. Created 5 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_LINUX_H_
6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_LINUX_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/files/scoped_file.h"
10 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/memory_pressure_listener.h" 11 #include "base/memory/memory_pressure_listener.h"
13 #include "base/memory/memory_pressure_monitor.h" 12 #include "base/memory/memory_pressure_monitor.h"
14 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
16 15
17 namespace base { 16 namespace base {
18 namespace chromeos { 17 namespace nix {
chrisha 2015/07/24 13:25:46 This doesn't feel like the right namespace. In fa
proberge 2015/07/24 19:03:10 Done, but note that my C++ is very rusty and that
19 18
20 class TestMemoryPressureMonitor; 19 class TestMemoryPressureMonitor;
21 20
22 //////////////////////////////////////////////////////////////////////////////// 21 ////////////////////////////////////////////////////////////////////////////////
23 // MemoryPressureMonitor 22 // MemoryPressureMonitor
24 // 23 //
25 // A class to handle the observation of our free memory. It notifies the 24 // A class to handle the observation of our free memory. It notifies the
26 // MemoryPressureListener of memory fill level changes, so that it can take 25 // MemoryPressureListener of memory fill level changes, so that it can take
27 // action to reduce memory resources accordingly. 26 // action to reduce memory resources accordingly.
28 // 27 //
(...skipping 12 matching lines...) Expand all
41 // Use the system default. 40 // Use the system default.
42 THRESHOLD_DEFAULT = 0, 41 THRESHOLD_DEFAULT = 0,
43 // Try to keep as much content in memory as possible. 42 // Try to keep as much content in memory as possible.
44 THRESHOLD_CONSERVATIVE = 1, 43 THRESHOLD_CONSERVATIVE = 1,
45 // Discard caches earlier, allowing to keep more tabs in memory. 44 // Discard caches earlier, allowing to keep more tabs in memory.
46 THRESHOLD_AGGRESSIVE_CACHE_DISCARD = 2, 45 THRESHOLD_AGGRESSIVE_CACHE_DISCARD = 2,
47 // Discard tabs earlier, allowing the system to get faster. 46 // Discard tabs earlier, allowing the system to get faster.
48 THRESHOLD_AGGRESSIVE_TAB_DISCARD = 3, 47 THRESHOLD_AGGRESSIVE_TAB_DISCARD = 3,
49 // Discard caches and tabs earlier to allow the system to be faster. 48 // Discard caches and tabs earlier to allow the system to be faster.
50 THRESHOLD_AGGRESSIVE = 4 49 THRESHOLD_AGGRESSIVE = 4
51 }; 50 };
chrisha 2015/07/24 13:25:46 This ends up copying a *lot* from the ChromeOS pre
proberge 2015/07/24 19:03:10 Removed some more logic. If we were to merge the t
52 51
53 explicit MemoryPressureMonitor(MemoryPressureThresholds thresholds); 52 MemoryPressureMonitor();
54 ~MemoryPressureMonitor() override; 53 ~MemoryPressureMonitor() override;
55 54
56 // Redo the memory pressure calculation soon and call again if a critical 55 // Redo the memory pressure calculation soon and call again if a critical
57 // memory pressure prevails. Note that this call will trigger an asynchronous 56 // memory pressure prevails. Note that this call will trigger an asynchronous
58 // action which gives the system time to release memory back into the pool. 57 // action which gives the system time to release memory back into the pool.
59 void ScheduleEarlyCheck(); 58 void ScheduleEarlyCheck();
60 59
61 // Get the current memory pressure level. 60 // Get the current memory pressure level.
62 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const 61 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel()
63 override; 62 const override;
64 63
65 // Returns a type-casted version of the current memory pressure monitor. A 64 // Returns a type-casted version of the current memory pressure monitor. A
66 // simple wrapper to base::MemoryPressureMonitor::Get. 65 // simple wrapper to base::MemoryPressureMonitor::Get.
67 static MemoryPressureMonitor* Get(); 66 static MemoryPressureMonitor* Get();
68 67
69 private: 68 private:
70 friend TestMemoryPressureMonitor; 69 friend TestMemoryPressureMonitor;
71 // Starts observing the memory fill level. 70 // Starts observing the memory fill level.
72 // Calls to StartObserving should always be matched with calls to 71 // Calls to StartObserving should always be matched with calls to
73 // StopObserving. 72 // StopObserving.
(...skipping 20 matching lines...) Expand all
94 current_memory_pressure_level_; 93 current_memory_pressure_level_;
95 94
96 // A periodic timer to check for resource pressure changes. This will get 95 // A periodic timer to check for resource pressure changes. This will get
97 // replaced by a kernel triggered event system (see crbug.com/381196). 96 // replaced by a kernel triggered event system (see crbug.com/381196).
98 base::RepeatingTimer<MemoryPressureMonitor> timer_; 97 base::RepeatingTimer<MemoryPressureMonitor> timer_;
99 98
100 // To slow down the amount of moderate pressure event calls, this counter 99 // To slow down the amount of moderate pressure event calls, this counter
101 // gets used to count the number of events since the last event occured. 100 // gets used to count the number of events since the last event occured.
102 int moderate_pressure_repeat_count_; 101 int moderate_pressure_repeat_count_;
103 102
104 // The thresholds for moderate and critical pressure.
105 const int moderate_pressure_threshold_percent_;
106 const int critical_pressure_threshold_percent_;
107
108 // File descriptor used to detect low memory condition.
109 ScopedFD low_mem_file_;
110
111 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; 103 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_;
112 104
113 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); 105 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
114 }; 106 };
115 107
116 } // namespace chromeos 108 } // namespace nix
117 } // namespace base 109 } // namespace base
118 110
119 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 111 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698