Advertisement
arter97

Untitled

Mar 10th, 2020
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.45 KB | None | 0 0
  1. From 4e1e953202d45ed5eb024fae9c6e0ce7509b25f0 Mon Sep 17 00:00:00 2001
  2. From: Park Ju Hyung <qkrwngud825@gmail.com>
  3. Date: Mon, 9 Mar 2020 03:22:53 +0900
  4. Subject: [PATCH] simple_lmk: count kills and export to sysfs
  5.  
  6. Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
  7. ---
  8. drivers/android/simple_lmk.c | 22 ++++++++++++++++------
  9.  1 file changed, 16 insertions(+), 6 deletions(-)
  10.  
  11. diff --git a/drivers/android/simple_lmk.c b/drivers/android/simple_lmk.c
  12. index f502eb5da8d78..1ee8817f69946 100644
  13. --- a/drivers/android/simple_lmk.c
  14. +++ b/drivers/android/simple_lmk.c
  15. @@ -13,6 +13,10 @@
  16.  #include <linux/vmpressure.h>
  17.  #include <uapi/linux/sched/types.h>
  18.  
  19. +/* Needed to prevent Android from thinking there's no LMK and thus rebooting */
  20. +#undef MODULE_PARAM_PREFIX
  21. +#define MODULE_PARAM_PREFIX "lowmemorykiller."
  22. +
  23.  /* The minimum number of pages to free per reclaim */
  24.  #define MIN_FREE_PAGES (CONFIG_ANDROID_SIMPLE_LMK_MINFREE * SZ_1M / PAGE_SIZE)
  25.  
  26. @@ -26,6 +30,7 @@ struct victim_info {
  27.     struct task_struct *tsk;
  28.     struct mm_struct *mm;
  29.     unsigned long size;
  30. +   int adj_index;
  31.  };
  32.  
  33.  /* Pulled from the Android framework. Lower adj means higher priority. */
  34. @@ -54,6 +59,9 @@ static int victims_to_kill;
  35.  static atomic_t needs_reclaim = ATOMIC_INIT(0);
  36.  static atomic_t nr_killed = ATOMIC_INIT(0);
  37.  
  38. +static int lmk_count[ARRAY_SIZE(adjs)];
  39. +module_param_array(lmk_count, int, NULL, S_IRUGO);
  40. +
  41.  static int victim_size_cmp(const void *lhs_ptr, const void *rhs_ptr)
  42.  {
  43.     const struct victim_info *lhs = (typeof(lhs))lhs_ptr;
  44. @@ -85,12 +93,13 @@ static unsigned long get_total_mm_pages(struct mm_struct *mm)
  45.     return pages;
  46.  }
  47.  
  48. -static unsigned long find_victims(int *vindex, short target_adj_min,
  49. -                 short target_adj_max)
  50. +static unsigned long find_victims(int *vindex, int adj_index)
  51.  {
  52.     unsigned long pages_found = 0;
  53.     int old_vindex = *vindex;
  54.     struct task_struct *tsk;
  55. +   short target_adj_min = adjs[adj_index];
  56. +   short target_adj_max = adjs[adj_index - 1];
  57.  
  58.     for_each_process(tsk) {
  59.         struct signal_struct *sig;
  60. @@ -122,6 +131,7 @@ static unsigned long find_victims(int *vindex, short target_adj_min,
  61.         victims[*vindex].tsk = vtsk;
  62.         victims[*vindex].mm = vtsk->mm;
  63.         victims[*vindex].size = get_total_mm_pages(vtsk->mm);
  64. +       victims[*vindex].adj_index = adj_index;
  65.  
  66.         /* Keep track of the number of pages that have been found */
  67.         pages_found += victims[*vindex].size;
  68. @@ -179,7 +189,7 @@ static void scan_and_kill(unsigned long pages_needed)
  69.      */
  70.     read_lock(&tasklist_lock);
  71.     for (i = 1; i < ARRAY_SIZE(adjs); i++) {
  72. -       pages_found += find_victims(&nr_victims, adjs[i], adjs[i - 1]);
  73. +       pages_found += find_victims(&nr_victims, i);
  74.         if (pages_found >= pages_needed || nr_victims == MAX_VICTIMS)
  75.             break;
  76.     }
  77. @@ -219,6 +229,9 @@ static void scan_and_kill(unsigned long pages_needed)
  78.             vtsk->signal->oom_score_adj,
  79.             victim->size << (PAGE_SHIFT - 10));
  80.  
  81. +       /* Count kills */
  82. +       lmk_count[ARRAY_SIZE(adjs) - victim->adj_index - 1]++;
  83. +
  84.         /* Accelerate the victim's death by forcing the kill signal */
  85.         do_send_sig_info(SIGKILL, SEND_SIG_FORCED, vtsk, true);
  86.  
  87. @@ -320,7 +333,4 @@ static const struct kernel_param_ops simple_lmk_init_ops = {
  88.     .set = simple_lmk_init_set
  89.  };
  90.  
  91. -/* Needed to prevent Android from thinking there's no LMK and thus rebooting */
  92. -#undef MODULE_PARAM_PREFIX
  93. -#define MODULE_PARAM_PREFIX "lowmemorykiller."
  94.  module_param_cb(minfree, &simple_lmk_init_ops, NULL, 0200);
  95. --
  96. 2.25.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement