From dcd968db5eb5e03e591b1cc1e342994755057db3 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Wed, 15 Jan 2025 21:31:53 +0000 Subject: [PATCH] lmkd: fallback to reading procfs stats when failing to read cgroup stats If cgroup interface is unavailable and can't be used to obtain memory stats we can fall back to reading procfs stats. Such failure would indicate a misconfigured device with ro.config.per_app_memcg set but memory cgroup not being mounted or enabled correctly. However stats reporting should not suffer because of this misconfiguration. Allow lmkd to fall back to reading stats from procfs interface when this happens. Bug: 388926998 Change-Id: Idfc777022c842b45a2640f04edb70de7ca6feac8 Signed-off-by: Suren Baghdasaryan --- statslog.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/statslog.cpp b/statslog.cpp index fbb8867..ccba857 100644 --- a/statslog.cpp +++ b/statslog.cpp @@ -158,12 +158,11 @@ struct memory_stat *stats_read_memory_stat(bool per_app_memcg, int pid, uid_t ui if (memory_stat_from_cgroup(&mem_st, pid, uid) == 0) { return &mem_st; } - } else { - if (memory_stat_from_procfs(&mem_st, pid) == 0) { - mem_st.rss_in_bytes = rss_bytes; - mem_st.swap_in_bytes = swap_bytes; - return &mem_st; - } + } + if (memory_stat_from_procfs(&mem_st, pid) == 0) { + mem_st.rss_in_bytes = rss_bytes; + mem_st.swap_in_bytes = swap_bytes; + return &mem_st; } return NULL;