From 297520dcd0bef9a690f6e0c2f634f6abe8639a92 Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Thu, 17 Aug 2023 13:39:04 +0900 Subject: [PATCH] config: Add AfterScreenDim configuration Add AfterScreenDim configuration of MemoryBackgroundReclaim section in optimizer.conf to reclaim memory from most recently used background apps. This is one of patch to restore BackgroundReclaim configuration of resourced 6.0. Change-Id: I30fbb0814c3622ea1d4615f8e3b424a4c105ace7 Signed-off-by: Unsung Lee --- conf/README | 20 ++++++++++++---- conf/optimizer.conf | 4 ++++ src/common/conf/config-parser.c | 17 ++++++++++++++ src/common/conf/config-parser.h | 2 ++ src/common/conf/reclaim-config.c | 45 ++++++++++++++++++++++++++++++++++++ src/common/conf/reclaim-config.h | 45 ++++++++++++++++++++++++++++++++++++ src/resource-limiter/memory/lowmem.c | 15 ++++++++++++ 7 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 src/common/conf/reclaim-config.c create mode 100644 src/common/conf/reclaim-config.h diff --git a/conf/README b/conf/README index c61c470..b93dc97 100644 --- a/conf/README +++ b/conf/README @@ -250,7 +250,17 @@ Comment: Specify external fragmentation size of the kernel zone. 800 means 80%. Example: FragLevel=800 -2.7 Section: CpuSched +2.7 Section: MemoryBackgroundReclaim +============================= +Key: AfterScreenDim +Value: (yes|1|ok|on|no|0|off) +Comment: Specify whether memory is reclaimed + from most recently used background app. + If value is (yes|1|ok|on), background reclaim on. + If value is (no|0|off), background reclaim off. +Example: AfterScreenDim=yes + +2.8 Section: CpuSched ===================== Key: CpuSchedFeature Value: ([,]+)* @@ -271,7 +281,7 @@ Comment: Specify cpu rt period in milliseconds(m), microseconds(u) or seconds. is an decimal integer value. Example: CpuRTRuntime=900ms -2.8 Section: CpuAffinity +2.9 Section: CpuAffinity ======================== Key: ForegroundApps Value: (|)(,(|))* @@ -280,7 +290,7 @@ Comment: Specify the cpu affinity of each core is: - Example: ForegroundApps=1,2,3-5 -2.9 Section: CpuBoostingLevelStrong +2.10 Section: CpuBoostingLevelStrong =================================== Key: CpuSched Value: @@ -300,7 +310,7 @@ Comment: Specify the cpu rt priority when the cpu boosting level is "strong". is an decimal integer value. Example: CpuRTPriority=50 -2.10 Section: CpuBoostingLevelMedium +2.11 Section: CpuBoostingLevelMedium ==================================== Key: CpuSched Value: @@ -320,7 +330,7 @@ Comment: Specify the cpu rt priority when the cpu boosting level is "medium". is an decimal integer value. Example: CpuRTPriority=50 -2.11 Section: CpuBoostingLevelWeak +2.12 Section: CpuBoostingLevelWeak ================================== Key: CpuSched Value: diff --git a/conf/optimizer.conf b/conf/optimizer.conf index 24ec2d7..71d4127 100644 --- a/conf/optimizer.conf +++ b/conf/optimizer.conf @@ -25,6 +25,10 @@ PagesToScanWithBoost=1000 [MemoryCompaction] FragLevel=800 +[MemoryBackgroundReclaim] +# Unset this option if it causes any unexepcted issue (e.g. jerky animation). +AfterScreenDim=yes + [CpuSched] CpuSchedFeature=no_rt_runtime_share CpuRTRuntime=950ms diff --git a/src/common/conf/config-parser.c b/src/common/conf/config-parser.c index 5027245..ced1ace 100644 --- a/src/common/conf/config-parser.c +++ b/src/common/conf/config-parser.c @@ -31,6 +31,7 @@ #include "dedup-common.h" #include "compact-common.h" #include "cpu-common.h" +#include "reclaim-config.h" #include "procfs.h" #define MAX_SECTION 64 @@ -310,6 +311,12 @@ static int optimizer_config(struct parse_result *result, void *user_data) return RESOURCED_ERROR_FAIL; } + struct reclaim_conf *reclaim_conf = config_get_reclaim_conf(); + if (reclaim_conf == NULL) { + _E("[CONFIG] reclaim configuration is NULL"); + return RESOURCED_ERROR_FAIL; + } + struct cpu_sched_conf *cpu_sched_conf = get_cpu_sched_conf(); if (cpu_sched_conf == NULL) { _E("[CONFIG] cpu_sched configuration is NULL"); @@ -429,6 +436,16 @@ static int optimizer_config(struct parse_result *result, void *user_data) result->name, result->value, result->section); } } + else if (!strncmp(result->section, BACKGROUND_RECLAIM_SECTION, + strlen(BACKGROUND_RECLAIM_SECTION) + 1)) { + if (!strncmp(result->name, AFTER_SCREEN_DIM_CONF, + strlen(AFTER_SCREEN_DIM_CONF) + 1)) + reclaim_conf->screen_dim = config_parse_bool(result->value); + else + _W("[CONFIG] Unknown configuration name (%s)" + " and value (%s) on section (%s)", + result->name, result->value, result->section); + } else if (!strncmp(result->section, CPU_SCHED_SECTION, strlen(CPU_SCHED_SECTION)+1)) { if (!strncmp(result->name, CPU_SCHED_FEATURE_NAME_CONF, diff --git a/src/common/conf/config-parser.h b/src/common/conf/config-parser.h index e774635..82cbead 100644 --- a/src/common/conf/config-parser.h +++ b/src/common/conf/config-parser.h @@ -55,6 +55,7 @@ extern "C" { #define DEDUP_SECTION "MemoryDedup" #define KSM_SECTION "MemoryKsm" #define COMPACTION_SECTION "MemoryCompaction" +#define BACKGROUND_RECLAIM_SECTION "MemoryBackgroundReclaim" #define CPU_SCHED_SECTION "CpuSched" #define CPU_AFFINITY_SECTION "CpuAffinity" #define CPU_BOOSTING_LEVEL_STRONG_SECTION "CpuBoostingLevelStrong" @@ -116,6 +117,7 @@ extern "C" { #define PAGES_TO_SCAN_WITH_BOOST_NAME_CONF "PagesToScanWithBoost" #define COMPACTION_ENABLE_NAME_CONF "CompactionEnable" #define FRAG_LEVEL_NAME_CONF "FragLevel" +#define AFTER_SCREEN_DIM_CONF "AfterScreenDim" #define FOREGROUND_APPS_NAME_CONF "ForegroundApps" #define CPU_AFFINITY_NAME_CONF "CpuAffinity" diff --git a/src/common/conf/reclaim-config.c b/src/common/conf/reclaim-config.c new file mode 100644 index 0000000..a449051 --- /dev/null +++ b/src/common/conf/reclaim-config.c @@ -0,0 +1,45 @@ +/* + * resourced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "trace.h" +#include "reclaim-config.h" + +static struct reclaim_conf *reclaim_conf = NULL; + +struct reclaim_conf *config_get_reclaim_conf(void) +{ + if (!reclaim_conf) { + reclaim_conf = (struct reclaim_conf *)calloc(1, sizeof (struct reclaim_conf)); + if (!reclaim_conf) { + _E("Failed to alloc memory for reclaim configuration"); + return NULL; + } + + reclaim_conf->screen_dim = false; + } + + return reclaim_conf; +} + +void config_free_reclaim_conf(void) +{ + if (reclaim_conf) + free(reclaim_conf); +} diff --git a/src/common/conf/reclaim-config.h b/src/common/conf/reclaim-config.h new file mode 100644 index 0000000..b66e3d6 --- /dev/null +++ b/src/common/conf/reclaim-config.h @@ -0,0 +1,45 @@ +/* + * resourced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * @file reclaim-config.h + * @desc reclaim config header + **/ + +#ifndef __RECLAIM_CONFIG_H__ +#define __RECLAIM_CONFIG_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct reclaim_conf { + bool screen_dim; +}; + +struct reclaim_conf *config_get_reclaim_conf(void); +void config_free_reclaim_conf(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __RECLAIM_CONFIG_H__ */ diff --git a/src/resource-limiter/memory/lowmem.c b/src/resource-limiter/memory/lowmem.c index 98dcbfe..0efa907 100644 --- a/src/resource-limiter/memory/lowmem.c +++ b/src/resource-limiter/memory/lowmem.c @@ -70,6 +70,7 @@ #include "fd-handler.h" #include "resourced-helper-worker.h" #include "dedup-common.h" +#include "reclaim-config.h" #define MAX_PROACTIVE_HIGH_VICTIMS 4 #define FOREGROUND_VICTIMS 1 @@ -290,6 +291,8 @@ static bool oom_popup; static bool memcg_swap_status; static int fragmentation_size; +static bool g_bg_reclaim = false; + const char *lowmem_convert_cgroup_type_to_str(int type) { static const char *type_table[] = @@ -1336,6 +1339,7 @@ static inline int calculate_threshold_size(double ratio) static void load_configs(void) { struct memcg_conf *memcg_conf = get_memcg_conf(); + struct reclaim_conf *reclaim_conf = config_get_reclaim_conf(); /* set MemoryGroupLimit section */ for (int cgroup = MEMCG_THROTTLING; cgroup < MEMCG_END; cgroup++) { @@ -1379,6 +1383,15 @@ static void load_configs(void) lowmem_action_init(memcg_conf->service.action, memcg_conf->widget.action, memcg_conf->guiapp.action, memcg_conf->background.action); + /* set MemoryBackgroundReclaim section */ + if (!reclaim_conf) + goto free_memcg_conf; + + g_bg_reclaim = reclaim_conf->screen_dim; + + config_free_reclaim_conf(); + +free_memcg_conf: free_memcg_conf(); } @@ -1404,6 +1417,8 @@ static void print_mem_configs(void) /* print info of POPUP section */ _I("[POPUP] oom popup is %s", oom_popup_enable == true ? "enabled" : "disabled"); + + _I("Background reclaim enabled = %d", g_bg_reclaim); } /* To Do: should we need lowmem_fd_start, lowmem_fd_stop ?? */ -- 2.7.4