From 95e3b2c00f82ee88f019dc504fa77baea0456614 Mon Sep 17 00:00:00 2001 From: lk_hauwei Date: Thu, 23 Jun 2022 20:31:48 +0800 Subject: [PATCH] mm: optimize lowmem_debug code ohos inclusion category: bugfix issue: #I5DUM4 CVE: NA -------------------------------- Reduce surplus code ,optimize code logic Signed-off-by: lk_hauwei --- mm/lmkd_dbg_trigger.c | 19 +++++++------------ mm/lowmem_dbg.c | 36 +++++------------------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/mm/lmkd_dbg_trigger.c b/mm/lmkd_dbg_trigger.c index e845b14f5f02..c0b7a758c6b2 100644 --- a/mm/lmkd_dbg_trigger.c +++ b/mm/lmkd_dbg_trigger.c @@ -5,16 +5,14 @@ * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd. */ #include -#include #include -#include -#include #include #include #include -#include #include -#define PROC_NUMBUF 8 + +#define PROC_NUMBUF 3 +#define STATE_BIT 1 static int lmkd_oom_score_adj; static atomic64_t lmkd_no_cma_cnt = ATOMIC64_INIT(0); @@ -61,14 +59,11 @@ static ssize_t lmkd_dbg_trigger_write(struct file *file, const char __user *buf, if (err) goto out; - if (oom_score_adj < OOM_SCORE_ADJ_MIN || - oom_score_adj > OOM_SCORE_ADJ_MAX) { + if (!(oom_score_adj >> STATE_BIT)) { + lmkd_oom_score_adj = oom_score_adj; + lowmem_dbg(oom_score_adj); + } else err = -EINVAL; - goto out; - } - - lmkd_oom_score_adj = oom_score_adj; - lowmem_dbg(oom_score_adj); out: return err < 0 ? err : count; diff --git a/mm/lowmem_dbg.c b/mm/lowmem_dbg.c index fc548ce78fd2..f515d729efb8 100644 --- a/mm/lowmem_dbg.c +++ b/mm/lowmem_dbg.c @@ -6,30 +6,17 @@ */ #define pr_fmt(fmt) "lowmem:" fmt -#include -#include #include #include -#include #include -#include #include -#include -#include -#include #include #include #include -#include -#include -#include #include -#define LMK_PRT_TSK_RSS 10000 #define LMK_INTERVAL 3 -/* SERVICE_ADJ(5) * OOM_SCORE_ADJ_MAX / -OOM_DISABLE */ -#define LMK_SERVICE_ADJ 500 /* defiine TASK STATE String */ #define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn" @@ -38,7 +25,6 @@ static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; static void lowmem_dump(struct work_struct *work); static DEFINE_MUTEX(lowmem_dump_mutex); -static DECLARE_WORK(lowmem_dbg_wk, lowmem_dump); static DECLARE_WORK(lowmem_dbg_verbose_wk, lowmem_dump); static int task_state_char(unsigned long state) @@ -48,7 +34,7 @@ static int task_state_char(unsigned long state) return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; } -static void tasks_dump(bool verbose) +static void tasks_dump(void) { struct task_struct *p = NULL; struct task_struct *task = NULL; @@ -56,7 +42,8 @@ static void tasks_dump(bool verbose) unsigned long tsk_nr_ptes = 0; char frozen_mark = ' '; - pr_info("[ pid ] uid tgid total_vm rss nptes swap adj s name\n"); + pr_info("[%5s] %5s %5s %8s %6s %5s %5s %5s %s %s\n", + "pid", "uid", "tgid", "total_vm", "rss", "nptes", "swap", "adj", "s", "name"); rcu_read_lock(); for_each_process(p) { @@ -71,12 +58,6 @@ static void tasks_dump(bool verbose) } tsk_oom_adj = task->signal->oom_score_adj; - if (!verbose && tsk_oom_adj && - (tsk_oom_adj <= LMK_SERVICE_ADJ) && - (get_mm_rss(task->mm) < LMK_PRT_TSK_RSS)) { - task_unlock(task); - continue; - } tsk_nr_ptes = mm_pgtables_bytes(task->mm); @@ -98,16 +79,9 @@ static void tasks_dump(bool verbose) static void lowmem_dump(struct work_struct *work) { - bool verbose = (work == &lowmem_dbg_verbose_wk) ? true : false; - mutex_lock(&lowmem_dump_mutex); -#if defined(SHOW_MEM_FILTER_PAGE_COUNT) - show_mem(SHOW_MEM_FILTER_NODES | - (verbose ? 0 : SHOW_MEM_FILTER_PAGE_COUNT)); -#else show_mem(SHOW_MEM_FILTER_NODES, NULL); -#endif - tasks_dump(verbose); + tasks_dump(); mutex_unlock(&lowmem_dump_mutex); } @@ -119,7 +93,7 @@ void lowmem_dbg(short oom_score_adj) schedule_work(&lowmem_dbg_verbose_wk); } else if (time_after64(jiffs, (last_jiffs + LMK_INTERVAL * HZ))) { last_jiffs = get_jiffies_64(); - schedule_work(&lowmem_dbg_wk); + schedule_work(&lowmem_dbg_verbose_wk); } } -- Gitee