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..30f80a816bfea9bf8ba8ea9ba2110b67ac7c9c96 100644 |
--- a/athena/resource_manager/delegate/resource_manager_delegate.cc |
+++ b/athena/resource_manager/delegate/resource_manager_delegate.cc |
@@ -4,6 +4,7 @@ |
#include "athena/resource_manager/public/resource_manager_delegate.h" |
+#include <algorithm> |
#include <string> |
#include "base/logging.h" |
@@ -25,11 +26,35 @@ 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) && info.total > 0 && info.free >= 0) { |
Luigi Semenzato
2014/08/29 15:37:36
Not sure that you should check info.total and info
Mr4D (OOO till 08-26)
2014/08/29 16:45:47
Done.
|
+ // TODO(skuhne): Instead of adding the kernel memory pressure calculation |
Luigi Semenzato
2014/08/29 15:37:36
Do you want to open a bug to keep track of this?
Mr4D (OOO till 08-26)
2014/08/29 16:45:47
Done.
|
+ // logic here, we should have a kernel mechanism similar to the low memory |
+ // notifier in ChromeOS which offers multiple pressure states. |
+ |
+ // The available memory consists of "real" and virtual (z)ram memory. |
+ // Since swapp-able memory uses a non pre-deterministic compression and |
Luigi Semenzato
2014/08/29 15:37:36
"swappable" may be better
Mr4D (OOO till 08-26)
2014/08/29 16:45:46
Done.
|
+ // the compression creates it's own "dynamic" in the system, it gets |
Luigi Semenzato
2014/08/29 15:37:36
its
Mr4D (OOO till 08-26)
2014/08/29 16:45:46
Done.
|
+ // 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; |
+ |
+ // We don't know this value - it's kernel internal. |
Luigi Semenzato
2014/08/29 15:37:36
Just use 50Mb. You're already copying kernel inte
Mr4D (OOO till 08-26)
2014/08/29 16:45:46
Done.
|
+ int min_file_memory = 0; |
+ |
+ // 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; |
+ |
+ // Available memory is the sum of free, swap and easy reclaimable memory. |
+ int available_memory = |
+ info.free + info.swap_free / kSwapWeight + file_memory; |
+ |
+ int percentage = ((total_memory - available_memory) * 100) / total_memory; |
+ return std::min(0, std::max(percentage, 100)); |
Luigi Semenzato
2014/08/29 15:37:36
available memory can be assumed to be positive, so
Mr4D (OOO till 08-26)
2014/08/29 16:45:47
Done. I might be wrong, but what if the compressio
Luigi Semenzato
2014/08/29 18:42:56
Ah, good question. This may be a concern in gener
|
} |
LOG(WARNING) << "Cannot determine the free memory of the system."; |
return 0; |