Support resourced early boot 91/275291/4
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 20 May 2022 01:43:54 +0000 (10:43 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 20 May 2022 05:05:34 +0000 (14:05 +0900)
Change-Id: I5140217ac049f65a81cd622cc23597caf34dfd22
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
conf/monitor.conf
src/common/cgroup/cgroup.c
src/common/module.c
src/common/module.h
src/common/resourced-helper-worker.c
src/resource-limiter/memory/vmpressure-lowmem-handler.c
src/resource-monitor/heart.c
src/resource-optimizer/memory/swap/swap.c
src/resourced/resourced.service

index 6a262b2..54e4b5f 100644 (file)
@@ -1,8 +1,8 @@
 [HEART]
-BATTERY=ON
-CPU=ON
+BATTERY=OFF
+CPU=OFF
 MEMORY=OFF
-STORAGE=ON
+STORAGE=OFF
 
 [BATTERY_POWER_MODE]
 POWER_NORMAL_MODE=676
index 3557374..59fd9b7 100644 (file)
@@ -121,78 +121,120 @@ resourced_ret_c cgroup_write_pid(const char *cgroup_subsystem,
 int cgroup_write_node_uint32(const char *cgroup_name,
                const char *file_name, uint32_t value)
 {
+       int ret;
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, value %u\n", buf, value);
-       return fwrite_uint(buf, value);
+       ret = fwrite_uint(buf, value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %u\n", buf, value);
+       else
+               _SE("errno = %d", ret);
+
+       return ret;
 }
 
 int cgroup_write_node_int32(const char *cgroup_name,
                const char *file_name, int32_t value)
 {
+       int ret;
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, value %d\n", buf, value);
-       return fwrite_int(buf, value);
+       ret = fwrite_int(buf, value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %d\n", buf, value);
+       else
+               _SE("errno = %d", ret);
+
+       return ret;
 }
 
 int cgroup_write_node_ulonglong(const char *cgroup_name,
                const char *file_name, unsigned long long value)
 {
+       int ret;
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, value %llu\n", buf, value);
-       return fwrite_ulonglong(buf, value);
+       ret = fwrite_ulonglong(buf, value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %llu\n", buf, value);
+       else
+               _SE("errno = %d", ret);
+
+       return ret;
 }
 
 int cgroup_write_node_longlong(const char *cgroup_name,
                const char *file_name, long long value)
 {
+       int ret;
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, value %lld\n", buf, value);
-       return fwrite_longlong(buf, value);
+       ret = fwrite_longlong(buf, value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %lld\n", buf, value);
+       else
+               _SE("errno = %d", ret);
+
+       return ret;
 }
 
 int cgroup_write_node_str(const char *cgroup_name,
                        const char *file_name, const char *string)
 {
+       int ret;
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
-       _SD("cgroup_buf %s, string %s\n", buf, string);
-       return fwrite_str(buf, string);
+       ret = fwrite_str(buf, string);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %s\n", buf, string);
+       else
+               _SE("errno = %d", ret);
+
+       return ret;
 }
 
 int cgroup_read_node_uint32(const char *cgroup_name,
                const char *file_name, uint32_t *value)
 {
-       char buf[MAX_PATH_LENGTH];
        int ret;
+       char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
        ret = fread_uint(buf, value);
-       _SD("cgroup_buf %s, value %d\n", buf, *value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %u\n", buf, *value);
+       else
+               _SE("errno = %d", ret);
+
        return ret;
 }
 
 int cgroup_read_node_int32(const char *cgroup_name,
                const char *file_name, int32_t *value)
 {
-       char buf[MAX_PATH_LENGTH];
        int ret;
+       char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
        ret = fread_int(buf, value);
-       _SD("cgroup_buf %s, value %d\n", buf, *value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %d\n", buf, *value);
+       else
+               _SE("errno = %d", ret);
+
        return ret;
 }
 
 int cgroup_read_node_ulonglong(const char *cgroup_name,
                const char *file_name, unsigned long long *value)
 {
-       char buf[MAX_PATH_LENGTH];
        int ret;
+       char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
        ret = fread_ulonglong(buf, value);
-       _SD("cgroup_buf %s, value %llu\n", buf, *value);
+       if (ret == RESOURCED_ERROR_NONE)
+               _SD("cgroup_buf = %s, value = %llu\n", buf, *value);
+       else
+               _SE("errno = %d", ret);
+
        return ret;
 }
 
index 4fb2d6d..1ac2a68 100644 (file)
@@ -117,11 +117,12 @@ static void module_initcall_level(void *data, int priority)
 
 void modules_init(void *data)
 {
-       module_initcall_level(data, MODULE_PRIORITY_NORMAL);
+       module_initcall_level(data, MODULE_PRIORITY_HIGH);
 }
 
 void modules_init_late(void *data)
 {
+       module_initcall_level(data, MODULE_PRIORITY_NORMAL);
        module_initcall_level(data, MODULE_PRIORITY_LATE);
 }
 
index 50241d6..0cf1aa0 100644 (file)
@@ -48,16 +48,16 @@ enum module_priority {
        MODULE_PRIORITY_NORMAL,
 
        /**
-        * MODULE_PRIORITY_EARLY modules are initialized
-        * before MODULE_PRIORITY_NORMAL modules.
-        */
-       MODULE_PRIORITY_EARLY,
-
-       /**
         * MODULE_PRIORITY_HIGH modules are initialized
         * as soon as resourced is started.
         */
        MODULE_PRIORITY_HIGH,
+
+       /**
+        * MODULE_PRIORITY_EARLY modules are initialized
+        * before MODULE_PRIORITY_NORMAL modules.
+        */
+       MODULE_PRIORITY_EARLY,
 };
 
 enum module_state {
index 0ed382c..5ae1e63 100644 (file)
@@ -31,7 +31,7 @@
 #include "fd-handler.h"
 
 /* resourced helper worker */
-static struct resourced_worker rhw;
+/*static struct resourced_worker rhw;
 static int pfds[2];
 static fd_handler_h phandler;
 
@@ -178,13 +178,13 @@ int request_helper_worker(enum helper_worker_operation op,
        queue_request(&rhw, rhd);
 
        return RESOURCED_ERROR_NONE;
-}
+}*/
 
 static int resourced_worker_init(void *data)
 {
        int ret = RESOURCED_ERROR_NONE;
 
-       if (PTHREAD_WORKER_IS_ACTIVE(&rhw)) {
+/*     if (PTHREAD_WORKER_IS_ACTIVE(&rhw)) {
                _I("helper worker thread [%d] has already been created\n",
                                (unsigned)rhw.worker_thread);
                return ret;
@@ -206,25 +206,25 @@ static int resourced_worker_init(void *data)
        } else {
                pthread_detach(rhw.worker_thread);
                ret = RESOURCED_ERROR_NONE;
-       }
+       }*/
        return ret;
 }
 
 static int resourced_worker_finalize(void *data)
 {
-       if (!PTHREAD_WORKER_IS_ACTIVE(&rhw))
+/*     if (!PTHREAD_WORKER_IS_ACTIVE(&rhw))
                return RESOURCED_ERROR_NONE;
 
        pipe_exit();
        PTHREAD_WORKER_DEACTIVATE(&rhw);
        resourced_helper_drain_queue(&rhw);
        g_async_queue_unref(rhw.queue);
-       pthread_cancel(rhw.worker_thread);
+       pthread_cancel(rhw.worker_thread);*/
        return RESOURCED_ERROR_NONE;
 }
 
 static struct module_ops resourced_helper_worker_ops = {
-       .priority = MODULE_PRIORITY_HIGH,
+       .priority = MODULE_PRIORITY_NORMAL,
        .name = "resourced-helper-worker",
        .init = resourced_worker_init,
        .exit = resourced_worker_finalize,
index 8e3e1b1..f224763 100644 (file)
@@ -357,8 +357,6 @@ static int num_vict_between_check = MAX_VICTIMS_BETWEEN_CHECK;
 static unsigned long long totalram_bytes;
 static unsigned long totalram_kb;
 
-static struct module_ops memory_modules_ops;
-static const struct module_ops *lowmem_ops;
 static bool oom_popup_enable;
 static bool oom_popup;
 static bool memcg_swap_status;
@@ -1891,7 +1889,6 @@ static int lowmem_exit(void)
 
 static int resourced_memory_init(void *data)
 {
-       lowmem_ops = &memory_modules_ops;
        return lowmem_init();
 }
 
@@ -1959,7 +1956,7 @@ void lowmem_restore_memcg(struct proc_app_info *pai)
 }
 
 static struct module_ops memory_modules_ops = {
-       .priority       = MODULE_PRIORITY_HIGH,
+       .priority       = MODULE_PRIORITY_EARLY,
        .name           = "lowmem",
        .init           = resourced_memory_init,
        .exit           = resourced_memory_finalize,
index d0a568e..99217f7 100644 (file)
@@ -166,7 +166,7 @@ static int resourced_heart_exit(void *data)
 }
 
 static struct module_ops heart_modules_ops = {
-       .priority       = MODULE_PRIORITY_HIGH,
+       .priority       = MODULE_PRIORITY_NORMAL,
        .name           = "HEART",
        .init           = resourced_heart_init,
        .dump           = resourced_heart_dump,
index 7a053c7..d68dbf4 100644 (file)
@@ -71,6 +71,7 @@
 
 enum swap_thread_op {
        SWAP_OP_ACTIVATE,
+       SWAP_OP_EARLY_RECLAIM,
        SWAP_OP_RECLAIM,
        SWAP_OP_COMPACT,
        SWAP_OP_END,
@@ -194,7 +195,7 @@ static int swap_move_to_cgroup_by_pid(enum cgroup_type type, pid_t pid)
 
        error = proc_get_oom_score_adj(pid, &oom_score_adj);
        if (error) {
-               _E("Cannot get oom_score_adj of pid (%d)", pid);
+               _E("[SWAP] Cannot get oom_score_adj of pid (%d)", pid);
                return RESOURCED_ERROR_FAIL;
        }
 
@@ -240,7 +241,7 @@ static int swap_use_hard_limit(char *memcg)
        }
 
        if (ret != RESOURCED_ERROR_NONE)
-               _E("Not able to set hard limit of %s memory cgroup", memcg);
+               _E("[SWAP] Not able to set hard limit of %s memory cgroup", memcg);
 
        return ret;
 }
@@ -322,7 +323,7 @@ static int swap_start_reclaim(char *memcg)
                r = cgroup_write_node_uint32(memcg,
                        MEMCG_SWAPPINESS, SWAP_MEMCG_SWAPPINESS);
                if (r) {
-                       _I("failed to write %s %d to %s the",
+                       _I("[SWAP] failed to write %s %d to %s the",
                                MEMCG_SWAPPINESS, SWAP_MEMCG_SWAPPINESS, memcg);
                        return -errno;
                }
@@ -339,7 +340,7 @@ static int swap_start_reclaim(char *memcg)
                r = cgroup_write_node_uint32(memcg,
                        MEMCG_SWAPPINESS, current_swappiness);
                if (r) {
-                       _I("failed to write %s %d to %s the",
+                       _I("[SWAP] failed to write %s %d to %s the",
                                MEMCG_SWAPPINESS, SWAP_MEMCG_SWAPPINESS, memcg);
                        return -errno;
                }
@@ -422,7 +423,7 @@ static int swap_losetup(struct swap_module_ops *swap,
        if (!is_empty(crypt_type)) {
                r = gen_urandom_string(passwd, LO_KEY_SIZE);
                if (r < 0) {
-                       _E("Failed to generate random passwd: %m");
+                       _E("[SWAP] Failed to generate random passwd: %m");
                        return r;
                }
        }
@@ -430,10 +431,10 @@ static int swap_losetup(struct swap_module_ops *swap,
        r = find_loop_device(swapfile, swapdevice);
        if (r < 0) {
                if (r == -EEXIST) {
-                       _I("'%s' is already setuped to '%s'", swapfile, swapdevice);
+                       _I("[SWAP] '%s' is already setuped to '%s'", swapfile, swapdevice);
                        goto finish;
                } else
-                       _E("Failed to find available loop device.");
+                       _E("[SWAP] Failed to find available loop device.");
                return r;
        }
 
@@ -441,7 +442,7 @@ static int swap_losetup(struct swap_module_ops *swap,
                    crypt_type, passwd, false);
 
        if (r < 0) {
-               _E("Failed to setup loop: %d", r);
+               _E("[SWAP] Failed to setup loop: %d", r);
                return r;
        }
 
@@ -461,17 +462,17 @@ int swap_set_file(char *filename, struct swap_module_ops *swap, char *crypt_type
                r = do_dd("/dev/zero", filename, PAGE_SIZE,
                          KBYTE_TO_BYTE(swap->k_size) >> PAGE_SHIFT);
                if (r > 0) {
-                       _E("Failed to create swap file(%s), exit code: %d",
+                       _E("[SWAP] Failed to create swap file(%s), exit code: %d",
                                        filename, r);
                        return -1;
                } else if (r < 0) {
-                       _E("Failed to create swap file(%s): %d",
+                       _E("[SWAP] Failed to create swap file(%s): %d",
                                        filename, r);
                        return r;
                }
-               _I("SwapFile is created: %s", filename);
+               _I("[SWAP] SwapFile is created: %s", filename);
        } else if (r != 0) {
-               _E("Failed to access swap file(%s): %m", filename);
+               _E("[SWAP] Failed to access swap file(%s): %m", filename);
                return -errno;
        }
 
@@ -484,10 +485,10 @@ int swap_set_file(char *filename, struct swap_module_ops *swap, char *crypt_type
 
        r = do_mkswap(swap->path);
        if (r > 0) {
-               _E("Failed to make swap device(%s), exit code: %d", swap->path, r);
+               _E("[SWAP] Failed to make swap device(%s), exit code: %d", swap->path, r);
                return -EBUSY;
        } else if (r < 0) {
-               _E("Failed to make swap device(%s): %d", swap->path, r);
+               _E("[SWAP] Failed to make swap device(%s): %d", swap->path, r);
        }
        return r;
 }
@@ -509,15 +510,75 @@ bool swap_is_on(const char *name)
        return false;
 }
 
+static void swap_early_reclaim_memcg(void)
+{
+       int r;
+       static bool early_reclaim = false;
+
+       /*
+        * Most system daemons use much memory for intializing own process.
+        * but there is little change to reuse it while running.
+        * So early reclaiming moves unused system memory to swap device.
+        * If multiple swap devices are available,
+        * first swap with the lowest priority will start reclaiming.
+        */
+       if (!early_reclaim) {
+               int try = arg_swap_at_boot_maxtry;
+               unsigned long long usage_bytes, prev_usage_bytes = 0;
+
+               r = cgroup_read_node_ulonglong(MEMCG_PATH,
+                               MEMCG_SWAP_USAGE, &prev_usage_bytes);
+               if (r) {
+                       r = cgroup_read_node_ulonglong(MEMCG_PATH,
+                                       MEMCG_USAGE, &prev_usage_bytes);
+                       if (r)
+                               prev_usage_bytes = ULONG_MAX;
+               }
+
+               for (;;) {
+                       try--;
+                       swap_start_reclaim(MEMCG_PATH);
+
+                       r = cgroup_read_node_ulonglong(MEMCG_PATH,
+                                       MEMCG_SWAP_USAGE, &usage_bytes);
+                       if (r) {
+                               r = cgroup_read_node_ulonglong(MEMCG_PATH,
+                                               MEMCG_USAGE, &usage_bytes);
+                               if (r) {
+                                       _E("[SWAP] Early reclaim is aborted");
+                                       break;
+                               }
+                       }
+
+                       /*
+                        * Continue to reclaim memory at boot time until
+                        * there is no more saving or trial reaches maximum.
+                        * The default threshold is very large, so it may
+                        * reclaim once.
+                        */
+                       if (!try || prev_usage_bytes - usage_bytes < arg_swap_at_boot_threshold_bytes)
+                               break;
+
+                       prev_usage_bytes = usage_bytes;
+                       /*
+                        * To prevent continuous reclaim to harm entire system,
+                        * having relaxation on each reclaim
+                        */
+                       sleep(arg_swap_at_boot_interval_sec);
+               }
+
+               early_reclaim = true;
+       }
+}
+
 static void swap_activate_in_module(void)
 {
        int r;
        GSList *iter;
        struct swap_module_ops *swaps;
-       static bool early_reclaim;
 
        r = cgroup_read_node_int32(MEMCG_PATH,
-               MEMCG_SWAPPINESS, &current_swappiness);
+                       MEMCG_SWAPPINESS, &current_swappiness);
        if (r)
                return;
 
@@ -535,7 +596,7 @@ static void swap_activate_in_module(void)
                r = swaps->activate(swaps);
                if (r != 0) {
                        if (r != -EEXIST) {
-                               _E("%s activate failed", swaps->name);
+                               _E("[SWAP] %s activate failed", swaps->name);
                                swap_remove(swaps);
                        }
                        swap_set_state(SWAP_ON);
@@ -550,56 +611,11 @@ static void swap_activate_in_module(void)
 #endif
                r = swapon(swaps->path, flags);
                if (r < 0) {
-                       _E("Failed to turn on swap device(%s): %m", swaps->path);
+                       _E("[SWAP] Failed to turn on swap device(%s): %m", swaps->path);
                        continue;
                }
-               _I("swap device(%s) was turned on: %s", swaps->name, swaps->path);
-
-               /*
-                * Most system daemons use much memory for intializing own process.
-                * but there is little change to reuse it while running.
-                * So early reclaiming moves unused system memory to swap device.
-                * If multiple swap devices are available,
-                * first swap with the lowest priority will start reclaiming.
-                */
-               if (!early_reclaim) {
-                       int try = arg_swap_at_boot_maxtry;
-                       unsigned long long usage_bytes, prev_usage_bytes = 0;
-
-                       r = cgroup_read_node_ulonglong(MEMCG_PATH,
-                               MEMCG_SWAP_USAGE, &prev_usage_bytes);
-                       if (r)
-                               prev_usage_bytes = ULONG_MAX;
+               _I("[SWAP] swap device(%s) was turned on: %s", swaps->name, swaps->path);
 
-                       for (;;) {
-                               try--;
-                               swap_start_reclaim(MEMCG_PATH);
-
-                               r = cgroup_read_node_ulonglong(MEMCG_PATH,
-                                               MEMCG_SWAP_USAGE, &usage_bytes);
-                               if (r) {
-                                       _E("Early reclaimed is aborted");
-                                       break;
-                               }
-
-                               /*
-                                * Continue to reclaim memory at boot time until
-                                * there is no more saving or trial reaches maximum.
-                                * The default threshold is very large, so it may
-                                * reclaim once.
-                                */
-                               if (!try || prev_usage_bytes - usage_bytes < arg_swap_at_boot_threshold_bytes)
-                                       break;
-
-                               prev_usage_bytes = usage_bytes;
-                               /*
-                                * To prevent continuous reclaim to harm entire system,
-                                * having relaxation on each reclaim
-                                */
-                               sleep(arg_swap_at_boot_interval_sec);
-                       }
-                       early_reclaim = true;
-               }
 
                swap_set_state(SWAP_ON);
        }
@@ -632,22 +648,26 @@ static void *swap_thread_main(void * data)
                        goto unlock_out;
 
                switch (bundle->op) {
-               /* Swap activation operttion: mkswap, swapon etc. */
-               case SWAP_OP_ACTIVATE:
-                       swap_activate_in_module();
-                       break;
-               /* Swap reclaim opertation: move to swap, force_reclaim */
-               case SWAP_OP_RECLAIM:
-                       swap_reclaim_memcg(bundle->msg.path);
-                       break;
-               /* Swap compact operation of zsmalloc. */
-               case SWAP_OP_COMPACT:
-                       swap_compact_in_module();
-                       break;
-               /* Move inactive procesess to swap, and reclaim after that. */
-               case SWAP_OP_END:
-               default:
-                       _D("wrong swap thread operation selected");
+                       /* Swap activation operttion: mkswap, swapon etc. */
+                       case SWAP_OP_ACTIVATE:
+                               swap_activate_in_module();
+                               break;
+                               /* Swap early reclaim operation: move to swap, force_reclaim */
+                       case SWAP_OP_EARLY_RECLAIM:
+                               swap_early_reclaim_memcg();
+                               break;
+                               /* Swap reclaim opertation: move to swap, force_reclaim */
+                       case SWAP_OP_RECLAIM:
+                               swap_reclaim_memcg(bundle->msg.path);
+                               break;
+                               /* Swap compact operation of zsmalloc. */
+                       case SWAP_OP_COMPACT:
+                               swap_compact_in_module();
+                               break;
+                               /* Move inactive procesess to swap, and reclaim after that. */
+                       case SWAP_OP_END:
+                       default:
+                               _D("[SWAP] wrong swap thread operation selected");
                }
 
                free(bundle);
@@ -670,14 +690,14 @@ static int swap_communicate_thread(struct swap_thread_bundle *bundle)
        if (ret == 0) {
                pthread_cond_signal(&swap_cond);
                pthread_mutex_unlock(&swap_mutex);
-               _I("send signal to swap thread");
+               _I("[SWAP] send signal to swap thread");
                return RESOURCED_ERROR_NONE;
        } else if (ret == EBUSY) {
-               _D("swap thread already active");
+               _D("[SWAP] swap thread already active");
                return RESOURCED_ERROR_NONE;
        }
 
-       _E("pthread_mutex_trylock fail: %d, errno: %d", ret, errno);
+       _E("[SWAP] pthread_mutex_trylock fail: %d, errno: %d", ret, errno);
        return RESOURCED_ERROR_FAIL;
 }
 
@@ -688,7 +708,7 @@ static int swap_start_handler(void *data)
        struct swap_thread_bundle *bundle;
 
        if (!path) {
-               _E("path name is NULL");
+               _E("[SWAP] path name is NULL");
                return RESOURCED_ERROR_NO_DATA;
        }
 
@@ -698,7 +718,7 @@ static int swap_start_handler(void *data)
 
        ret = str_name_cpy(bundle->msg.path, path, sizeof(bundle->msg.path), strlen(path));
        if (ret < 0) {
-               _E("msg size (%d) is smaller than source length (%d)",
+               _E("[SWAP] msg size (%d) is smaller than source length (%d)",
                                (int)sizeof(bundle->msg.path), (int)strlen(path) + 1);
                free(bundle);
                return ret;
@@ -729,9 +749,9 @@ static int swap_activate_handler(void *data)
 
 static gboolean swap_activate_timer_cb(gpointer data)
 {
-       _I("Starting an " EARLYRECLAIM_WITH_AN_EXPLANATION_FOR_LAYMEN);
+       _I("[SWAP] Starting an " EARLYRECLAIM_WITH_AN_EXPLANATION_FOR_LAYMEN);
        swap_activating_timer = NULL;
-       swap_internal_bundle_sender(SWAP_OP_ACTIVATE);
+       swap_internal_bundle_sender(SWAP_OP_EARLY_RECLAIM);
        return false;
 }
 
@@ -751,7 +771,7 @@ static int swap_booting_done(void *data)
                return RESOURCED_ERROR_NONE;
        }
 
-       _D("booting done; starting up a timer to perform an " EARLYRECLAIM_WITH_AN_EXPLANATION_FOR_LAYMEN " %ds from now", arg_timer_swap_at_boot_sec);
+       _D("[SWAP] booting done; starting up a timer to perform an " EARLYRECLAIM_WITH_AN_EXPLANATION_FOR_LAYMEN " %ds from now", arg_timer_swap_at_boot_sec);
        swap_activating_timer = g_timeout_source_new_seconds((guint) arg_timer_swap_at_boot_sec);
        g_source_set_callback(swap_activating_timer, swap_activate_timer_cb, NULL, NULL);
        g_source_attach(swap_activating_timer, NULL);
@@ -761,7 +781,7 @@ static int swap_booting_done(void *data)
 
 static int swap_compact_handler(void *data)
 {
-       _I("compaction request. Reason: %s",
+       _I("[SWAP] compaction request. Reason: %s",
                        compact_reason_to_str((enum swap_compact_reason)data));
        return swap_internal_bundle_sender(SWAP_OP_COMPACT);
 }
@@ -776,7 +796,7 @@ static int swap_cgroup_reset_limit(void *data)
        struct memcg_info *mi = (struct memcg_info *)data;
 
        if (!mi) {
-               _E("memory cgroup information is NULL");
+               _E("[SWAP] memory cgroup information is NULL");
                return RESOURCED_ERROR_INVALID_PARAMETER;
        }
 
@@ -785,9 +805,9 @@ static int swap_cgroup_reset_limit(void *data)
 
        ret = check_oom_and_set_limit(mi->name, mi->limit_bytes);
        if (ret != RESOURCED_ERROR_NONE)
-               _E("Failed to change hard limit of %s cgroup to -1", mi->name);
+               _E("[SWAP] Failed to change hard limit of %s cgroup to -1", mi->name);
        else
-               _D("changed hard limit of %s cgroup to -1", mi->name);
+               _D("[SWAP] changed hard limit of %s cgroup to -1", mi->name);
 
        return ret;
 }
@@ -799,7 +819,7 @@ static void swap_start_pid_dbus_signal_handler(GVariant *params)
 
        do_expr_unless_g_variant_get_typechecked(return, params, "(i)", &pid);
        if (pid <= 0) {
-               _D("Invalid parameter");
+               _D("[SWAP] Invalid parameter");
                return;
        }
 
@@ -808,7 +828,7 @@ static void swap_start_pid_dbus_signal_handler(GVariant *params)
                return;
        swap_move_to_cgroup_by_pid(MEMCG_LOW, pid);
        swap_start_handler(cgroup_swap->memcg_info->name);
-       _I("swap cgroup entered : pid : %d", (int)pid);
+       _I("[SWAP] swap cgroup entered : pid : %d", (int)pid);
 }
 
 
@@ -903,13 +923,13 @@ static int swap_thread_create(void)
        swap_thread_queue.queue = g_queue_new();
 
        if (!swap_thread_queue.queue) {
-               _E("fail to allocate swap thread queue");
+               _E("[SWAP] fail to allocate swap thread queue");
                return RESOURCED_ERROR_FAIL;
        }
 
        ret = pthread_create(&pth, NULL, &swap_thread_main, (void *)NULL);
        if (ret) {
-               _E("pthread creation for swap_thread failed\n");
+               _E("[SWAP] pthread creation for swap_thread failed\n");
                return ret;
        } else {
                pthread_detach(pth);
@@ -952,21 +972,21 @@ static int swap_init(void)
                 */
                if (swap_pri == SWAP_PRI_DISABLE) {
                        swap_remove(swaps);
-                       _E("don't allow other %s module", swaps->name);
+                       _E("[SWAP] don't allow other %s module", swaps->name);
                        continue;
                }
                swap_pri = swaps->priority;
 
                r = swaps->init(swaps);
                if (r != 0) {
-                       _E("%s module init failed", swaps->name);
+                       _E("[SWAP] %s module init failed", swaps->name);
                        swap_remove(swaps);
                }
        }
 
        r = swap_thread_create();
        if (r) {
-               _E("swap thread create failed");
+               _E("[SWAP] swap thread create failed");
                return r;
        }
        swap_dbus_init();
@@ -980,7 +1000,7 @@ static int swap_check_node(char *path)
 
        fp = fopen(path, "w");
        if (fp == NULL) {
-               _E("%s open failed", path);
+               _E("[SWAP] %s open failed", path);
                return RESOURCED_ERROR_NO_DATA;
        }
        return RESOURCED_ERROR_NONE;
@@ -988,22 +1008,24 @@ static int swap_check_node(char *path)
 
 static int resourced_swap_check_runtime_support(void *data)
 {
-       int r;
-       unsigned long long usage_bytes;
+       int r = RESOURCED_ERROR_NONE;
+//     unsigned long long usage_bytes;
 
        /*
         * Check whether CONFIG_SWAP is enabled in kernel.
         */
-       if (access("/proc/swaps", R_OK) != 0)
+       if (access("/proc/swaps", R_OK) != 0) {
+               _W("CONFIG_SWAP is disabled");
                return -ENOENT;
+       }
 
        /*
         * Check whether kernel is supporting MEMCG_SWAP.
         */
-       r = cgroup_read_node_ulonglong(MEMCG_PATH,
+/*     r = cgroup_read_node_ulonglong(MEMCG_PATH,
                                MEMCG_SWAP_USAGE, &usage_bytes);
        if (r)
-               return -ENOENT;
+               return -ENOENT;*/
 
        return r;
 }
@@ -1052,17 +1074,17 @@ static void resourced_swap_change_memcg_settings(enum cgroup_type type)
        ret = cgroup_write_node_uint32(cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE, 1);
        if (ret != RESOURCED_ERROR_NONE)
        {
-               _E("Failed to write at %s/%s", cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE);
+               _E("[SWAP] Failed to write at %s/%s", cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE);
        }
 
        snprintf(buf, sizeof(buf), "%s/%s", MEMCG_PATH, MEMCG_FORCE_RECLAIM);
        ret = swap_check_node(buf);
        if (ret == RESOURCED_ERROR_NONE) {
                swap_node = SWAP_NODE_FORCE_RECLAIM;
-               _I("use %s node for swapping memory", MEMCG_FORCE_RECLAIM);
+               _I("[SWAP] use %s node for swapping memory", MEMCG_FORCE_RECLAIM);
        } else {
                swap_node = SWAP_NODE_HARD_LIMIT;
-               _I("use %s node for swapping memory", MEMCG_LIMIT_BYTE);
+               _I("[SWAP] use %s node for swapping memory", MEMCG_LIMIT_BYTE);
        }
 }
 
@@ -1070,6 +1092,8 @@ static int resourced_swap_init(void *data)
 {
        int ret;
 
+       _D("[SWAP] resourced swap init start");
+
        resourced_swap_change_memcg_settings(MEMCG_LOW);
        swap_set_state(SWAP_OFF);
 
@@ -1078,9 +1102,10 @@ static int resourced_swap_init(void *data)
                return ret;
 
        if (!resourced_restarted()) {
+               swap_activate_handler(NULL);
                register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, swap_booting_done);
        } else {
-               _I("Assuming swap is already set up. To reconfigure, reboot the device.");
+               _I("[SWAP] Assuming swap is already set up. To reconfigure, reboot the device.");
        }
 
        register_notifier(RESOURCED_NOTIFIER_SWAP_START, swap_start_handler);
@@ -1105,7 +1130,7 @@ static int resourced_swap_finalize(void *data)
 }
 
 static struct module_ops swap_modules_ops = {
-       .priority = MODULE_PRIORITY_NORMAL,
+       .priority = MODULE_PRIORITY_HIGH,
        .name = "swap",
        .init = resourced_swap_init,
        .exit = resourced_swap_finalize,
index a30a818..47c33a4 100644 (file)
@@ -6,6 +6,7 @@ Description=Resource management daemon
 # refers to user-sessions, because tlm, and consequently user@.service
 # starts after user-sessions are allowed.
 Before=systemd-user-sessions.service
+DefaultDependencies=no
 
 [Service]
 Type=simple