-/* lowmem actions */
-static int high_mem_act(void *data)
+/* lowmem control actions */
+static int high_mem_control(void *data)
{
int ret, status;
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;
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;
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;
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);
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;
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;
}
/*-------------------------------------------------*/
-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:
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);
};
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;
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)))
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);
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();