diff options
author | Unsung Lee <unsung.lee@samsung.com> | 2022-03-22 19:58:08 +0900 |
---|---|---|
committer | Unsung Lee <unsung.lee@samsung.com> | 2022-03-22 20:45:57 +0900 |
commit | 4114a602b74e8915bf1c6eed882df5f2be0b272a (patch) | |
tree | c3b19c728467b426b85923f55f8be9ac77c89e22 | |
parent | 315e662530aca1c7ffd9e0048c249f68a6b5109b (diff) | |
download | resourced-4114a602b74e8915bf1c6eed882df5f2be0b272a.tar.gz resourced-4114a602b74e8915bf1c6eed882df5f2be0b272a.tar.bz2 resourced-4114a602b74e8915bf1c6eed882df5f2be0b272a.zip |
Parse a new style in optimizer.conf
Change-Id: I67d514d692a02e8927cb7df810f92698d0c8f7d2
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
-rw-r--r-- | conf/optimizer.conf | 4 | ||||
-rw-r--r-- | src/common/compact-common.c | 25 | ||||
-rw-r--r-- | src/common/compact-common.h | 22 | ||||
-rw-r--r-- | src/common/config-parser.c | 221 | ||||
-rw-r--r-- | src/common/config-parser.h | 34 | ||||
-rw-r--r-- | src/common/dedup-common.c | 22 | ||||
-rw-r--r-- | src/common/dedup-common.h | 16 | ||||
-rw-r--r-- | src/common/swap-common.c | 23 | ||||
-rw-r--r-- | src/common/swap-common.h | 22 | ||||
-rw-r--r-- | src/resource-optimizer/memory/dedup/dedup.c | 5 |
10 files changed, 384 insertions, 10 deletions
diff --git a/conf/optimizer.conf b/conf/optimizer.conf index 685cb627..75e7b040 100644 --- a/conf/optimizer.conf +++ b/conf/optimizer.conf @@ -19,7 +19,7 @@ FileSize=30M PoolRatio=40 PoolType=z3fold -[DEDUP] +[Dedup] Enable=1 DedupAtBoot=yes DedupAtBootDelayMs=60000 @@ -28,7 +28,7 @@ StatIntervalMs=60000 PartialScanIntervalMs=10000 FullScanIntervalMs=600000 -[KSM] +[Ksm] Mode=oneshot #Mode=periodic diff --git a/src/common/compact-common.c b/src/common/compact-common.c new file mode 100644 index 00000000..b3f7e406 --- /dev/null +++ b/src/common/compact-common.c @@ -0,0 +1,25 @@ + +#include "compact-common.h" +#include "trace.h" + +static struct compact_conf *compact_conf = NULL; + +struct compact_conf *get_compact_conf(void) +{ + if (!compact_conf) { + compact_conf = (struct compact_conf *)calloc(1, sizeof (struct compact_conf)); + if (!compact_conf) { + _E("Failed to alloc memory for cpu configuration"); + return NULL; + } + } + + return compact_conf; +} + +void free_compact_conf(void) +{ + if (compact_conf) + free(compact_conf); +} + diff --git a/src/common/compact-common.h b/src/common/compact-common.h new file mode 100644 index 00000000..01f044ed --- /dev/null +++ b/src/common/compact-common.h @@ -0,0 +1,22 @@ +#ifndef __COMPACT_COMMON_H__ +#define __COMPACT_COMMON_H__ + +#include "resourced.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct compact_conf { + bool enable; + int frag_level; +}; + +struct compact_conf *get_compact_conf(void); +void free_compact_conf(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __COMPACT_COMMON_H__ */ diff --git a/src/common/config-parser.c b/src/common/config-parser.c index 68c50898..8992eabf 100644 --- a/src/common/config-parser.c +++ b/src/common/config-parser.c @@ -27,10 +27,228 @@ #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) @@ -395,6 +613,9 @@ void resourced_parse_vendor_configs(void) 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); } diff --git a/src/common/config-parser.h b/src/common/config-parser.h index 061af99a..794adf81 100644 --- a/src/common/config-parser.h +++ b/src/common/config-parser.h @@ -31,10 +31,12 @@ extern "C" { #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" @@ -42,7 +44,16 @@ extern "C" { #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" @@ -51,25 +62,40 @@ extern "C" { #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" diff --git a/src/common/dedup-common.c b/src/common/dedup-common.c index 30980b4c..02699216 100644 --- a/src/common/dedup-common.c +++ b/src/common/dedup-common.c @@ -18,9 +18,31 @@ #include "macro.h" #include "dedup-common.h" +#include "trace.h" + +static struct dedup_conf *dedup_conf = NULL; static enum dedup_state dedup_state; +struct dedup_conf *get_dedup_conf(void) +{ + if (!dedup_conf) { + dedup_conf = (struct dedup_conf *)calloc(1, sizeof (struct dedup_conf)); + if (!dedup_conf) { + _E("Failed to alloc memory for cpu configuration"); + return NULL; + } + } + + return dedup_conf; +} + +void free_dedup_conf(void) +{ + if (dedup_conf) + free(dedup_conf); +} + enum dedup_state dedup_get_state(void) { return dedup_state; diff --git a/src/common/dedup-common.h b/src/common/dedup-common.h index 6af20b00..3b27965d 100644 --- a/src/common/dedup-common.h +++ b/src/common/dedup-common.h @@ -67,6 +67,22 @@ enum ksm_scan_mode { KSM_SCAN_FULL, }; +struct ksm { + char mode[10]; + int pages; + int boost_pages; +}; + +struct dedup_conf { + bool enable; + bool boot_dedup_enable; + bool scan_on_lowmem; + struct ksm ksm; +}; + +struct dedup_conf *get_dedup_conf(void); +void free_dedup_conf(void); + enum dedup_state dedup_get_state(void); void dedup_set_state(enum dedup_state state); unsigned int dedup_get_ksm_stat(enum ksm_stat stat_type); diff --git a/src/common/swap-common.c b/src/common/swap-common.c index b318bca6..3bc3e448 100644 --- a/src/common/swap-common.c +++ b/src/common/swap-common.c @@ -18,9 +18,32 @@ #include "macro.h" #include "swap-common.h" +#include "trace.h" + +static struct swap_conf *swap_conf = NULL; static enum swap_state swap_state = SWAP_OFF; +struct swap_conf *get_swap_conf(void) +{ + if (!swap_conf) { + swap_conf = (struct swap_conf *)calloc(1, sizeof (struct swap_conf)); + if (!swap_conf) { + _E("Failed to alloc memory for cpu configuration"); + return NULL; + } + } + + return swap_conf; +} + + +void free_swap_conf(void) +{ + if (swap_conf) + free(swap_conf); +} + enum swap_state swap_get_state(void) { return swap_state; diff --git a/src/common/swap-common.h b/src/common/swap-common.h index 3959e70a..f89d8815 100644 --- a/src/common/swap-common.h +++ b/src/common/swap-common.h @@ -90,6 +90,28 @@ struct swap_module_ops { int (*reclaim)(void *data); }; +struct zram_conf { + char algorithm[10]; + float ratio; +}; + +struct zswap_conf { + float pool_ratio; + char pool_type[10]; +}; + +struct swap_conf { + bool enable; + bool boot_reclaim_enable; + char type[10]; + int swappiness[CGROUP_END]; + struct zram_conf zram; + struct zswap_conf zswap; +}; + +struct swap_conf *get_swap_conf(void); +void free_swap_conf(void); + enum swap_state swap_get_state(void); void swap_set_state(enum swap_state state); diff --git a/src/resource-optimizer/memory/dedup/dedup.c b/src/resource-optimizer/memory/dedup/dedup.c index 4d7aef36..7614a658 100644 --- a/src/resource-optimizer/memory/dedup/dedup.c +++ b/src/resource-optimizer/memory/dedup/dedup.c @@ -78,7 +78,7 @@ static bool dedup_at_boot_enable = false; static enum dedup_mode dedup_mode = DEDUP_MODE_NONE; static bool dedup_on_lowmem = false; -static int dedup_at_boot_delay = 120; +static int dedup_at_boot_delay = 60000; static int dedup_full_scan_interval = 600000; static int dedup_stat_interval = 60000; static int dedup_partial_scan_interval = 60000; @@ -485,9 +485,6 @@ static int config_parse_dedup_modes(const char *filename, return 0; } -#define DEDUP_SECTION "DEDUP" -#define KSM_SECTION "KSM" - static int config_parse_param(const char *filename, unsigned line, const char *section, |