Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: android: lowmemorykiller: Only iterate over process list when needed.

Use NR_ACTIVE plus NR_INACTIVE as a size estimate for our fake cache
instead the sum of rss. Neither method is accurate.

Also skip the process scan, if the amount of memory available is above
the largest threshold set.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
Cc: David Rientjes <rientjes@google.com>
Cc: San Mehat <san@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


authored by

Arve Hjønnevåg and committed by
Greg Kroah-Hartman
f501d001 4900dea6

+21 -14
+21 -14
drivers/staging/android/lowmemorykiller.c
··· 71 71 } 72 72 if(nr_to_scan > 0) 73 73 lowmem_print(3, "lowmem_shrink %d, %x, ofree %d, ma %d\n", nr_to_scan, gfp_mask, other_free, min_adj); 74 + rem = global_page_state(NR_ACTIVE) + global_page_state(NR_INACTIVE); 75 + if (nr_to_scan <= 0 || min_adj == OOM_ADJUST_MAX + 1) { 76 + lowmem_print(5, "lowmem_shrink %d, %x, return %d\n", nr_to_scan, gfp_mask, rem); 77 + return rem; 78 + } 79 + 74 80 read_lock(&tasklist_lock); 75 81 for_each_process(p) { 76 - if(p->oomkilladj >= 0 && p->mm) { 77 - tasksize = get_mm_rss(p->mm); 78 - if(nr_to_scan > 0 && tasksize > 0 && p->oomkilladj >= min_adj) { 79 - if(selected == NULL || 80 - p->oomkilladj > selected->oomkilladj || 81 - (p->oomkilladj == selected->oomkilladj && 82 - tasksize > selected_tasksize)) { 83 - selected = p; 84 - selected_tasksize = tasksize; 85 - lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n", 86 - p->pid, p->comm, p->oomkilladj, tasksize); 87 - } 88 - } 89 - rem += tasksize; 82 + if (p->oomkilladj < min_adj || !p->mm) 83 + continue; 84 + tasksize = get_mm_rss(p->mm); 85 + if (tasksize <= 0) 86 + continue; 87 + if (selected) { 88 + if (p->oomkilladj < selected->oomkilladj) 89 + continue; 90 + if (p->oomkilladj == selected->oomkilladj && 91 + tasksize <= selected_tasksize) 92 + continue; 90 93 } 94 + selected = p; 95 + selected_tasksize = tasksize; 96 + lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n", 97 + p->pid, p->comm, p->oomkilladj, tasksize); 91 98 } 92 99 if(selected != NULL) { 93 100 lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",