Fix a bug & remove useless logs 96/273096/1
authorUnsung Lee <unsung.lee@samsung.com>
Wed, 30 Mar 2022 11:30:49 +0000 (20:30 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 30 Mar 2022 11:33:34 +0000 (20:33 +0900)
fix an overflow bug
remove logs inserted for the test

Change-Id: I4e060ff0e4681ea6f7041eea02bd0c42e4414ffb
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/cgroup/cgroup.c
src/common/cgroup/memory-cgroup.c
src/common/cgroup/memory-cgroup.h
src/common/file-helper.c
src/common/module.c
src/resource-limiter/cpu/cpu-sched.c
src/resource-limiter/memory/lowmem-limit.c
src/resource-limiter/memory/vmpressure-lowmem-handler.c
src/resource-optimizer/memory/swap/swap.c
src/resourced/init.c

index 59a00d2..043075e 100644 (file)
@@ -277,7 +277,7 @@ int cgroup_write_node_uint32(const char *cgroup_name,
 {
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, value %d\n", buf, value);
+       _SD("cgroup_buf %s, value %u\n", buf, value);
        return fwrite_uint(buf, value);
 }
 
index c15bb2b..d71e4ca 100644 (file)
@@ -188,6 +188,9 @@ static void set_limit_in_bytes(const char *dir, unsigned int limit)
                return;
        }
 
+       if (limit == prev)
+               return;
+
        if (prev > limit) {
                cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, limit);
                cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, limit);
@@ -225,19 +228,31 @@ int check_oom_and_set_limit(const char *dir, unsigned int limit)
        return RESOURCED_ERROR_NONE;
 }
 
-static int memcg_write_params_info(struct memcg_info *mi)
+static int memcg_write_limiter_info(struct memcg_info *mi)
 {
        unsigned int limit = mi->limit;
        const char *name = mi->name;
        int ret = RESOURCED_ERROR_NONE;
-       int swappiness = -1;
-       _I("write memcg param for %s", name);
        /* enable cgroup move */
        ret = cgroup_write_node_uint32(name,
                        MEMCG_MOVE_CHARGE, 3);
        if (ret)
                return ret;
 
+       if (mi->limit_ratio == MEMCG_NO_LIMIT)
+               return ret;
+
+       /* write limit_in_bytes */
+       ret = check_oom_and_set_limit(name, limit);
+       return ret;
+}
+
+static int memcg_write_optimizer_info(struct memcg_info *mi)
+{
+       const char *name = mi->name;
+       int ret = RESOURCED_ERROR_NONE;
+       int swappiness = -1;
+
        /*
         * write swapness if it has a meaningful value.
         * if it has own swappiness value, set it to memcg at first.
@@ -252,26 +267,38 @@ static int memcg_write_params_info(struct memcg_info *mi)
                ret = cgroup_write_node_uint32(name,
                        MEMCG_SWAPPINESS, swappiness);
                if (ret)
-                       _I("failed to write %s %d to %s the",
+                       _I("[DEBUG] failed to write %s %d to %s the",
                                MEMCG_SWAPPINESS, swappiness, name);
        }
 
-       if (mi->limit_ratio == MEMCG_NO_LIMIT)
-               return ret;
-
-       /* write limit_in_bytes */
-       ret = check_oom_and_set_limit(name, limit);
-       _I("set %s's limit to %u", name, limit);
        return ret;
 }
 
-int memcg_write_params(void)
+int memcg_write_limiter_params(void)
+{
+       unsigned int i;
+       unsigned int lower_group_limit = 0;
+
+       for (i = CGROUP_LOW; i > CGROUP_ROOT; i--) {
+               struct memcg_info *mi = get_memcg_info(i);
+
+               if (mi->limit < lower_group_limit)
+                       mi->limit = lower_group_limit;
+
+               memcg_write_limiter_info(mi);
+               lower_group_limit = mi->limit;
+       }
+
+       return RESOURCED_ERROR_NONE;
+}
+
+int memcg_write_optimizer_params(void)
 {
        unsigned int i;
 
-       for (i = CGROUP_ROOT; i < CGROUP_END; i++) {
+       for (i = CGROUP_VIP; i < CGROUP_END; i++) {
                struct memcg_info *mi = get_memcg_info(i);
-               memcg_write_params_info(mi);
+               memcg_write_optimizer_info(mi);
        }
 
        return RESOURCED_ERROR_NONE;
@@ -304,7 +331,6 @@ void memcg_info_set_limit(struct memcg_info *mi, float ratio,
 
        mi->limit = (float)totalram * ratio;
        mi->limit_ratio = ratio;
-       _I("[DEBUG] ratio = %f, limit = %u, ram = %u", ratio, mi->limit, totalram);
        mi->threshold[MEM_LEVEL_CRITICAL] = (unsigned int)(mi->limit * MEMCG_LOW_RATIO);
        mi->threshold[MEM_LEVEL_OOM] = (unsigned int)(mi->limit * MEMCG_MEDIUM_RATIO);
        mi->threshold_leave = (float)mi->limit * MEMCG_FOREGROUND_LEAVE_RATIO;
index 6d6e628..0f3d5aa 100644 (file)
@@ -193,7 +193,8 @@ void free_memcg_conf(void);
 const char *cgroup_memory_stat_id_to_string(enum cgroup_memory_stat_id id);
 enum cgroup_memory_stat_id cgroup_memory_stat_string_to_id(const char *str);
 
-int memcg_write_params(void);
+int memcg_write_limiter_params(void);
+int memcg_write_optimizer_params(void);
 
 void memcg_set_threshold(int type, int level, int value);
 void memcg_set_leave_threshold(int type, int value);
index c1737a4..afd3f94 100644 (file)
@@ -71,7 +71,7 @@ int fwrite_uint(const char *path, const u_int32_t number)
        _cleanup_free_ char *digit_buf = NULL;
        int ret;
 
-       ret = asprintf(&digit_buf, "%d", number);
+       ret = asprintf(&digit_buf, "%u", number);
        ret_value_errno_msg_if(ret < 0, -ENOMEM,
                               "sprintf failed\n");
 
index 52d4759..e0cdaa3 100644 (file)
@@ -36,8 +36,6 @@ void add_module(const struct module_ops *module)
 {
        ret_msg_if(!module, "Invalid module handler\n");
 
-       _I("[DEBUG] module: %s is added", module->name);        
-
        if (module->priority == MODULE_PRIORITY_EARLY)
                modules_list = g_slist_prepend(modules_list, (gpointer)module);
        else
@@ -114,7 +112,6 @@ static void module_initcall_level(void *data, int priority)
                }
 
                module->initalized = MODULE_INITIALIZED;
-               _D("[DEBUG] Initialized [%s] module\n", module->name);
        }
 }
 
index 1b96960..a85a026 100644 (file)
@@ -88,7 +88,6 @@ static int cpu_sched_init_cgroup_set(const struct coreset *set)
        assert(set);
        assert(set->name);
 
-       _D("[DEBUG] cpu-sched: init cgroup set for %s", set->name);
        r = cgroup_make_subdir(CPUSET_CGROUP, set->name, NULL);
        if (r < 0) {
                _E("[DEBUG] failed to make cpuset cgroup (%s)", set->name);
@@ -116,7 +115,6 @@ static int cpu_sched_init_cgroup(struct cpu_sched *cs)
        GSList *i;
        struct coreset *c;
 
-       _D("[DEBUG] cpu-sched: init cgroup subsystem");
        if (cpu_sched_is_cpuset_mounted() == false) {
                r = cgroup_make_subdir(CGROUP_PATH, "cpuset", NULL);
                if (r < 0) {
@@ -151,7 +149,6 @@ static int cpu_sched_new_core(struct coreset *set, int core_id)
        assert(set);
        assert(core_id >= 0);
 
-       _D("[DEBUG] cpu-sched: new core %d for set %s", core_id, set->name);
        c = (struct core *)calloc(1, sizeof *c);
        if (c == NULL) {
                _E("cpu-sched: could not allocate memory for core struct");
@@ -200,7 +197,6 @@ static int cpu_sched_parse_cpuset(struct coreset *set, char *value)
        assert(set);
        assert(value);
        assert(!set->cores);
-       _D("[DEBUG] cpu-sched: parse cpuset for %s (%s)", set->name, value);
 
        ptr = strtok_r(value, ",", &saveptr);
        while (ptr) {
@@ -272,7 +268,6 @@ static int load_config(struct cpu_sched *data)
 
 static int cpu_sched_parse_config(struct cpu_sched *data)
 {
-       _D("[DEBUG] cpu-sched: parse config");
        load_config(data);
 /*     if (config_parse(CPU_SCHED_CONF_FILE, load_config, data) < 0)
                return RESOURCED_ERROR_FAIL;*/
@@ -569,7 +564,6 @@ static void cpu_sched_check_apps()
 static int cpu_sched_init(void *data)
 {
        int r;
-       _D("[DEBUG] cpu-sched: init module");
 
        if (cpu_sched_parse_config(&cs) != RESOURCED_ERROR_NONE) {
                _E("cpu-sched: error parsing config");
@@ -586,7 +580,6 @@ static int cpu_sched_init(void *data)
                return RESOURCED_ERROR_FAIL;
        }
 
-       _D("[DEBUG] cpu-sched: init module end");
        cs.is_initalized = true;
        cpu_sched_check_apps();
        return RESOURCED_ERROR_NONE;
index 1cea90a..4143e36 100644 (file)
@@ -204,7 +204,6 @@ static int lowmem_limit_broadcast(pid_t pid)
        if (ret < 0)
                _E("[DEBUG] Fail to broadcast dbus signal with pid(%d), appname(%s)", pid, appname);
 
-       _I("[DEBUG] broadcast signal to notify");
        return ret;
 }
 
@@ -223,12 +222,9 @@ static gboolean liveness_check_cb(gpointer data)
        }
 
        if (kill(mle->pid, 0) == 0) {
-               _D("[DEBUG] pid (%d) is still alive, so kill directly using SIGKILL", mle->pid);
                safe_kill(mle->pid, SIGKILL);
        }
 
-       _D("[DEBUG] pid (%d) is dead", mle->pid);
-
 mle_timer_init:
        mle->pid = -1;
 timer_out:
@@ -245,7 +241,6 @@ static bool memory_action_cb(int fd, void *data)
        struct memory_limit_event *mle;
        _cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
 
-       _I("[DEBUG] receive lowmem limit about %s", cg_dir);
        mle = g_hash_table_lookup(memory_limit_hash, cg_dir);
        if (!mle) {
                _E("invalid event\n");
@@ -395,7 +390,6 @@ int lowmem_reassign_limit(const char *dir,
                g_hash_table_insert(memory_limit_hash, (gpointer)mle->path,
                                (gpointer)mle);
 
-               _I("[DEBUG] a memory cgroup notificatoin is registered at %s", dir);
                return RESOURCED_ERROR_NONE;
        }
 
@@ -461,8 +455,6 @@ void lowmem_limit_set_system_service(pid_t pid, unsigned int limit,
        int result;
        unsigned int totalram = lowmem_get_totalram();
 
-       _I("[DEBUG] pid: %d, limit: %u, name: %s, action: %d", pid, limit, name, action);
-
        if (limit < MIN_LIMIT_VALUE || limit > totalram) {
                _E("[DEBUG] It's meaningless to set memory limit with size (%d)", limit);
                return;
@@ -645,9 +637,6 @@ void lowmem_memory_init(unsigned int service_limit, unsigned int widget_limit,
        mem_widget_limit = widget_limit;
        mem_guiapp_limit = guiapp_limit;
        mem_bgapp_limit = bgapp_limit;
-
-       _I("[DEBUG] Limit of service = %u, widget = %u, guiap = %u, bgapp = %u bytes", 
-                       mem_service_limit, mem_widget_limit, mem_guiapp_limit, mem_bgapp_limit);
 }
 
 void lowmem_action_init(int service_action, int widget_action,
@@ -664,9 +653,6 @@ void lowmem_action_init(int service_action, int widget_action,
 
        if (bgapp_action > 0)
                mem_bgapp_action = bgapp_action;
-
-       _I("[DEBUG] action of service = %d, widget = %d, guiap = %d, bgapp = %d bytes", 
-                       service_action, widget_action, guiapp_action, bgapp_action);
 }
 
 void lowmem_limit_init(void)
index 4211080..1e4678d 100644 (file)
@@ -1743,7 +1743,6 @@ static void setup_memcg_params(void)
                memcg_set_leave_threshold(CGROUP_ROOT, CGROUP_ROOT_3072_THRES_LEAVE);
                num_max_victims = CGROUP_ROOT_3072_NUM_VICTIMS;
        }
-
 }
 
 static void lowmem_move_memcgroup(int pid, int next_oom_score_adj, struct proc_app_info *pai)
@@ -1779,7 +1778,6 @@ static void lowmem_move_memcgroup(int pid, int next_oom_score_adj, struct proc_a
                if (cur_oom_score_adj != OOMADJ_APP_MAX + 10) {
                        /* VIP processes should not be asked to move. */
                        if (cur_memcg_idx <= CGROUP_VIP) {
-                               _I("[DEBUG] pid: %d, name: %s, cur_oom_score_adj: %d", pid, pai->appid, cur_oom_score_adj);
                                _E("[DEBUG] current cgroup (%s) cannot be VIP or Root", convert_cgroup_type_to_str(cur_memcg_idx));
                                return;
                        }
@@ -2210,7 +2208,7 @@ static void print_mem_configs(void)
        _I("[DEBUG] set number of max victims as %d", num_max_victims);
        _I("[DEBUG] set threshold leave to %u MB", get_root_memcg_info()->threshold_leave);
        _I("[DEBUG] set proactive threshold to %u MB", proactive_threshold);
-       _I("[DEUBG] set proactive low memory killer leave to %u MB", proactive_leave);
+       _I("[DEBUG] set proactive low memory killer leave to %u MB", proactive_leave);
 
        /* print info of POPUP section */
        _I("[DEBUG] oom popup is %s", oom_popup_enable == true ? "enabled" : "disabled");
@@ -2227,6 +2225,8 @@ static void print_mem_configs(void)
        _I("prefix of memlimit memps is %s", memlog_prefix[MEMLOG_MEMPS_MEMLIMIT]);*/
 }
 
+#include "file-helper.h"
+
 /* To Do: should we need lowmem_fd_start, lowmem_fd_stop ?? */
 static int lowmem_init(void)
 {
@@ -2245,7 +2245,7 @@ static int lowmem_init(void)
        load_configs(MEM_CONF_FILE);
 
        /* this function should be called after parsing configurations */
-       memcg_write_params();
+       memcg_write_limiter_params();
        print_mem_configs();
 
        /* make a worker thread called low memory killer */
@@ -2266,7 +2266,6 @@ static int lowmem_init(void)
        lowmem_limit_init();
        lowmem_system_init();
 
-       _D("[DEBUG] resourced memory init end with ret = %d", ret);
        register_notifier(RESOURCED_NOTIFIER_APP_PRELAUNCH, lowmem_prelaunch_handler);
        register_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler);
        register_notifier(RESOURCED_NOTIFIER_LCD_OFF, lowmem_bg_reclaim_handler);
index ef06171..47801e2 100644 (file)
@@ -876,8 +876,6 @@ static int swap_parse_config_file(void)
        if (arg_swap_enable == false)
                goto free_swap_conf;
 
-       _I("[DEBUG] swap type: %s", swap_conf->type);
-
        arg_swap_at_boot = swap_conf->boot_reclaim_enable; 
        if (config_parse_swap_types(swap_conf->type, &arg_swap_type) < 0) { 
                _E("[DEBUG] Failed to parse type of swap, so use default zram type");
@@ -989,6 +987,8 @@ static int swap_init(void)
        if (!arg_swap_enable)
                return -ENODEV;
 
+       memcg_write_optimizer_params();
+
        gslist_for_each_safe(swap_module, iter, next, swaps) {
                swaps = (struct swap_module_ops *)iter->data;
                if (!CHECK_BIT(arg_swap_type, swaps->type)) {
index 804824c..5b868b8 100644 (file)
@@ -252,26 +252,22 @@ int fixed_service_list_init(void *data)
 
                /* fixed memory cgroup */
                if (pci->mem_type != CGROUP_TOP) {
-                       _I("[DEBUG] pid = %d, oom: %d, name: %s", pid, cgroup_get_lowest_oom_score_adj(pci->mem_type), pci->name);
                        proc_set_oom_score_adj(pid, cgroup_get_lowest_oom_score_adj(pci->mem_type), NULL);
                }
 
                /* fixed cpu cgroup */
                if (pci->cpu_type != CGROUP_TOP) {
-                       _I("[DEBUG] pid = %d, cgroup: %s, name: %s", pid, CPU_CGROUP_PATH(pci->cpu_type), pci->name);
                        cpu_move_cgroup_foreach(pid, NULL, CPU_CGROUP_PATH(pci->cpu_type));
                }
 
                /* fixed cpu priority */
                if (pci->cpu_priority != CPU_INIT_PRIO) {
-                       _I("[DEBUG] pid = %d, cpu prio: %d, name: %s", pid, pci->cpu_priority, pci->name);
                        setpriority(PRIO_PROCESS, pid, pci->cpu_priority);
                }
 
                /* register a notification when this service is released */
                switch (pci->fail_action) {
                        case PROC_ACTION_REBOOT:
-                               _I("[DEBUG] Reboot on Failure");
                                proc_watchdog_booting_done(pci->name, pid);
                                break;
                        default: