diff options
author | Dongwoo Lee <dwoo08.lee@samsung.com> | 2020-07-29 16:53:10 +0900 |
---|---|---|
committer | Dongwoo Lee <dwoo08.lee@samsung.com> | 2020-08-05 19:52:34 +0900 |
commit | b193516a6cd857aafa32e1697c30fdd9b6a2191a (patch) | |
tree | e4e7a8436dac5668d221f4ebb1873c568f169d7d | |
parent | 379f0512e298b6d9a539c1e26ad71f271e5d3e11 (diff) | |
download | resourced-b193516a6cd857aafa32e1697c30fdd9b6a2191a.tar.gz resourced-b193516a6cd857aafa32e1697c30fdd9b6a2191a.tar.bz2 resourced-b193516a6cd857aafa32e1697c30fdd9b6a2191a.zip |
memory: lowmem-limit: Fix to read precise cgroup limit value
The unlimit for memcg limit_in_bytes is represented by 64bit value.
However, resourced reads it as 32bit value, so wrong value is retrived
and printed out as below:
"cgroup.c: cgroup_read_node_uint32(129) > [SECURE_LOG] cgroup_buf {path_to_memcg}/memory.limit_in_bytes, value -4096"
Moreover, it can possibly cause unintended result since resourced
utilizes current limitation value to determine its behavior.
To this end, this fixes to use 64bit api for memcg limitation value.
Change-Id: I09a16b44058720f72141cf081fc442819adfb807
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
-rw-r--r-- | src/memory/lowmem-handler.h | 2 | ||||
-rw-r--r-- | src/memory/lowmem-limit.c | 9 | ||||
-rw-r--r-- | src/memory/lowmem-system.c | 4 | ||||
-rw-r--r-- | tests/lowmem-system-env.cpp | 2 | ||||
-rw-r--r-- | tests/lowmem-system-env.hpp | 2 |
5 files changed, 10 insertions, 9 deletions
diff --git a/src/memory/lowmem-handler.h b/src/memory/lowmem-handler.h index 3e4217cb..136033f2 100644 --- a/src/memory/lowmem-handler.h +++ b/src/memory/lowmem-handler.h @@ -72,7 +72,7 @@ void lowmem_limit_init(void); void lowmem_limit_exit(void); void lowmem_limit_set(pid_t pid, unsigned int limit); int lowmem_limit_move_cgroup(struct proc_app_info *pai); -void lowmem_reassign_limit(const char *dir, unsigned int limit); +void lowmem_reassign_limit(const char *dir, u_int64_t limit); unsigned int lowmem_get_task_mem_usage_rss(const struct task_info *tsk); bool lowmem_fragmentated(void); unsigned int lowmem_get_proactive_thres(void); diff --git a/src/memory/lowmem-limit.c b/src/memory/lowmem-limit.c index 5b141fdd..5eab167a 100644 --- a/src/memory/lowmem-limit.c +++ b/src/memory/lowmem-limit.c @@ -32,6 +32,7 @@ #include <sys/types.h> #include <signal.h> #include <unistd.h> +#include <inttypes.h> #include "trace.h" #include "macro.h" @@ -378,14 +379,14 @@ remove_mle: return false; } -void lowmem_reassign_limit(const char *dir, unsigned int limit) +void lowmem_reassign_limit(const char *dir, u_int64_t limit) { int fd, ret; gpointer hash_entry; fd_handler_h fdh = NULL; struct memory_limit_event *mle = NULL; char buf[MAX_DEC_SIZE(int)] = {0}; - unsigned int prev; + uint64_t prev; if (memory_limit_hash) { hash_entry = g_hash_table_lookup(memory_limit_hash, dir); @@ -405,7 +406,7 @@ void lowmem_reassign_limit(const char *dir, unsigned int limit) } } - ret = cgroup_read_node_uint32(dir, MEMCG_LIMIT_PATH, &prev); + ret = cgroup_read_node_uint64(dir, MEMCG_LIMIT_PATH, &prev); if (ret) { _E("Failed to get %s from %s", MEMCG_LIMIT_PATH, dir); return; @@ -452,7 +453,7 @@ void lowmem_reassign_limit(const char *dir, unsigned int limit) } break; case MEM_LIMIT_TRHESHOLD: - snprintf(buf, sizeof(buf), "%d", limit); + snprintf(buf, sizeof(buf), "%"PRIu64, limit); /* * need to set limitation value again for preventing kernel OOM * it is larger than original limitation value diff --git a/src/memory/lowmem-system.c b/src/memory/lowmem-system.c index f40b0d73..e642a625 100644 --- a/src/memory/lowmem-system.c +++ b/src/memory/lowmem-system.c @@ -104,7 +104,7 @@ static int search_systemd_cgroup(const char *dir) FOREACH_DIRENT(de, d, return -errno) { _cleanup_free_ char *path = NULL; - unsigned int limit; + uint64_t limit; if (de->d_type != DT_DIR) continue; @@ -113,7 +113,7 @@ static int search_systemd_cgroup(const char *dir) if (ret < 0) return -ENOMEM; - ret = cgroup_read_node_uint32(path, MEMCG_LIMIT_PATH, &limit); + ret = cgroup_read_node_uint64(path, MEMCG_LIMIT_PATH, &limit); if (ret != RESOURCED_ERROR_NONE ||limit <= 0) continue; diff --git a/tests/lowmem-system-env.cpp b/tests/lowmem-system-env.cpp index 694899e9..b2ed8411 100644 --- a/tests/lowmem-system-env.cpp +++ b/tests/lowmem-system-env.cpp @@ -41,7 +41,7 @@ LowmemSystemEnv::~LowmemSystemEnv() global_test_lowmem_system_env = nullptr; } -void LowmemSystemEnv::lowmem_reassign_limit(const char *dir, unsigned int limit) +void LowmemSystemEnv::lowmem_reassign_limit(const char *dir, uint64_t limit) { check_expected(dir); check_expected(limit); diff --git a/tests/lowmem-system-env.hpp b/tests/lowmem-system-env.hpp index aedf4196..145c16b7 100644 --- a/tests/lowmem-system-env.hpp +++ b/tests/lowmem-system-env.hpp @@ -40,7 +40,7 @@ public: void g_source_set_callback(GSource *source, GSourceFunc fun, gpointer data, GDestroyNotify notify); guint g_source_attach(GSource *source, GMainContext *context); - void lowmem_reassign_limit(const char *dir, unsigned int limit); + void lowmem_reassign_limit(const char *dir, uint64_t limit); void trigger_booting_done(); void trigger_timeout(); |