Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 4e1e953202d45ed5eb024fae9c6e0ce7509b25f0 Mon Sep 17 00:00:00 2001
- From: Park Ju Hyung <qkrwngud825@gmail.com>
- Date: Mon, 9 Mar 2020 03:22:53 +0900
- Subject: [PATCH] simple_lmk: count kills and export to sysfs
- Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
- ---
- drivers/android/simple_lmk.c | 22 ++++++++++++++++------
- 1 file changed, 16 insertions(+), 6 deletions(-)
- diff --git a/drivers/android/simple_lmk.c b/drivers/android/simple_lmk.c
- index f502eb5da8d78..1ee8817f69946 100644
- --- a/drivers/android/simple_lmk.c
- +++ b/drivers/android/simple_lmk.c
- @@ -13,6 +13,10 @@
- #include <linux/vmpressure.h>
- #include <uapi/linux/sched/types.h>
- +/* Needed to prevent Android from thinking there's no LMK and thus rebooting */
- +#undef MODULE_PARAM_PREFIX
- +#define MODULE_PARAM_PREFIX "lowmemorykiller."
- +
- /* The minimum number of pages to free per reclaim */
- #define MIN_FREE_PAGES (CONFIG_ANDROID_SIMPLE_LMK_MINFREE * SZ_1M / PAGE_SIZE)
- @@ -26,6 +30,7 @@ struct victim_info {
- struct task_struct *tsk;
- struct mm_struct *mm;
- unsigned long size;
- + int adj_index;
- };
- /* Pulled from the Android framework. Lower adj means higher priority. */
- @@ -54,6 +59,9 @@ static int victims_to_kill;
- static atomic_t needs_reclaim = ATOMIC_INIT(0);
- static atomic_t nr_killed = ATOMIC_INIT(0);
- +static int lmk_count[ARRAY_SIZE(adjs)];
- +module_param_array(lmk_count, int, NULL, S_IRUGO);
- +
- static int victim_size_cmp(const void *lhs_ptr, const void *rhs_ptr)
- {
- const struct victim_info *lhs = (typeof(lhs))lhs_ptr;
- @@ -85,12 +93,13 @@ static unsigned long get_total_mm_pages(struct mm_struct *mm)
- return pages;
- }
- -static unsigned long find_victims(int *vindex, short target_adj_min,
- - short target_adj_max)
- +static unsigned long find_victims(int *vindex, int adj_index)
- {
- unsigned long pages_found = 0;
- int old_vindex = *vindex;
- struct task_struct *tsk;
- + short target_adj_min = adjs[adj_index];
- + short target_adj_max = adjs[adj_index - 1];
- for_each_process(tsk) {
- struct signal_struct *sig;
- @@ -122,6 +131,7 @@ static unsigned long find_victims(int *vindex, short target_adj_min,
- victims[*vindex].tsk = vtsk;
- victims[*vindex].mm = vtsk->mm;
- victims[*vindex].size = get_total_mm_pages(vtsk->mm);
- + victims[*vindex].adj_index = adj_index;
- /* Keep track of the number of pages that have been found */
- pages_found += victims[*vindex].size;
- @@ -179,7 +189,7 @@ static void scan_and_kill(unsigned long pages_needed)
- */
- read_lock(&tasklist_lock);
- for (i = 1; i < ARRAY_SIZE(adjs); i++) {
- - pages_found += find_victims(&nr_victims, adjs[i], adjs[i - 1]);
- + pages_found += find_victims(&nr_victims, i);
- if (pages_found >= pages_needed || nr_victims == MAX_VICTIMS)
- break;
- }
- @@ -219,6 +229,9 @@ static void scan_and_kill(unsigned long pages_needed)
- vtsk->signal->oom_score_adj,
- victim->size << (PAGE_SHIFT - 10));
- + /* Count kills */
- + lmk_count[ARRAY_SIZE(adjs) - victim->adj_index - 1]++;
- +
- /* Accelerate the victim's death by forcing the kill signal */
- do_send_sig_info(SIGKILL, SEND_SIG_FORCED, vtsk, true);
- @@ -320,7 +333,4 @@ static const struct kernel_param_ops simple_lmk_init_ops = {
- .set = simple_lmk_init_set
- };
- -/* Needed to prevent Android from thinking there's no LMK and thus rebooting */
- -#undef MODULE_PARAM_PREFIX
- -#define MODULE_PARAM_PREFIX "lowmemorykiller."
- module_param_cb(minfree, &simple_lmk_init_ops, NULL, 0200);
- --
- 2.25.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement