memory: reset swappiness to memcg directories which have been already created by... 87/207887/3
authorByungSoo Kim <bs1770.kim@samsung.com>
Tue, 28 Mar 2017 06:03:17 +0000 (15:03 +0900)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 27 Jun 2019 12:12:15 +0000 (14:12 +0200)
Systemd makes all cgroup directories as soon as it starts.
So, if someone tires to change default swappiness by using sysctl,
kernel can't change systemd cgroup directories with changed value
because they are already created.
So, resourced can search all systemd cgroup directories
while it reassigns memory limit.
At that time, it will check swappiness and reset again
with current swappiness of root memcgroup.

Change-Id: Id06cad1decff768daa042f61f84e63ba9d733f03
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
src/memory/lowmem-system.c

index a27cc65..33fc5bb 100644 (file)
@@ -53,6 +53,8 @@ static int search_systemd_cgroup(const char *dir)
        _cleanup_closedir_ DIR *d = NULL;
        struct dirent *de;
        int ret;
+       int rootswappiness, memcgswappiness;
+       int changeswappiness = -1;
 
        d = opendir(dir);
        if (!d) {
@@ -60,6 +62,27 @@ static int search_systemd_cgroup(const char *dir)
                return -errno;
        }
 
+       ret = cgroup_read_node_int32(LOWMEM_ROOT_CGROUP, MEMCG_SWAPNESS_PATH,
+                       &rootswappiness);
+       if (ret != RESOURCED_ERROR_NONE)
+               return -errno;
+
+       ret = cgroup_read_node_int32(dir, MEMCG_SWAPNESS_PATH,
+                       &memcgswappiness);
+       if (ret != RESOURCED_ERROR_NONE)
+               return -errno;
+
+       if ((rootswappiness >=0) && (rootswappiness != memcgswappiness)) {
+               changeswappiness = rootswappiness;
+               ret = cgroup_write_node_uint32(dir,
+                       MEMCG_SWAPNESS_PATH, changeswappiness);
+               if (ret != RESOURCED_ERROR_NONE) {
+                       _I("failed to write %s %d to %s the",
+                               MEMCG_SWAPNESS_PATH, changeswappiness, dir);
+                       return -errno;
+               }
+       }
+
        /*
         * set memory limit
         * The purpose of this operation is to make debug information
@@ -82,6 +105,14 @@ static int search_systemd_cgroup(const char *dir)
                if (ret != RESOURCED_ERROR_NONE ||limit <= 0)
                        continue;
 
+               if (changeswappiness >= 0) {
+                       ret = cgroup_write_node_uint32(path,
+                                       MEMCG_SWAPNESS_PATH, changeswappiness);
+                       if (ret != RESOURCED_ERROR_NONE)
+                               _I("failed to write %s %d to %s the",
+                                       MEMCG_SWAPNESS_PATH, changeswappiness, path);
+               }
+
                lowmem_reassign_limit(path, limit);
        }
        return RESOURCED_ERROR_NONE;