]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oomd: update system context when oomctl is invoked
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Oct 2024 03:26:52 +0000 (12:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Oct 2024 20:36:11 +0000 (05:36 +0900)
Otherwise, oomctl shows 0 memory and swap usage when swap monitoring
is not enabled.
=======
$ oomctl
Dry Run: no
Swap Used Limit: 90.00%
Default Memory Pressure Limit: 60.00%
Default Memory Pressure Duration: 20s
System Context:
        Memory: Used: 0B Total: 0B
        Swap: Used: 0B Total: 0B
Swap Monitored CGroups:
Memory Pressure Monitored CGroups:
...
======

src/oom/oomd-manager.c

index 5e25daadcbd9d346a4165b875f5ba49e221d57e0..6ff4d98c32db4497a6fd088395f04c59da102868 100644 (file)
@@ -799,10 +799,17 @@ int manager_get_dump_string(Manager *m, char **ret) {
         _cleanup_(memstream_done) MemStream ms = {};
         OomdCGroupContext *c;
         FILE *f;
+        int r;
 
         assert(m);
         assert(ret);
 
+        /* Always reread memory/swap info here. Otherwise it may be outdated if swap monitoring is off.
+         * Let's make sure to always report up-to-date data. */
+        r = oomd_system_context_acquire("/proc/meminfo", &m->system_context);
+        if (r < 0)
+                log_debug_errno(r, "Failed to acquire system context, ignoring: %m");
+
         f = memstream_init(&ms);
         if (!f)
                 return -ENOMEM;