simple_lmk: Pass a custom swap function to sort()

When sort() isn't provided with a custom swap function, it falls back
onto its generic implementation of just swapping one byte at a time,
which is quite slow. Since we know the type of the objects being sorted,
we can provide our own swap function which simply uses the swap() macro.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
fourteen
Sultan Alsawaf 4 years ago committed by Jenna
parent 308878a60e
commit e5c2a8ab88
  1. 13
      drivers/android/simple_lmk.c

@ -62,6 +62,14 @@ static int victim_cmp(const void *lhs_ptr, const void *rhs_ptr)
return rhs->size - lhs->size;
}
static void victim_swap(void *lhs_ptr, void *rhs_ptr, int size)
{
struct victim_info *lhs = (typeof(lhs))lhs_ptr;
struct victim_info *rhs = (typeof(rhs))rhs_ptr;
swap(*lhs, *rhs);
}
static bool vtsk_is_duplicate(int vlen, struct task_struct *vtsk)
{
int i;
@ -137,7 +145,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_cmp, NULL);
sizeof(*victims), victim_cmp, victim_swap);
return pages_found;
}
@ -198,7 +206,8 @@ static void scan_and_kill(void)
* 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);
sort(victims, nr_to_kill, sizeof(*victims), victim_cmp,
victim_swap);
/* Second round of processing to finally select the victims */
nr_to_kill = process_victims(nr_to_kill);

Loading…
Cancel
Save