diff options
author | Robert Benea <robenea@google.com> | 2017-09-13 15:20:30 -0700 |
---|---|---|
committer | Robert Benea <robenea@google.com> | 2017-09-14 13:47:40 -0700 |
commit | 6e8e7106754b62f9770c1c3b69ff5a227796178e (patch) | |
tree | f6b9e62f4ba4708a91484424c57b61785d455458 /lmkd | |
parent | 164baebc0173500b4317529b7e942100c45c7191 (diff) | |
download | core-6e8e7106754b62f9770c1c3b69ff5a227796178e.tar.gz core-6e8e7106754b62f9770c1c3b69ff5a227796178e.tar.bz2 core-6e8e7106754b62f9770c1c3b69ff5a227796178e.zip |
Downgrade memory pressure events
If the system has enough memory the pressure events are ignored or
downgraded from critical to medium.
Bug: 65642829
Test: tested on gobo
Change-Id: I44e66d2e35508aceee5c1719313db217b80d582e
Diffstat (limited to 'lmkd')
-rw-r--r-- | lmkd/lmkd.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c index e26b2271a..525d7b3cf 100644 --- a/lmkd/lmkd.c +++ b/lmkd/lmkd.c @@ -82,6 +82,7 @@ static int critical_oomadj; static bool debug_process_killing; static bool enable_pressure_upgrade; static int64_t upgrade_pressure; +static int64_t downgrade_pressure; static bool is_go_device; /* control socket listen and data */ @@ -678,28 +679,47 @@ static void mp_event_common(bool is_critical) { int min_adj_score = is_critical ? critical_oomadj : medium_oomadj; int index = is_critical ? CRITICAL_INDEX : MEDIUM_INDEX; int64_t mem_usage, memsw_usage; + int64_t mem_pressure; ret = read(mpevfd[index], &evcount, sizeof(evcount)); if (ret < 0) ALOGE("Error reading memory pressure event fd; errno=%d", errno); - if (enable_pressure_upgrade && !is_critical) { - mem_usage = get_memory_usage(MEMCG_MEMORY_USAGE); - memsw_usage = get_memory_usage(MEMCG_MEMORYSW_USAGE); - if (memsw_usage < 0 || mem_usage < 0) { - find_and_kill_process(min_adj_score, is_critical); - return; - } + mem_usage = get_memory_usage(MEMCG_MEMORY_USAGE); + memsw_usage = get_memory_usage(MEMCG_MEMORYSW_USAGE); + if (memsw_usage < 0 || mem_usage < 0) { + find_and_kill_process(min_adj_score, is_critical); + return; + } - // We are swapping too much, calculate percent for swappinness. - if (((mem_usage * 100) / memsw_usage) < upgrade_pressure) { + // Calculate percent for swappinness. + mem_pressure = (mem_usage * 100) / memsw_usage; + + if (enable_pressure_upgrade && !is_critical) { + // We are swapping too much. + if (mem_pressure < upgrade_pressure) { ALOGI("Event upgraded to critical."); min_adj_score = critical_oomadj; is_critical = true; } } + // If the pressure is larger than downgrade_pressure lmk will not + // kill any process, since enough memory is available. + if (mem_pressure > downgrade_pressure) { + if (debug_process_killing) { + ALOGI("Ignore %s memory pressure", is_critical ? "critical" : "medium"); + } + return; + } else if (is_critical && mem_pressure > upgrade_pressure) { + if (debug_process_killing) { + ALOGI("Downgrade critical memory pressure"); + } + // Downgrade event to medium, since enough memory available. + is_critical = false; + } + if (find_and_kill_process(min_adj_score, is_critical) == 0) { if (debug_process_killing) { ALOGI("Nothing to kill"); @@ -878,6 +898,7 @@ int main(int argc __unused, char **argv __unused) { debug_process_killing = property_get_bool("ro.lmk.debug", false); enable_pressure_upgrade = property_get_bool("ro.lmk.critical_upgrade", false); upgrade_pressure = (int64_t)property_get_int32("ro.lmk.upgrade_pressure", 50); + downgrade_pressure = (int64_t)property_get_int32("ro.lmk.downgrade_pressure", 60); is_go_device = property_get_bool("ro.config.low_ram", false); mlockall(MCL_FUTURE); |