lowmem-monitor: Modify psi event handler like vmpressure 97/296697/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 3 Aug 2023 06:33:58 +0000 (15:33 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 3 Aug 2023 06:33:58 +0000 (15:33 +0900)
The handler for psi events is modified like the vmpressure's one.
 - Get available memory by calling proc_get_mem_available()
 - Get memory status(level) by calling lowmem_check_mem_state()
 - Do an action by calling lowmem_trigger_memory_state_action
 - Do nothing if the available memory is same as the previous one.

Change-Id: I770093c1ad501c63620444a6aede91f500978fd3
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/resource-limiter/memory/lowmem-monitor-psi.c

index 434840d..d1eebea 100644 (file)
@@ -78,9 +78,19 @@ static void assert_mem_level(int mem_level)
 
 static void *psi_memory_monitor_handler(struct psi_memory_monitor_info *info)
 {
+       static unsigned int prev_available_mb;
+       unsigned int available_mb;
+       int mem_level;
+
        assert_mem_level(info->mem_level);
 
-       lowmem_trigger_memory_state_action(info->mem_level);
+       available_mb = proc_get_mem_available();
+       if (prev_available_mb == available_mb)
+               return NULL;
+
+       mem_level = lowmem_check_mem_state(available_mb);
+       lowmem_trigger_memory_state_action(mem_level);
+       prev_available_mb = available_mb;
 
        return NULL;
 }