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

Unified Diff: athena/resource_manager/delegate/resource_manager_delegate.cc

Issue 511383003: Adding proper GetUsedMemoryInPercent calculation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/resource_manager/delegate/resource_manager_delegate.cc
diff --git a/athena/resource_manager/delegate/resource_manager_delegate.cc b/athena/resource_manager/delegate/resource_manager_delegate.cc
index ca76c650907b1cf80d434601a9c31717bdf46479..e58aaacdefeb4278c03662fd406ba0138741d2d9 100644
--- a/athena/resource_manager/delegate/resource_manager_delegate.cc
+++ b/athena/resource_manager/delegate/resource_manager_delegate.cc
@@ -25,14 +25,40 @@ class ResourceManagerDelegateImpl : public ResourceManagerDelegate {
private:
virtual int GetUsedMemoryInPercent() OVERRIDE {
- base::SystemMemoryInfoKB memory;
- // TODO(skuhne): According to semenzato this calculation has to change.
- if (base::GetSystemMemoryInfo(&memory) &&
- memory.total > 0 && memory.free >= 0) {
- return ((memory.total - memory.free) * 100) / memory.total;
+ base::SystemMemoryInfoKB info;
+ if (!base::GetSystemMemoryInfo(&info)) {
+ LOG(WARNING) << "Cannot determine the free memory of the system.";
+ return 0;
}
- LOG(WARNING) << "Cannot determine the free memory of the system.";
- return 0;
+ // TODO(skuhne): Instead of adding the kernel memory pressure calculation
+ // logic here, we should have a kernel mechanism similar to the low memory
+ // notifier in ChromeOS which offers multiple pressure states.
+ // To track this, we have crbug.com/381196.
+
+ // The available memory consists of "real" and virtual (z)ram memory.
+ // Since swappable memory uses a non pre-deterministic compression and
+ // the compression creates its own "dynamic" in the system, it gets
+ // de-emphasized by the |kSwapWeight| factor.
+ const int kSwapWeight = 4;
+
+ // The total memory we have is the "real memory" plus the virtual (z)ram.
+ int total_memory = info.total + info.swap_total / kSwapWeight;
+
+ // The kernel internally uses 50MB.
+ const int kMinFileMemory = 50 * 1024;
+
+ // Most file memory can be easily reclaimed.
+ int file_memory = info.active_file + info.inactive_file;
+ // unless it is dirty or it's a minimal portion which is required.
+ file_memory -= info.dirty + kMinFileMemory;
+
+ // Available memory is the sum of free, swap and easy reclaimable memory.
+ int available_memory =
+ info.free + info.swap_free / kSwapWeight + file_memory;
+
+ DCHECK(available_memory < total_memory);
+ int percentage = ((total_memory - available_memory) * 100) / total_memory;
+ return percentage;
}
virtual int MemoryPressureIntervalInMS() OVERRIDE {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698