config: Add AfterScreenDim configuration 87/303587/1
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 17 Aug 2023 04:39:04 +0000 (13:39 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 2 Jan 2024 08:43:56 +0000 (17:43 +0900)
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 <unsung.lee@samsung.com>
conf/README
conf/optimizer.conf
src/common/conf/config-parser.c
src/common/conf/config-parser.h
src/common/conf/reclaim-config.c [new file with mode: 0644]
src/common/conf/reclaim-config.h [new file with mode: 0644]
src/resource-limiter/memory/lowmem.c

index d36c8ea..98e0e14 100644 (file)
@@ -264,7 +264,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: <feature>([,]+<feature>)*
@@ -285,7 +295,7 @@ Comment: Specify cpu rt period in milliseconds(m), microseconds(u) or seconds.
          <cpu rt period> is an decimal integer value.
 Example: CpuRTRuntime=900ms
 
-2.8 Section: CpuAffinity
+2.9 Section: CpuAffinity
 ========================
 Key: ForegroundApps
 Value: (<core num>|<core range>)(,(<core num>|<core range>))*
@@ -294,7 +304,7 @@ Comment: Specify the cpu affinity of each core
          <core range> is: <core num>-<core num>
 Example: ForegroundApps=1,2,3-5
 
-2.9 Section: CpuBoostingLevelStrong
+2.10 Section: CpuBoostingLevelStrong
 ===================================
 Key: CpuSched
 Value: <schedule scheme>
@@ -314,7 +324,7 @@ Comment: Specify the cpu rt priority when the cpu boosting level is "strong".
          <priority> is an decimal integer value.
 Example: CpuRTPriority=50
 
-2.10 Section: CpuBoostingLevelMedium
+2.11 Section: CpuBoostingLevelMedium
 ====================================
 Key: CpuSched
 Value: <schedule scheme>
@@ -334,7 +344,7 @@ Comment: Specify the cpu rt priority when the cpu boosting level is "medium".
          <priority> is an decimal integer value.
 Example: CpuRTPriority=50
 
-2.11 Section: CpuBoostingLevelWeak
+2.12 Section: CpuBoostingLevelWeak
 ==================================
 Key: CpuSched
 Value: <schedule scheme>
index 9a1f125..49aa6a8 100644 (file)
@@ -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
index b476933..3747257 100644 (file)
@@ -31,6 +31,7 @@
 #include "dedup-common.h"
 #include "compact-common.h"
 #include "cpu-common.h"
+#include "reclaim-config.h"
 #include "procfs.h"
 #include "memory-common.h"
 
@@ -412,6 +413,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");
@@ -531,6 +538,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,
index caec857..cc73a67 100644 (file)
@@ -60,6 +60,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"
@@ -128,6 +129,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"
 #define CPU_BOOSTING_STALL_GOVERNOR_NAME_CONF        "CpuBoostingStallGovernor"
diff --git a/src/common/conf/reclaim-config.c b/src/common/conf/reclaim-config.c
new file mode 100644 (file)
index 0000000..a449051
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..b66e3d6
--- /dev/null
@@ -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 <stdbool.h>
+
+#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__ */
index f1b43f9..2b51a9f 100644 (file)
@@ -71,6 +71,7 @@
 #include "dedup-common.h"
 #include "const.h"
 #include "memory-common.h"
+#include "reclaim-config.h"
 
 #define MAX_PROACTIVE_HIGH_VICTIMS          4
 #define FOREGROUND_VICTIMS                  1
@@ -312,6 +313,8 @@ void lowmem_set_memcg_swap_status(bool 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[] =
@@ -1542,6 +1545,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++) {
@@ -1585,6 +1589,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();
 }
 
@@ -1610,6 +1623,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 ?? */