diff options
author | Suren Baghdasaryan | 2017-12-08 15:17:06 -0600 |
---|---|---|
committer | Suren Baghdasaryan | 2018-03-01 19:09:12 -0600 |
commit | b93764db9c52b49edfc10962884e98bf6450d5cb (patch) | |
tree | 9026e7e790a13c31e1fd81d0151fb4a4b1105bd0 | |
parent | e5c9643119ca32ce0175a1119b410f393f74dfa7 (diff) | |
download | platform-system-core-b93764db9c52b49edfc10962884e98bf6450d5cb.tar.gz platform-system-core-b93764db9c52b49edfc10962884e98bf6450d5cb.tar.xz platform-system-core-b93764db9c52b49edfc10962884e98bf6450d5cb.zip |
lmkd: add logic to kill the heaviest of the eligible processes
(cherry pick from commit 662492ab1d21f138483a8f3943483924e8779d29)
Killing the most memory-demanding process from the set of eligible
processes yields better results on high-performance devices than
killing the first one we could find. This is in line with how in-kernel
lowmemorykiller driver chooses its victims.
Bug: 63631020
Test: alloc-stress
Change-Id: Ie1ef7f33f3e79698a9b4120c14490386d6129f9b
Merged-In: Ie1ef7f33f3e79698a9b4120c14490386d6129f9b
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
-rw-r--r-- | lmkd/lmkd.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c index d438203a7..17ebb1497 100644 --- a/lmkd/lmkd.c +++ b/lmkd/lmkd.c | |||
@@ -91,6 +91,7 @@ static bool enable_pressure_upgrade; | |||
91 | static int64_t upgrade_pressure; | 91 | static int64_t upgrade_pressure; |
92 | static int64_t downgrade_pressure; | 92 | static int64_t downgrade_pressure; |
93 | static bool is_go_device; | 93 | static bool is_go_device; |
94 | static bool kill_heaviest_task; | ||
94 | 95 | ||
95 | /* control socket listen and data */ | 96 | /* control socket listen and data */ |
96 | static int ctrl_lfd; | 97 | static int ctrl_lfd; |
@@ -593,6 +594,29 @@ static struct proc *proc_adj_lru(int oomadj) { | |||
593 | return (struct proc *)adjslot_tail(&procadjslot_list[ADJTOSLOT(oomadj)]); | 594 | return (struct proc *)adjslot_tail(&procadjslot_list[ADJTOSLOT(oomadj)]); |
594 | } | 595 | } |
595 | 596 | ||
597 | static struct proc *proc_get_heaviest(int oomadj) { | ||
598 | struct adjslot_list *head = &procadjslot_list[ADJTOSLOT(oomadj)]; | ||
599 | struct adjslot_list *curr = head->next; | ||
600 | struct proc *maxprocp = NULL; | ||
601 | int maxsize = 0; | ||
602 | while (curr != head) { | ||
603 | int pid = ((struct proc *)curr)->pid; | ||
604 | int tasksize = proc_get_size(pid); | ||
605 | if (tasksize <= 0) { | ||
606 | struct adjslot_list *next = curr->next; | ||
607 | pid_remove(pid); | ||
608 | curr = next; | ||
609 | } else { | ||
610 | if (tasksize > maxsize) { | ||
611 | maxsize = tasksize; | ||
612 | maxprocp = (struct proc *)curr; | ||
613 | } | ||
614 | curr = curr->next; | ||
615 | } | ||
616 | } | ||
617 | return maxprocp; | ||
618 | } | ||
619 | |||
596 | /* Kill one process specified by procp. Returns the size of the process killed */ | 620 | /* Kill one process specified by procp. Returns the size of the process killed */ |
597 | static int kill_one_process(struct proc* procp, int min_score_adj, | 621 | static int kill_one_process(struct proc* procp, int min_score_adj, |
598 | enum vmpressure_level level) { | 622 | enum vmpressure_level level) { |
@@ -643,7 +667,10 @@ static int find_and_kill_process(enum vmpressure_level level) { | |||
643 | struct proc *procp; | 667 | struct proc *procp; |
644 | 668 | ||
645 | retry: | 669 | retry: |
646 | procp = proc_adj_lru(i); | 670 | if (kill_heaviest_task) |
671 | procp = proc_get_heaviest(i); | ||
672 | else | ||
673 | procp = proc_adj_lru(i); | ||
647 | 674 | ||
648 | if (procp) { | 675 | if (procp) { |
649 | killed_size = kill_one_process(procp, min_score_adj, level); | 676 | killed_size = kill_one_process(procp, min_score_adj, level); |
@@ -929,6 +956,8 @@ int main(int argc __unused, char **argv __unused) { | |||
929 | (int64_t)property_get_int32("ro.lmk.upgrade_pressure", 100); | 956 | (int64_t)property_get_int32("ro.lmk.upgrade_pressure", 100); |
930 | downgrade_pressure = | 957 | downgrade_pressure = |
931 | (int64_t)property_get_int32("ro.lmk.downgrade_pressure", 100); | 958 | (int64_t)property_get_int32("ro.lmk.downgrade_pressure", 100); |
959 | kill_heaviest_task = | ||
960 | property_get_bool("ro.lmk.kill_heaviest_task", true); | ||
932 | is_go_device = property_get_bool("ro.config.low_ram", false); | 961 | is_go_device = property_get_bool("ro.config.low_ram", false); |
933 | 962 | ||
934 | // MCL_ONFAULT pins pages as they fault instead of loading | 963 | // MCL_ONFAULT pins pages as they fault instead of loading |