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..f0ea87646a0ab4db96b107e7387f793b2f01af40 100644 |
--- a/athena/resource_manager/delegate/resource_manager_delegate.cc |
+++ b/athena/resource_manager/delegate/resource_manager_delegate.cc |
@@ -25,11 +25,37 @@ 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)) { |
Jun Mukai
2014/08/29 22:59:32
Early exit like if(!base::GetSystemMemoryInfo(&inf
Mr4D (OOO till 08-26)
2014/08/29 23:44:03
Done.
|
+ // 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. |
+ int min_file_memory = 50 * 1024; |
Jun Mukai
2014/08/29 22:59:32
const int kMinFileMemory = ...
Mr4D (OOO till 08-26)
2014/08/29 23:44:03
Done.
|
+ |
+ // 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 - min_file_memory; |
Jun Mukai
2014/08/29 22:59:33
If dirty is less than 50MB, it will increase file_
Mr4D (OOO till 08-26)
2014/08/29 23:44:03
sign got now corrected.
|
+ |
+ // Available memory is the sum of free, swap and easy reclaimable memory. |
+ int available_memory = |
+ info.free + info.swap_free / kSwapWeight + file_memory; |
Jun Mukai
2014/08/29 22:59:33
or this could be std::min(file_memory, min_file_me
Mr4D (OOO till 08-26)
2014/08/29 23:44:03
According to our semenzato that isn't a problem. (
|
+ |
+ DCHECK(available_memory < total_memory); |
+ int percentage = ((total_memory - available_memory) * 100) / total_memory; |
+ return percentage; |
} |
LOG(WARNING) << "Cannot determine the free memory of the system."; |
return 0; |