From 8b79551b1a0d3ddaf9b13411393677611180bdcd Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Mon, 10 Apr 2023 14:21:28 +0900 Subject: [PATCH] lowmem: Rename structure and functions of controller ops For unity, structure for storing governor/controller and related functions to it were renamed. Big rules: * initialize -> register * controller_ops -> mem_level_ops * action -> controller Details are below: * Registering(init) functions * lowmem_initialize_... -> lowmem_register_... * lowmem_..._governor_ops -> lowmem_..._lmk_governor * lowmem_..._kill_candidates -> lowmem_..._lmk_controller * lowmem_..._controller_ops_... -> lowmem_..._mem_level_... * lowmem_..._action -> lowmem_..._controller * Structure * struct lowmem_controller_ops -> structure lowmem_mem_level_ops * action -> controller (member of lowmem_mem_level_ops) * lowmem_actions[MEM_LEVEL_MAX] -> mem_level_ops_list[MEM_LEVEL_MAX] (declaration of 'struct lowmem_mem_level_ops') * Governor function * oom_mem_governor -> mem_state_oom_governor (for unity, since dummy governor is mem_state_dummy_governor) Change-Id: Ieb03b2ced71dd4826fbedc75cc333215b8d20193 Signed-off-by: SangYoun Kwak --- src/resource-limiter/memory/lowmem-controller.c | 30 ++++++++++++------------- src/resource-limiter/memory/lowmem-governor.c | 20 ++++++++--------- src/resource-limiter/memory/lowmem.c | 26 ++++++++++----------- src/resource-limiter/memory/lowmem.h | 8 +++---- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/resource-limiter/memory/lowmem-controller.c b/src/resource-limiter/memory/lowmem-controller.c index 676f3fa..91443f9 100644 --- a/src/resource-limiter/memory/lowmem-controller.c +++ b/src/resource-limiter/memory/lowmem-controller.c @@ -368,8 +368,8 @@ static void medium_cb(struct lowmem_control *ctl) -/* lowmem actions */ -static int high_mem_act(void *data) +/* lowmem control actions */ +static int high_mem_control(void *data) { int ret, status; @@ -395,7 +395,7 @@ static int high_mem_act(void *data) return RESOURCED_ERROR_NONE; } -static int medium_mem_act(void *data) +static int medium_mem_control(void *data) { int status = 0; int scan_mode = KSM_SCAN_PARTIAL; @@ -417,13 +417,13 @@ static int medium_mem_act(void *data) return RESOURCED_ERROR_NONE; } -static int low_mem_act(void *data) +static int low_mem_control(void *data) { swap_activate_act(); return RESOURCED_ERROR_NONE; } -static int critical_mem_act(void *data) +static int critical_mem_control(void *data) { int scan_mode = KSM_SCAN_FULL; @@ -437,7 +437,7 @@ static int critical_mem_act(void *data) return RESOURCED_ERROR_NONE; } -static int oom_mem_act(void *data) +static int oom_mem_control(void *data) { unsigned int available_mb; int status = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL; @@ -479,19 +479,19 @@ static int oom_mem_act(void *data) static int lowmem_controller_initialize(void *data) { /** - * FIXME: Consider to use one function to initialize the actions + * FIXME: Consider to use one function to register the controllers * (killer for the lowmem killer and actions for the memory levels) */ - /* Initialize the action(killer) for the lowmem_worker(lowmem killer) */ - lowmem_initialize_kill_candidates(lowmem_controller_kill_candidates); + /* Register the controller(killer) for the lowmem_worker(lowmem killer) */ + lowmem_register_lmk_controller(lowmem_controller_kill_candidates); - /* Initialize actions for the memory levels */ - lowmem_initialize_controller_ops_action(MEM_LEVEL_HIGH, high_mem_act); - lowmem_initialize_controller_ops_action(MEM_LEVEL_MEDIUM, medium_mem_act); - lowmem_initialize_controller_ops_action(MEM_LEVEL_LOW, low_mem_act); - lowmem_initialize_controller_ops_action(MEM_LEVEL_CRITICAL, critical_mem_act); - lowmem_initialize_controller_ops_action(MEM_LEVEL_OOM, oom_mem_act); + /* Register controllers for the memory levels */ + lowmem_register_mem_level_controller(MEM_LEVEL_HIGH, high_mem_control); + lowmem_register_mem_level_controller(MEM_LEVEL_MEDIUM, medium_mem_control); + lowmem_register_mem_level_controller(MEM_LEVEL_LOW, low_mem_control); + lowmem_register_mem_level_controller(MEM_LEVEL_CRITICAL, critical_mem_control); + lowmem_register_mem_level_controller(MEM_LEVEL_OOM, oom_mem_control); register_notifier(RESOURCED_NOTIFIER_MEM_CONTROL, lowmem_control_handler); diff --git a/src/resource-limiter/memory/lowmem-governor.c b/src/resource-limiter/memory/lowmem-governor.c index 7e24505..88389af 100644 --- a/src/resource-limiter/memory/lowmem-governor.c +++ b/src/resource-limiter/memory/lowmem-governor.c @@ -33,7 +33,7 @@ static int mem_state_dummy_governor(void *data) return RESOURCED_ERROR_NONE; } -static int oom_mem_governor(void *data) +static int mem_state_oom_governor(void *data) { if (lowmem_worker_is_running()) return RESOURCED_ERROR_FAIL; @@ -43,19 +43,19 @@ static int oom_mem_governor(void *data) static int lowmem_governor_initialize(void *data) { /** - * FIXME: Consider to use one function to initialize the governors + * FIXME: Consider to use one function to register the governors * (governor for the lowmem killer and governors for the memory levels) */ - /* Initialize the governor for the lowmem_worker(lowmem killer) */ - lowmem_initialize_governor_ops(plugin_resourced_memory_lmk_get_kill_candidates); + /* Register the governor for the lowmem_worker(lowmem killer) */ + lowmem_register_lmk_governor(plugin_resourced_memory_lmk_get_kill_candidates); - /* Initialize governors for the memory levels */ - lowmem_initialize_controller_ops_governor(MEM_LEVEL_HIGH, mem_state_dummy_governor); - lowmem_initialize_controller_ops_governor(MEM_LEVEL_MEDIUM, mem_state_dummy_governor); - lowmem_initialize_controller_ops_governor(MEM_LEVEL_LOW, mem_state_dummy_governor); - lowmem_initialize_controller_ops_governor(MEM_LEVEL_CRITICAL, mem_state_dummy_governor); - lowmem_initialize_controller_ops_governor(MEM_LEVEL_OOM, oom_mem_governor); + /* Register governors for the memory levels */ + lowmem_register_mem_level_governor(MEM_LEVEL_HIGH, mem_state_dummy_governor); + lowmem_register_mem_level_governor(MEM_LEVEL_MEDIUM, mem_state_dummy_governor); + lowmem_register_mem_level_governor(MEM_LEVEL_LOW, mem_state_dummy_governor); + lowmem_register_mem_level_governor(MEM_LEVEL_CRITICAL, mem_state_dummy_governor); + lowmem_register_mem_level_governor(MEM_LEVEL_OOM, mem_state_oom_governor); return RESOURCED_ERROR_NONE; } diff --git a/src/resource-limiter/memory/lowmem.c b/src/resource-limiter/memory/lowmem.c index 90ce82d..9056dba 100644 --- a/src/resource-limiter/memory/lowmem.c +++ b/src/resource-limiter/memory/lowmem.c @@ -252,12 +252,12 @@ static void lowmem_request_destroy(gpointer data) /*-------------------------------------------------*/ -struct lowmem_controller_ops { +struct lowmem_mem_level_ops { int (*governor)(void *data); - int (*action)(void *data); + int (*controller)(void *data); }; -static struct lowmem_controller_ops lowmem_actions[MEM_LEVEL_MAX] = { NULL }; -void lowmem_initialize_controller_ops_governor(int mem_state, int (*governor)(void *data)) +static struct lowmem_mem_level_ops mem_level_ops_list[MEM_LEVEL_MAX] = { NULL }; +void lowmem_register_mem_level_governor(int mem_state, int (*governor)(void *data)) { switch (mem_state) { case MEM_LEVEL_HIGH: @@ -265,20 +265,20 @@ void lowmem_initialize_controller_ops_governor(int mem_state, int (*governor)(vo case MEM_LEVEL_LOW: case MEM_LEVEL_CRITICAL: case MEM_LEVEL_OOM: - lowmem_actions[mem_state].governor = governor; + mem_level_ops_list[mem_state].governor = governor; return; default: assert(0); } } -void lowmem_initialize_controller_ops_action(int mem_state, int (*action)(void *data)) +void lowmem_register_mem_level_controller(int mem_state, int (*controller)(void *data)) { switch (mem_state) { case MEM_LEVEL_HIGH: case MEM_LEVEL_MEDIUM: case MEM_LEVEL_CRITICAL: case MEM_LEVEL_OOM: - lowmem_actions[mem_state].action = action; + mem_level_ops_list[mem_state].controller = controller; return; default: assert(0); @@ -653,7 +653,7 @@ struct lowmem_governor_ops { }; static struct lowmem_governor_ops governor_ops = { NULL }; -void lowmem_initialize_governor_ops(int(*get_kill_candidates)(GArray *, +void lowmem_register_lmk_governor(int(*get_kill_candidates)(GArray *, GArray *, GArray *, unsigned long)) { governor_ops.get_kill_candidates = get_kill_candidates; @@ -662,7 +662,7 @@ void lowmem_initialize_governor_ops(int(*get_kill_candidates)(GArray *, 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, +void lowmem_register_lmk_controller(int(*kill_candidates)(GArray *, unsigned, unsigned int, int, int, int *, unsigned int *, unsigned, void(*)(void))) @@ -996,11 +996,11 @@ void lowmem_trigger_memory_state_action(int mem_state) case MEM_LEVEL_LOW: case MEM_LEVEL_CRITICAL: case MEM_LEVEL_OOM: - assert(lowmem_actions[mem_state].governor != NULL); - assert(lowmem_actions[mem_state].action != NULL); - if (lowmem_actions[mem_state].governor(NULL) < 0) + assert(mem_level_ops_list[mem_state].governor != NULL); + assert(mem_level_ops_list[mem_state].controller != NULL); + if (mem_level_ops_list[mem_state].governor(NULL) < 0) break; - lowmem_actions[mem_state].action(NULL); + mem_level_ops_list[mem_state].controller(NULL); break; default: assert(0); diff --git a/src/resource-limiter/memory/lowmem.h b/src/resource-limiter/memory/lowmem.h index b189da4..763bc19 100644 --- a/src/resource-limiter/memory/lowmem.h +++ b/src/resource-limiter/memory/lowmem.h @@ -93,15 +93,15 @@ enum { LOWMEM_RECLAIM_NEXT_TYPE }; -void lowmem_initialize_governor_ops(int(*)(GArray *, GArray *, GArray *, +void lowmem_register_lmk_governor(int(*)(GArray *, GArray *, GArray *, unsigned long)); -void lowmem_initialize_kill_candidates(int(*kill_candidates)(GArray *, unsigned, +void lowmem_register_lmk_controller(int(*kill_candidates)(GArray *, unsigned, unsigned int, int, int, int *, unsigned int *, unsigned, void(*)(void))); -void lowmem_initialize_controller_ops_governor(int mem_state, int (*governor)(void *data)); -void lowmem_initialize_controller_ops_action(int mem_state, int (*action)(void *data)); +void lowmem_register_mem_level_governor(int mem_state, int (*governor)(void *data)); +void lowmem_register_mem_level_controller(int mem_state, int (*action)(void *data)); unsigned int lowmem_get_lowmem_state(); void lowmem_change_lowmem_state(unsigned int mem_state); bool lowmem_get_memcg_swap_status(); -- 2.7.4