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

Side by Side Diff: content/browser/memory/memory_state_updater.h

Issue 2718963002: Drop the global memory state from memory coordinator (Closed)
Patch Set: tweak Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ 5 #ifndef CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_
6 #define CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ 6 #define CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_
7 7
8 #include "base/cancelable_callback.h" 8 #include "base/cancelable_callback.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "content/browser/memory/memory_coordinator_impl.h" 11 #include "content/browser/memory/memory_coordinator_impl.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 // TODO(bashi): Rename MemoryStateUpdater -> MemoryConditionObserver?
17 // TODO(bashi): Update the comments.
18
16 // MemoryStateUpdater is an internal implementation of MemoryCoordinator 19 // MemoryStateUpdater is an internal implementation of MemoryCoordinator
17 // which uses a heuristic to determine a single global memory state. 20 // which uses a heuristic to determine a single global memory state.
18 // In the current implementation browser process and renderer processes share 21 // In the current implementation browser process and renderer processes share
19 // the global state; the memory coordinator will notify the global state to 22 // the global state; the memory coordinator will notify the global state to
20 // all background renderers if the state has changed. 23 // all background renderers if the state has changed.
21 // 24 //
22 // State calculation: 25 // State calculation:
23 // MemoryStateUpdater uses followings to determine the global state: 26 // MemoryStateUpdater uses followings to determine the global state:
24 // * Compute "number of renderers which can be created until the system will 27 // * Compute "number of renderers which can be created until the system will
25 // be in a critical state". Call this N. 28 // be in a critical state". Call this N.
26 // (See memory_monitor.h for the definition of "critical") 29 // (See memory_monitor.h for the definition of "critical")
27 // * Covert N to a memory state using some thresholds/hysteresis for each state. 30 // * Covert N to a memory state using some thresholds/hysteresis for each state.
28 // Once a state is changed to a limited state, larger N will be needed to go 31 // Once a state is changed to a limited state, larger N will be needed to go
29 // back to a relaxed state. (e.g. THROTTLED -> NORMAL) 32 // back to a relaxed state. (e.g. THROTTLED -> NORMAL)
30 // * Once a state is changed, it remains the same for a certain period of time. 33 // * Once a state is changed, it remains the same for a certain period of time.
31 class CONTENT_EXPORT MemoryStateUpdater { 34 class CONTENT_EXPORT MemoryStateUpdater {
32 public: 35 public:
33 // |coordinator| must outlive than this instance. 36 // |coordinator| must outlive than this instance.
34 MemoryStateUpdater(MemoryCoordinatorImpl* coordinator, 37 MemoryStateUpdater(MemoryCoordinatorImpl* coordinator,
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 38 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
36 ~MemoryStateUpdater(); 39 ~MemoryStateUpdater();
37 40
38 // Calculates the next global state from the amount of free memory using 41 // Schedules a task to update memory condition. The task will be executed
39 // a heuristic.
40 base::MemoryState CalculateNextState();
41
42 // Schedules a task to update the global state. The task will be executed
43 // after |delay| has passed. 42 // after |delay| has passed.
44 void ScheduleUpdateState(base::TimeDelta delay); 43 void ScheduleUpdateCondition(base::TimeDelta delay);
45 44
46 private: 45 private:
47 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState); 46 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, CalculateNextState);
48 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateState); 47 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, UpdateState);
49 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting); 48 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, SetMemoryStateForTesting);
50 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState); 49 FRIEND_TEST_ALL_PREFIXES(MemoryCoordinatorImplTest, ForceSetGlobalState);
51 50
52 // Periodically called to update the global state. 51 // Calculates next memory condition from the amount of free memory using
53 void UpdateState(); 52 // a heuristic.
53 MemoryCondition CalculateNextCondition();
54
55 // Periodically called to update the memory condition.
56 void UpdateCondition();
54 57
55 MemoryCoordinatorImpl* coordinator_; 58 MemoryCoordinatorImpl* coordinator_;
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
57 base::CancelableClosure update_state_closure_; 60 base::CancelableClosure update_condition_closure_;
58 61
59 // Sets up parameters for the heuristic. 62 // Sets up parameters for the heuristic.
60 void InitializeParameters(); 63 void InitializeParameters();
61 64
62 // Validates parameters defined below. 65 // Validates parameters defined below.
63 bool ValidateParameters(); 66 bool ValidateParameters();
64 67
65 // Parameters to control the heuristic. 68 // Parameters to control the heuristic.
69 // TODO(bashi): Rename these parameters.
66 70
67 // The median size of a renderer on the current platform. This is used to 71 // The median size of a renderer on the current platform. This is used to
68 // convert the amount of free memory to an expected number of new renderers 72 // convert the amount of free memory to an expected number of new renderers
69 // that could be started before hitting critical memory pressure. 73 // that could be started before hitting critical memory pressure.
70 int expected_renderer_size_; 74 int expected_renderer_size_;
71 // When in a NORMAL state and the potential number of new renderers drops 75 // When in a NORMAL state and the potential number of new renderers drops
72 // below this level, the coordinator will transition to a THROTTLED state. 76 // below this level, the coordinator will transition to a THROTTLED state.
73 int new_renderers_until_throttled_; 77 int new_renderers_until_throttled_;
74 // When in a NORMAL/THROTTLED state and the potential number of new renderers 78 // When in a NORMAL/THROTTLED state and the potential number of new renderers
75 // drops below this level, the coordinator will transition to a SUSPENDED 79 // drops below this level, the coordinator will transition to a SUSPENDED
(...skipping 12 matching lines...) Expand all
88 base::TimeDelta minimum_transition_period_; 92 base::TimeDelta minimum_transition_period_;
89 // The interval of checking the amount of free memory. 93 // The interval of checking the amount of free memory.
90 base::TimeDelta monitoring_interval_; 94 base::TimeDelta monitoring_interval_;
91 95
92 DISALLOW_COPY_AND_ASSIGN(MemoryStateUpdater); 96 DISALLOW_COPY_AND_ASSIGN(MemoryStateUpdater);
93 }; 97 };
94 98
95 } // namespace content 99 } // namespace content
96 100
97 #endif // CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_ 101 #endif // CONTENT_BROWSER_MEMORY_MEMORY_STATE_UPDATER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698