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

Side by Side Diff: content/browser/memory/memory_monitor_linux.cc

Issue 2448923004: memory coordinator: Use free memory to guess available memory on Linux (Closed)
Patch Set: fix test expectation Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/memory/memory_monitor_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "content/browser/memory/memory_monitor_linux.h" 5 #include "content/browser/memory/memory_monitor_linux.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/process/process_metrics.h" 8 #include "base/process/process_metrics.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 15 matching lines...) Expand all
26 delegate_->GetSystemMemoryInfo(&mem_info); 26 delegate_->GetSystemMemoryInfo(&mem_info);
27 27
28 // According to kernel commit 34e431b0ae398fc54ea69ff85ec700722c9da773, 28 // According to kernel commit 34e431b0ae398fc54ea69ff85ec700722c9da773,
29 // "available" is the "amount of memory that is available for a new workload 29 // "available" is the "amount of memory that is available for a new workload
30 // without pushing the system into swap"; return that value if it is valid. 30 // without pushing the system into swap"; return that value if it is valid.
31 // Old linux kernels (before 3.14) don't support "available" and show zero 31 // Old linux kernels (before 3.14) don't support "available" and show zero
32 // instead. 32 // instead.
33 if (mem_info.available > 0) 33 if (mem_info.available > 0)
34 return mem_info.available >> kShiftKiBtoMiB; 34 return mem_info.available >> kShiftKiBtoMiB;
35 35
36 // If there is no "available" value, guess at it based on free memory and 36 // If there is no "available" value, guess at it based on free memory.
37 // what the OS can easily discard. 37 // Though there will be easily discardable memory (buffers and caches), we
38 return (mem_info.free + mem_info.buffers + mem_info.cached) >> kShiftKiBtoMiB; 38 // don't count them because discarding them will affect the overall
39 // performance of the OS.
40 return mem_info.free >> kShiftKiBtoMiB;
39 } 41 }
40 42
41 // static 43 // static
42 std::unique_ptr<MemoryMonitorLinux> MemoryMonitorLinux::Create( 44 std::unique_ptr<MemoryMonitorLinux> MemoryMonitorLinux::Create(
43 MemoryMonitorDelegate* delegate) { 45 MemoryMonitorDelegate* delegate) {
44 return base::MakeUnique<MemoryMonitorLinux>(delegate); 46 return base::MakeUnique<MemoryMonitorLinux>(delegate);
45 } 47 }
46 48
47 // Implementation of factory function defined in memory_monitor.h. 49 // Implementation of factory function defined in memory_monitor.h.
48 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() { 50 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() {
49 return MemoryMonitorLinux::Create(MemoryMonitorDelegate::GetInstance()); 51 return MemoryMonitorLinux::Create(MemoryMonitorDelegate::GetInstance());
50 } 52 }
51 53
52 } // namespace content 54 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/memory/memory_monitor_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698