memory : read memory cgroup event fd after event is notified 73/189873/4
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 21 Sep 2018 09:05:18 +0000 (18:05 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 28 Sep 2018 06:48:01 +0000 (15:48 +0900)
- Reading cgroup.event_control blocks until the memory controller is out of memory
- Disable GIO buffering to prevent reading not fd but buffer

Change-Id: I7fbabca341131875081f1003716b11f85dd31c86
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/memory/memory-killer.c

index ad469c794d851649400f20f19065322aca61d854..339db5ed1f1ce46e74a487449ecd510645e57ce0 100644 (file)
@@ -59,6 +59,8 @@ static enum memory_killer_config_unit memory_killer_config_unit = MEMORY_KILLER_
 
 static unsigned int mem_available;     /* kB */
 
+static int memory_killer_event_fd = -1;
+
 struct memory_killer_threshold {
        const char *name;
        const int default_ratio;        /* % */
@@ -349,6 +351,10 @@ static gboolean memory_killer_notify(gpointer user_data)
        static enum memory_level last_level = MEMORY_LEVEL_NORMAL;
        enum memory_level cur_level;
        int ret;
+       unsigned long long dummy_state;
+
+       if (read(memory_killer_event_fd, &dummy_state, sizeof(dummy_state)) == -1)
+               return TRUE;
 
        cur_level = memory_killer_get_memory_level();
        if (cur_level == last_level)
@@ -533,7 +539,6 @@ static int memory_killer_read_config(void)
 API int memory_killer_init(void)
 {
        int ret;
-       int fd = -1;
        GIOChannel *channel;
        GSource *source;
 
@@ -543,15 +548,18 @@ API int memory_killer_init(void)
                return ret;
        }
 
-       fd = cgroup_open_eventfd(CGROUP_MEMORY, "memory.pressure_level", "low");
-       if (fd < 0) {
+       memory_killer_event_fd = cgroup_open_eventfd(CGROUP_MEMORY, "memory.pressure_level", "low");
+       if (memory_killer_event_fd < 0) {
                _E("Failed to open eventfd (%d)", ret);
                g_hash_table_destroy(memory_killer_whitelist);
                return ret;
        }
 
-       channel = g_io_channel_unix_new(fd);
+       channel = g_io_channel_unix_new(memory_killer_event_fd);
        g_assert(channel);
+       if (g_io_channel_set_encoding(channel, NULL, NULL) != G_IO_STATUS_NORMAL)
+               _W("Failed to set the encoding of channel");
+       g_io_channel_set_buffered(channel, FALSE);
 
        source = g_io_create_watch(channel, G_IO_IN);
        g_assert(source);