{MEMCG_THROTTLING_PATH,},
};
+/* Check whether memsw exists or not */
+bool memcg_memsw_is_supported(void)
+{
+ static bool is_cached = false;
+ static bool is_supported = false;
+
+ if (is_cached)
+ return is_supported;
+
+ if (access(MEMCG_PATH "/" MEMCG_SWAP_USAGE, F_OK) == 0)
+ is_supported = true;
+
+ is_cached = true;
+
+ return is_supported;
+}
+
int cgroup_get_type(int oom_score_adj)
{
if (oom_score_adj >= OOMADJ_BACKGRD_UNLOCKED + OOMADJ_APP_INCREASE &&
if (prev_bytes > limit_bytes) {
cgroup_write_node_ulonglong(dir, MEMCG_LIMIT_BYTE, limit_bytes);
- cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
+ if (memcg_memsw_is_supported())
+ cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
}
else {
- cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
+ if (memcg_memsw_is_supported())
+ cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
cgroup_write_node_ulonglong(dir, MEMCG_LIMIT_BYTE, limit_bytes);
}
}
long long value[CGROUP_MEMORY_STAT_MAX];
};
+bool memcg_memsw_is_supported(void);
+
void register_totalram_bytes(unsigned long long ram_bytes);
int set_mem_action_conf(struct mem_action *mem_action, const char *value);
int set_memcg_conf_threshold(bool percent, char size, int lvl, const char *value);
struct dirent **namelist;
if ((count = scandir(dir, &namelist, NULL, alphasort)) == -1) {
- _W("failed to opendir (%s)", dir);
+ _I("(%s) conf dir does not exist", dir);
return;
}
ret = module->check_runtime_support((void *)module);
if (ret != RESOURCED_ERROR_NONE) {
- _E("%s module check failed", module->name);
+ _I("%s module is not supported in this environment", module->name);
remove_module(module);
continue;
}
/* Module disabled on runtime or just failed to start. */
if (ret < 0) {
module->initalized = MODULE_DROPPED;
- _E("Fail to initialize [%s] module, dropped.", module->name);
+ _I("Fail to initialize [%s] module, dropped.", module->name);
continue;
}
bmi->mfd = fanotify_init(FAN_CLOEXEC|FAN_NONBLOCK | FAN_CLASS_CONTENT,
O_RDONLY | O_LARGEFILE | O_CLOEXEC | O_NOATIME);
if (bmi->mfd < 0) {
- _E("Failed to create fanotify fd");
+ _I("Fanotify fd creation is not supported");
goto error;
}
+
if (!check_mount_dest(bmi->path)) {
ret = mount(bmi->path, bmi->path, 0, MS_BIND, 0);
if (ret) {
g_hash_table_insert(bmi->block_include_proc, g_strndup(pai->ai->pkgname, strlen(pai->ai->pkgname)),
GINT_TO_POINTER(1));
- _E("insert data %s, table num : %d", pai->ai->pkgname, g_hash_table_size(bmi->block_include_proc));
+ _I("insert data %s, table num : %d", pai->ai->pkgname, g_hash_table_size(bmi->block_include_proc));
}
return RESOURCED_ERROR_NONE;
}
/* Check if libfreezer.so is present or not */
if (stat(FREEZER_MODULE_PATH, &buf)) {
- _E("Freezer library is not present @ %s", FREEZER_MODULE_PATH);
+ _I("Freezer library is not present @ %s", FREEZER_MODULE_PATH);
return false;
}
is_present = freezer_is_present();
if (!is_present) {
- _E("Freezer library not present. Not enabling freezer");
+ _I("Freezer library not present. Not enabling freezer");
return RESOURCED_ERROR_FAIL;
}
ret_code = freezer_load_symbols();
goto remove_mle;
}
- result = cgroup_read_node_ulonglong(cg_dir, MEMCG_SWAP_USAGE, &usage_bytes);
- if (result < 0) {
+ if (memcg_memsw_is_supported())
+ result = cgroup_read_node_ulonglong(cg_dir, MEMCG_SWAP_USAGE, &usage_bytes);
+ else
result = cgroup_read_node_ulonglong(cg_dir, MEMCG_USAGE, &usage_bytes);
- if (result < 0) {
- _D("[MEMORY-LIMIT] there is no (%s) cgroup any longer, removed it", cg_dir);
- goto remove_mle;
- }
+
+ if (result < 0) {
+ _D("[MEMORY-LIMIT] there is no (%s) cgroup any longer, removed it", cg_dir);
+ goto remove_mle;
}
if (usage_bytes < mle->threshold_bytes) {
void lowmem_limit_init(void)
{
- int result;
- unsigned long long usage_bytes;
-
- result = cgroup_read_node_ulonglong(MEMCG_PATH, MEMCG_SWAP_USAGE, &usage_bytes);
- if (result == RESOURCED_ERROR_NONE)
+ if (memcg_memsw_is_supported())
registerpath = MEMCG_SWAP_USAGE;
else
registerpath = MEMCG_USAGE;
config_parse(HEART_CONF_FILE_PATH, heart_load_config, &module_num);
if (!module_num) {
- _E("all heart modules have been disabled");
+ _I("all heart modules have been disabled");
return RESOURCED_ERROR_NONE;
}
* Check whether CONFIG_LKSM is enabled in kernel.
*/
if (access("/sys/kernel/mm/ksm/run", R_OK) != 0) {
- _W("the kernel don't support KSM, please check kernel configuration");
+ _I("the kernel doesn't support KSM, please check kernel configuration");
return -ENOENT;
}
if (access("/sys/kernel/mm/ksm/one_shot_scanning", R_OK) != 0) {
- _W("the kernel support KSM but not LKSM, please check kernel configuration");
+ _I("the kernel support KSM but not LKSM, please check kernel configuration");
return -ENOENT;
}
ret = check_oom_and_set_limit(memcg, memcg_limit_bytes);
else {
/* If the group is empty don't set the limit to enable adding processes. */
- ret = cgroup_write_node_int32(memcg, MEMCG_SWAP_LIMIT_BYTE, -1);
+ if (memcg_memsw_is_supported())
+ ret = cgroup_write_node_int32(memcg, MEMCG_SWAP_LIMIT_BYTE, -1);
ret = cgroup_write_node_int32(memcg, MEMCG_LIMIT_BYTE, -1);
}
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) {
+
+ if (memcg_memsw_is_supported()) {
+ r = cgroup_read_node_ulonglong(MEMCG_PATH,
+ MEMCG_SWAP_USAGE, &prev_usage_bytes);
+ }
+ else {
r = cgroup_read_node_ulonglong(MEMCG_PATH,
MEMCG_USAGE, &prev_usage_bytes);
- if (r)
- prev_usage_bytes = ULONG_MAX;
}
+ 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) {
+ if (memcg_memsw_is_supported()) {
+ r = cgroup_read_node_ulonglong(MEMCG_PATH,
+ MEMCG_SWAP_USAGE, &usage_bytes);
+ }
+ else {
r = cgroup_read_node_ulonglong(MEMCG_PATH,
MEMCG_USAGE, &usage_bytes);
- if (r) {
- _E("[SWAP] Early reclaim is aborted");
- break;
- }
+ }
+
+ if (r) {
+ _E("[SWAP] Early reclaim is aborted");
+ break;
}
/*
return RESOURCED_ERROR_NONE;
if (mi->limit_ratio == MEMCG_NO_LIMIT) {
- ret = cgroup_write_node_int32(mi->name, MEMCG_SWAP_LIMIT_BYTE, -1);
+ if (memcg_memsw_is_supported())
+ ret = cgroup_write_node_int32(mi->name, MEMCG_SWAP_LIMIT_BYTE, -1);
ret = cgroup_write_node_int32(mi->name, MEMCG_LIMIT_BYTE, -1);
}
else
fp = fopen(path, "w");
if (fp == NULL) {
- _E("[SWAP] %s open failed", path);
return RESOURCED_ERROR_NO_DATA;
}
return RESOURCED_ERROR_NONE;