Skip to content

Commit

Permalink
simple_lmk: Skip victim reduction when all victims need to be killed
Browse files Browse the repository at this point in the history
When there aren't enough pages found, it means all of the victims that
were found need to be killed. The additional processing that attempts to
reduce the number of victims can be skipped in this case.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Khusika Dhamar Gusti <mail@khusika.com>
  • Loading branch information
kerneltoast authored and Khusika Dhamar Gusti committed May 27, 2021
1 parent 33a7879 commit affe9f0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions drivers/android/simple_lmk.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int nr_victims;
static atomic_t needs_reclaim = ATOMIC_INIT(0);
static atomic_t nr_killed = ATOMIC_INIT(0);

static int victim_size_cmp(const void *lhs_ptr, const void *rhs_ptr)
static int victim_cmp(const void *lhs_ptr, const void *rhs_ptr)
{
const struct victim_info *lhs = (typeof(lhs))lhs_ptr;
const struct victim_info *rhs = (typeof(rhs))rhs_ptr;
Expand Down Expand Up @@ -136,7 +136,7 @@ static unsigned long find_victims(int *vindex, unsigned short target_adj_min,
*/
if (pages_found)
sort(&victims[old_vindex], *vindex - old_vindex,
sizeof(*victims), victim_size_cmp, NULL);
sizeof(*victims), victim_cmp, NULL);

return pages_found;
}
Expand Down Expand Up @@ -186,18 +186,25 @@ static void scan_and_kill(void)
return;
}

/* First round of victim processing to weed out unneeded victims */
nr_to_kill = process_victims(nr_found);
/* Minimize the number of victims if we found more pages than needed */
if (pages_found > MIN_FREE_PAGES) {
/* First round of processing to weed out unneeded victims */
nr_to_kill = process_victims(nr_found);

/*
* Try to kill as few of the chosen victims as possible by sorting the
* chosen victims by size, which means larger victims that have a lower
* adj can be killed in place of smaller victims with a high adj.
*/
sort(victims, nr_to_kill, sizeof(*victims), victim_size_cmp, NULL);
/*
* Try to kill as few of the chosen victims as possible by
* sorting the chosen victims by size, which means larger
* victims that have a lower adj can be killed in place of
* smaller victims with a high adj.
*/
sort(victims, nr_to_kill, sizeof(*victims), victim_cmp, NULL);

/* Second round of victim processing to finally select the victims */
nr_to_kill = process_victims(nr_to_kill);
/* Second round of processing to finally select the victims */
nr_to_kill = process_victims(nr_to_kill);
} else {
/* Too few pages found, so all the victims need to be killed */
nr_to_kill = nr_found;
}

/* Store the final number of victims for simple_lmk_mm_freed() */
write_lock(&mm_free_lock);
Expand Down

0 comments on commit affe9f0

Please sign in to comment.