memory: remove redundant operations 55/137655/11 submit/tizen/20170803.075349
authorByungSoo Kim <bs1770.kim@samsung.com>
Tue, 28 Mar 2017 05:56:18 +0000 (14:56 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 3 Aug 2017 07:14:42 +0000 (16:14 +0900)
Resourced will search all cgroup directories about systemd slice.
It is necessary to optimize the function lowmem_reassign_limit
by removing redundant codes.

Change-Id: Ica62829f18e4ade4394d88de7008c37ffcb4279b
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
packaging/resourced.spec
src/memory/lowmem-limit.c

index 6e5aa7c..e33d485 100644 (file)
@@ -1,7 +1,7 @@
 Name:       resourced
 Summary:    Resource management daemon
 Version:    0.4
-Release:    8
+Release:    9
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 03a2142..40c381a 100644 (file)
@@ -356,12 +356,14 @@ void lowmem_reassign_limit(const char *dir, unsigned int limit)
                 * only set memory limitation to memory.memsw.limit_in_bytes
                 * because almost memcg does't have a limitation about swap usage
                 */
-               if (prev >= limit) {
+               if (prev > limit) {
                        cgroup_write_node_uint32(dir, MEMCG_LIMIT_PATH, limit);
                        cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
-               } else {
+               } else if (prev < limit) {
                        cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
                        cgroup_write_node_uint32(dir, MEMCG_LIMIT_PATH, limit);
+               } else {
+                       cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
                }
                return;
        case MEM_LIMIT_OOM:
@@ -373,14 +375,15 @@ void lowmem_reassign_limit(const char *dir, unsigned int limit)
                 * Otherwise, MEM_LIMIT_NONE and MEM_LIMIT_OOM will be same.
                 */
                cgroup_write_node_uint32(dir, MEMCG_OOM_CONTROL_PATH, 1);
-               if (prev >= limit) {
+               if (prev > limit) {
                        cgroup_write_node_uint32(dir, MEMCG_LIMIT_PATH, limit);
                        cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
-               } else {
+               } else if (prev < limit) {
                        cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
                        cgroup_write_node_uint32(dir, MEMCG_LIMIT_PATH, limit);
+               } else {
+                       cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_PATH, limit);
                }
-               snprintf(buf, sizeof(buf), "%d", SIGTRAP);
                break;
        case MEM_LIMIT_TRHESHOLD:
                snprintf(buf, sizeof(buf), "%d", limit);
@@ -394,6 +397,11 @@ void lowmem_reassign_limit(const char *dir, unsigned int limit)
                return;
        }
 
+       if (mle) {
+               mle->threshold = limit;
+               return;
+       }
+
        fd = memcg_set_eventfd(dir, registerpath, buf);
        if (fd) {
                mle = calloc(1, sizeof(struct memory_limit_event));