#include "config-parser.h"
#include "proc-common.h"
#include "cpu-cgroup.h"
+#include "swap-common.h"
+#include "dedup-common.h"
+#include "compact-common.h"
#define MAX_SECTION 64
#define CPU_INIT_PRIO 100
+static int optimizer_config(struct parse_result *result, void *user_data)
+{
+ if (!result)
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+
+ struct swap_conf *swap_conf = get_swap_conf();
+ if (swap_conf == NULL) {
+ _E("[DEBUG] swap configuration is NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ struct dedup_conf *dedup_conf = get_dedup_conf();
+ if (dedup_conf == NULL) {
+ _E("[DEBUG] dedup configuration is NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ struct compact_conf *compact_conf = get_compact_conf();
+ if (compact_conf == NULL) {
+ _E("[DEBUG] compact configuration is NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ if (!strncmp(result->section, SWAP_SECTION, strlen(SWAP_SECTION)+1)) {
+ if (!strncmp(result->name, ENABLE_CONF, strlen(ENABLE_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3))
+ swap_conf->enable = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2))
+ swap_conf->enable = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else if (!strncmp(result->name, RECLAIM_AT_BOOT_CONF,
+ strlen(RECLAIM_AT_BOOT_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3))
+ swap_conf->boot_reclaim_enable = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2))
+ swap_conf->boot_reclaim_enable = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else if (!strncmp(result->name, TYPE_CONF,
+ strlen(TYPE_CONF)+1)) {
+ if (strlen(result->value) + 1 > sizeof(swap_conf->type)) {
+ _E("Size of swap_conf->type is not enough");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+ strncpy(swap_conf->type, result->value, sizeof(swap_conf->type) - 1);
+ }
+ else if (!strncmp(result->name, VIP_GROUP_SWAPPINESS_CONF,
+ strlen(VIP_GROUP_SWAPPINESS_CONF)+1)) {
+ swap_conf->swappiness[CGROUP_VIP] = atoi(result->value);
+ }
+ else if (!strncmp(result->name, HIGH_GROUP_SWAPPINESS_CONF,
+ strlen(HIGH_GROUP_SWAPPINESS_CONF)+1)) {
+ swap_conf->swappiness[CGROUP_HIGH] = atoi(result->value);
+ }
+ else if (!strncmp(result->name, MEDIUM_GROUP_SWAPPINESS_CONF,
+ strlen(MEDIUM_GROUP_SWAPPINESS_CONF)+1)) {
+ swap_conf->swappiness[CGROUP_MEDIUM] = atoi(result->value);
+ }
+ else if (!strncmp(result->name, LOWEST_GROUP_SWAPPINESS_CONF,
+ strlen(LOWEST_GROUP_SWAPPINESS_CONF)+1)) {
+ swap_conf->swappiness[CGROUP_LOW] = atoi(result->value);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else if (!strncmp(result->section, ZRAM_SECTION, strlen(ZRAM_SECTION)+1)) {
+ if (!strncmp(result->name, COMP_ALGORITHM_CONF, strlen(COMP_ALGORITHM_CONF)+1)) {
+ if (strlen(result->value) + 1 > sizeof(swap_conf->zram.algorithm)) {
+ _E("Size of swap_conf->zram.algorithm is not enough");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+ strncpy(swap_conf->zram.algorithm, result->value,
+ sizeof(swap_conf->zram.algorithm) - 1);
+ }
+ else if (!strncmp(result->name, RATIO_CONF, strlen(RATIO_CONF)+1)) {
+ swap_conf->zram.ratio = atof(result->value);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else if (!strncmp(result->section, ZSWAP_SECTION, strlen(ZSWAP_SECTION)+1)) {
+ if (!strncmp(result->name, POOL_RATIO_CONF, strlen(POOL_RATIO_CONF)+1)) {
+ swap_conf->zswap.pool_ratio = atof(result->value);
+ }
+ else if (!strncmp(result->name, POOL_TYPE_CONF, strlen(POOL_TYPE_CONF)+1)) {
+ if (strlen(result->value) + 1 > sizeof(swap_conf->zswap.pool_type)) {
+ _E("Size of swap_conf->zram.algorithm is not enough");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+ strncpy(swap_conf->zswap.pool_type, result->value,
+ sizeof(swap_conf->zswap.pool_type) - 1);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else if (!strncmp(result->section, DEDUP_SECTION, strlen(DEDUP_SECTION)+1)) {
+ if (!strncmp(result->name, ENABLE_CONF, strlen(ENABLE_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3))
+ dedup_conf->enable = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2))
+ dedup_conf->enable = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else if (!strncmp(result->name, DEDUP_AT_BOOT_CONF, strlen(DEDUP_AT_BOOT_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3))
+ dedup_conf->boot_dedup_enable = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2))
+ dedup_conf->boot_dedup_enable = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else if (!strncmp(result->name, SCAN_ON_LOWMEM_CONF, strlen(SCAN_ON_LOWMEM_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3) ||
+ !strncmp(result->value, "true", 5))
+ dedup_conf->scan_on_lowmem = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2) ||
+ !strncmp(result->value, "false", 6))
+ dedup_conf->scan_on_lowmem = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else if (!strncmp(result->section, KSM_SECTION, strlen(KSM_SECTION)+1)) {
+ if (!strncmp(result->name, MODE_CONF, strlen(MODE_CONF)+1)) {
+ if (strlen(result->value) + 1 > sizeof(dedup_conf->ksm.mode)) {
+ _E("Size of swap_conf->type is not enough");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+ strncpy(dedup_conf->ksm.mode, result->value,
+ sizeof(dedup_conf->ksm.mode) - 1);
+ }
+ else if (!strncmp(result->name, PAGES_TO_SCAN_CONF, strlen(PAGES_TO_SCAN_CONF)+1)) {
+ dedup_conf->ksm.pages = atoi(result->value);
+ }
+ else if (!strncmp(result->name, PAGES_TO_SCAN_WITH_BOOST_CONF,
+ strlen(PAGES_TO_SCAN_WITH_BOOST_CONF)+1)) {
+ dedup_conf->ksm.boost_pages = atoi(result->value);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else if (!strncmp(result->section, COMPACTION_SECTION, strlen(COMPACTION_SECTION)+1)) {
+ if (!strncmp(result->name, ENABLE_CONF, strlen(ENABLE_CONF)+1)) {
+ if (!strncmp(result->value, "yes", 4) ||
+ !strncmp(result->value, "1", 2) ||
+ !strncmp(result->value, "ok", 3) ||
+ !strncmp(result->value, "true", 5))
+ compact_conf->enable = true;
+ else if (!strncmp(result->value, "no", 3) ||
+ !strncmp(result->value, "0", 2) ||
+ !strncmp(result->value, "false", 6))
+ compact_conf->enable = false;
+ else {
+ _E("[DEBUG] Unknown value for %s", result->name);
+ return RESOURCED_ERROR_FAIL;
+ }
+ }
+ else if (!strncmp(result->name, FRAG_LEVEL_CONF, strlen(FRAG_LEVEL_CONF)+1)) {
+ compact_conf->frag_level = atoi(result->value);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
+ else {
+ _E("[DEBUG] Unknown section name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
+
static int limiter_config(struct parse_result *result, void *user_data)
{
if (!result)
config_type = LIMITER_CONFIG;
load_per_vendor_configs(LIMITER_CONF_DIR, vendor_config, &config_type);
+ /* Load configurations in optimizer.conf */
+ config_parse(OPTIMIZER_CONF_FILE, optimizer_config, NULL);
+
config_type = PROCESS_CONFIG;
load_per_vendor_configs(PROC_CONF_DIR, vendor_config, &config_type);
}
#define CONF_FILE_SUFFIX ".conf"
#define LIMITER_CONF_FILE RD_CONFIG_FILE(limiter)
+#define OPTIMIZER_CONF_FILE RD_CONFIG_FILE(optimizer)
#define LIMITER_CONF_DIR RD_CONFIG_PATH"/limiter.conf.d"
#define PROC_CONF_DIR RD_CONFIG_PATH"/process.conf.d"
/* section name */
+/* limiter.conf */
#define PER_PROCESS_SECTION "PerProcess"
#define MEMORY_GROUP_LIMIT_SECTION "MemoryGroupLimit"
#define MEMORY_LEVEL_THRESHOLD_SECTION "MemoryLevelThreshold"
#define MEMORY_APP_STATUS_LIMIT_SECTION "MemoryAppStatusLimit"
#define CPU_AFFINITY_SECTION "CpuAffinity"
+/* optimizer.conf */
+#define SWAP_SECTION "Swap"
+#define ZRAM_SECTION "Zram"
+#define ZSWAP_SECTION "Zswap"
+#define DEDUP_SECTION "Dedup"
+#define KSM_SECTION "Ksm"
+#define COMPACTION_SECTION "Compaction"
+
/* configuration name */
+/* limiter.conf */
#define SERVICE_NAME_CONF "Service"
#define APP_NAME_CONF "App"
#define CPU_CGROUP_NAME_CONF "CpuGroup"
#define CPU_PRIORITY_NAME_CONF "CpuPriority"
#define ACTION_ON_FAILURE_NAME_CONF "ActionOnFailure"
#define WATCHDOG_ACTION_NAME_CONF "WatchdogAction"
-
#define VIP_GROUP_LIMIT_CONF "VipGroupLimit"
#define HIGH_GROUP_LIMIT_CONF "HighGroupLimit"
#define MEDIUM_GROUP_LIMIT_CONF "MediumGroupLimit"
#define LOWEST_GROUP_LIMIT_CONF "LowestGroupLimit"
-
#define MEDIUM_LEVEL_CONF "MediumLevel"
#define LOW_LEVEL_CONF "LowLevel"
#define CRITICAL_LEVEL_CONF "CriticalLevel"
#define OOM_LEVEL_CONF "OomLevel"
#define OOM_POPUP_CONF "OomPopup"
-
#define SERVICE_PER_APP_LIMIT_ACTION "ServicePerAppLimitAction"
#define WIDGET_PER_APP_LIMIT_ACTION "WidgetPerAppLimitAction"
#define GUI_PER_APP_LIMIT_ACTION "GUIPerAppLimitAction"
#define BACKGROUND_PER_APP_LIMIT_ACTION "BackgroundPerAppLimitAction"
-
#define FOREGROUND_APPS "ForegroundApps"
+/* optimizer.cnof */
+#define ENABLE_CONF "Enable"
+#define RECLAIM_AT_BOOT_CONF "ReclaimAtBoot"
+#define TYPE_CONF "Type"
+#define VIP_GROUP_SWAPPINESS_CONF "VipGroupSwappiness"
+#define HIGH_GROUP_SWAPPINESS_CONF "HighGroupSwappiness"
+#define MEDIUM_GROUP_SWAPPINESS_CONF "MediumGroupSwappiness"
+#define LOWEST_GROUP_SWAPPINESS_CONF "LowestGroupSwappiness"
+#define COMP_ALGORITHM_CONF "CompAlgorithm"
+#define RATIO_CONF "Ratio"
+#define POOL_RATIO_CONF "PoolRatio"
+#define POOL_TYPE_CONF "PoolType"
+#define DEDUP_AT_BOOT_CONF "DedupAtBoot"
+#define SCAN_ON_LOWMEM_CONF "ScanOnLowmem"
+#define MODE_CONF "Mode"
+#define PAGES_TO_SCAN_CONF "PagesToScan"
+#define PAGES_TO_SCAN_WITH_BOOST_CONF "PagesToScanWithBoost"
+#define FRAG_LEVEL_CONF "FragLevel"
+
/* configuration value */
#define CGROUP_VIP_VALUE_CONF "vip"
#define CGROUP_HIGH_VALUE_CONF "high"