Commit a2181336 authored by bashi's avatar bashi Committed by Commit bot

Update MemoryMonitorChromeOS

Current guidelines for defining critical memory state is swapping will
occur in that situation. Update MemoryMonitorChromeOS to align the
guidelines.

- Use |available| field of base::SystemMemoryInfoKB if the OS supports it
- Don't count SwapFree as free available memory

BUG=696844

Review-Url: https://codereview.chromium.org/2731273003
Cr-Commit-Position: refs/heads/master@{#455970}
parent 9c002f2d
......@@ -25,11 +25,9 @@ int MemoryMonitorChromeOS::GetFreeMemoryUntilCriticalMB() {
base::SystemMemoryInfoKB mem_info = {};
delegate_->GetSystemMemoryInfo(&mem_info);
// 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;
// Use available free memory provided by the OS if the OS supports it.
if (mem_info.available > 0)
return mem_info.available >> kShiftKiBtoMiB;
// The kernel internally uses 50MB.
const int kMinFileMemory = 50 * 1024;
......@@ -39,9 +37,8 @@ int MemoryMonitorChromeOS::GetFreeMemoryUntilCriticalMB() {
// unless it is dirty or it's a minimal portion which is required.
file_memory -= mem_info.dirty + kMinFileMemory;
// Available memory is the sum of free, swap and easy reclaimable memory.
return (mem_info.free + mem_info.swap_free / kSwapWeight + file_memory) >>
kShiftKiBtoMiB;
// Available memory is the sum of free and easy reclaimable memory.
return (mem_info.free + file_memory) >> kShiftKiBtoMiB;
}
// static
......
......@@ -20,12 +20,14 @@ class TestMemoryMonitorChromeOSDelegate : public TestMemoryMonitorDelegate {
int swap_kb,
int active_kb,
int inactive_kb,
int dirty_kb) {
int dirty_kb,
int available_kb) {
mem_info_.free = free_kb;
mem_info_.swap_free = swap_kb;
mem_info_.active_file = active_kb;
mem_info_.inactive_file = inactive_kb;
mem_info_.dirty = dirty_kb;
mem_info_.available = available_kb;
}
private:
......@@ -56,10 +58,17 @@ TEST_F(MemoryMonitorChromeOSTest, GetFreeMemoryUntilCriticalMB) {
monitor_.reset(new MemoryMonitorChromeOS(&delegate_));
EXPECT_EQ(0u, delegate_.calls());
delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB,
32 * kKBperMB, 16 * kKBperMB);
EXPECT_EQ(318, monitor_->GetFreeMemoryUntilCriticalMB());
// |available| is supported.
delegate_.SetFreeMemoryKB(1 * kKBperMB, 1 * kKBperMB, 1 * kKBperMB,
1 * kKBperMB, 1 * kKBperMB, 286 * kKBperMB);
EXPECT_EQ(286, monitor_->GetFreeMemoryUntilCriticalMB());
EXPECT_EQ(1U, delegate_.calls());
// |available| is not supported.
delegate_.SetFreeMemoryKB(256 * kKBperMB, 128 * kKBperMB, 64 * kKBperMB,
32 * kKBperMB, 16 * kKBperMB, 0 * kKBperMB);
EXPECT_EQ(286, monitor_->GetFreeMemoryUntilCriticalMB());
EXPECT_EQ(2U, delegate_.calls());
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment