lowmem-controller: Modify controller as a module 40/290340/14
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 23 Mar 2023 08:56:13 +0000 (17:56 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Fri, 7 Apr 2023 07:59:04 +0000 (16:59 +0900)
lowmem-controller was just a library and used by lowmem.c.
lowmem-controller is now a module which is registered to module manager
of resourced and initialized as an independent module.

Change-Id: I207fa4404e076f2555cc00730e79e7c540c898dc
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/resource-limiter/memory/lowmem-controller.c
src/resource-limiter/memory/lowmem-controller.h [deleted file]
src/resource-limiter/memory/lowmem.c
src/resource-limiter/memory/lowmem.h

index 4e91048..74f982c 100644 (file)
@@ -25,7 +25,6 @@
 #include <limits.h>
 
 #include "lowmem.h"
-#include "lowmem-controller.h"
 #include "proc-common.h"
 #include "proc-main.h"
 #include "resourced.h"
@@ -33,6 +32,7 @@
 #include "trace.h"
 #include "util.h"
 #include "safe-kill.h"
+#include "module.h"
 
 #define MAX_VICTIMS_BETWEEN_CHECK  3
 
@@ -129,7 +129,7 @@ static int lowmem_check_kill_continued(struct task_info *tsk, int flags,
        return LOWMEM_RECLAIM_CONT;
 }
 
-int lowmem_controller_kill_candidates(GArray *candidates,
+static int lowmem_controller_kill_candidates(GArray *candidates,
                        unsigned should_be_freed, unsigned int threshold,
                        int max_victims, int flags,
                        int *status, unsigned int *total_victim_size,
@@ -192,3 +192,23 @@ int lowmem_controller_kill_candidates(GArray *candidates,
 
        return victim_cnt;
 }
+
+static int lowmem_controller_initialize(void *data)
+{
+       lowmem_initialize_kill_candidates(lowmem_controller_kill_candidates);
+       return RESOURCED_ERROR_NONE;
+}
+
+static int lowmem_controller_finalize(void *data)
+{
+       return RESOURCED_ERROR_NONE;
+}
+
+static struct module_ops lowmem_controller_module_ops = {
+       .priority       = MODULE_PRIORITY_INITIAL,
+       .name           = "lowmem-controller",
+       .init           = lowmem_controller_initialize,
+       .exit           = lowmem_controller_finalize,
+};
+
+MODULE_REGISTER(&lowmem_controller_module_ops)
diff --git a/src/resource-limiter/memory/lowmem-controller.h b/src/resource-limiter/memory/lowmem-controller.h
deleted file mode 100644 (file)
index d848f79..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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 excontroller or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * @file lowmem-controller.h
- * @desc Functions for controller features.
- */
-
-#ifndef __LOWMEM_CONTROLLER_H__
-#define __LOWMEM_CONTROLLER_H__
-
-int lowmem_controller_kill_candidates(GArray *candidates,
-                       unsigned should_be_freed, unsigned int threshold,
-                       int max_victims, int flags,
-                       int *status, unsigned int *total_victim_size,
-                       unsigned lmk_start_threshold_mb,
-                       void(*oom_popup)(void));
-
-#endif /* __LOWMEM_CONTROLLER_H__ */
index 61bd193..51e4059 100644 (file)
@@ -49,7 +49,6 @@
 #include "lowmem-dbus.h"
 #include "lowmem-system.h"
 #include "lowmem-limit.h"
-#include "lowmem-controller.h"
 #include "proc-common.h"
 #include "procfs.h"
 #include "freezer.h"
@@ -640,6 +639,17 @@ void lowmem_initialize_governor_ops(int(*get_kill_candidates)(GArray *,
        governor_ops.get_kill_candidates = get_kill_candidates;
 }
 
+static int(*lowmem_controller_kill_candidates)(GArray *, unsigned, unsigned int,
+                                       int, int, int *, unsigned int *,
+                                       unsigned, void(*)(void));
+void lowmem_initialize_kill_candidates(int(*kill_candidates)(GArray *, unsigned,
+                                               unsigned int, int, int, int *,
+                                               unsigned int *, unsigned,
+                                               void(*)(void)))
+{
+       lowmem_controller_kill_candidates = kill_candidates;
+}
+
 /**
  * @brief Terminate up to max_victims processes after finding them from pai.
        It depends on proc_app_info lists
@@ -693,6 +703,7 @@ static int lowmem_kill_victims(int max_victims,
                goto leave;
        }
 
+       assert(lowmem_controller_kill_candidates != NULL);
        victim_cnt = lowmem_controller_kill_candidates(lowmem_kill_candidates,
                                                should_be_freed, threshold,
                                                max_victims, flags,
index e8d012f..c454a5c 100644 (file)
@@ -96,6 +96,12 @@ enum {
 void lowmem_initialize_governor_ops(int(*)(GArray *, GArray *, GArray *,
                                        unsigned long));
 
+void lowmem_initialize_kill_candidates(int(*kill_candidates)(GArray *, unsigned,
+                                               unsigned int, int, int, int *,
+                                               unsigned int *, unsigned,
+                                               void(*)(void)));
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */