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

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

Issue 2332423002: Added memory-monitor for ChromeOS. (Closed)
Patch Set: fixed name of ChromeOS Created 4 years, 3 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 (c) 2016 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 "content/browser/memory/memory_monitor_chromeos.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/process/process_metrics.h"
9
10 namespace content {
11
12 namespace {
13
14 // The number of bits to shift to convert KiB to MiB.
15 const int kShiftKiBtoMiB = 10;
16
17 } // namespace
18
19 MemoryMonitorChromeOS::MemoryMonitorChromeOS(MemoryMonitorDelegate* delegate)
20 : delegate_(delegate) {}
21
22 MemoryMonitorChromeOS::~MemoryMonitorChromeOS() {}
23
24 int MemoryMonitorChromeOS::GetFreeMemoryUntilCriticalMB() {
25 base::SystemMemoryInfoKB mem_info = {};
26 delegate_->GetSystemMemoryInfo(&mem_info);
27
28 // The available memory consists of "real" and virtual (z)ram memory.
29 // Since swappable memory uses a non pre-deterministic compression and
30 // the compression creates its own "dynamic" in the system, it gets
31 // de-emphasized by the |kSwapWeight| factor.
32 const int kSwapWeight = 4;
33
34 // The kernel internally uses 50MB.
35 const int kMinFileMemory = 50 * 1024;
36
37 // Most file memory can be easily reclaimed.
38 int file_memory = mem_info.active_file + mem_info.inactive_file;
39 // unless it is dirty or it's a minimal portion which is required.
40 file_memory -= mem_info.dirty + kMinFileMemory;
41
42 // Available memory is the sum of free, swap and easy reclaimable memory.
43 return (mem_info.free + mem_info.swap_free / kSwapWeight + file_memory) >>
44 kShiftKiBtoMiB;
45 }
46
47 // static
48 std::unique_ptr<MemoryMonitorChromeOS> MemoryMonitorChromeOS::Create(
49 MemoryMonitorDelegate* delegate) {
50 return base::MakeUnique<MemoryMonitorChromeOS>(delegate);
51 }
52
53 // Implementation of factory function defined in memory_monitor.h.
54 std::unique_ptr<MemoryMonitor> CreateMemoryMonitor() {
55 return MemoryMonitorChromeOS::Create(MemoryMonitorDelegate::GetInstance());
56 }
57
58 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_monitor_chromeos.h ('k') | content/browser/memory/memory_monitor_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698