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 <surenb@google.com>
This commit is contained in:
Suren Baghdasaryan 2025-01-15 21:31:53 +00:00
parent efa3f840cf
commit dcd968db5e
1 changed files with 5 additions and 6 deletions

View File

@ -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;