diff options
author | Christian Hergert <chergert@redhat.com> | 2023-08-29 23:58:10 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-09-02 03:25:58 +0200 |
commit | b63beb4d283438be2b0f5c62757ab0db7dee8d65 (patch) | |
tree | d6b9e08ffbaf20ed2d2c69a3c69b3548df7d3df2 /src/oom/oomd-manager.c | |
parent | Journal: Add message IDs for emergency-level log messages (diff) | |
download | systemd-b63beb4d283438be2b0f5c62757ab0db7dee8d65.tar.xz systemd-b63beb4d283438be2b0f5c62757ab0db7dee8d65.zip |
oomd: avoid unnecessary wake-ups for ManagedOOMSwap
If there are no "ManagedOOMSwap" entries to monitor, then the event source
can be completely disabled. This scenario appears to be common and avoiding
the wake-ups can save idle energy consumption.
This was discovered while using Sysprof for various GNOME 45 performance
tuning. systemd-oomd goes from waking up a few times a second to no
wake-ups helping keep a laptop in deep(er) sleep.
Signed-off-by: Christian Hergert <chergert@redhat.com>
Diffstat (limited to '')
-rw-r--r-- | src/oom/oomd-manager.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 514a4750d2..49896ea7f1 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -127,6 +127,12 @@ static int process_managed_oom_message(Manager *m, uid_t uid, JsonVariant *param ctx->mem_pressure_limit = limit; } + /* Toggle wake-ups for "ManagedOOMSwap" if entries are present. */ + r = sd_event_source_set_enabled(m->swap_context_event_source, + hashmap_isempty(m->monitored_swap_cgroup_contexts) ? SD_EVENT_OFF : SD_EVENT_ON); + if (r < 0) + return log_error_errno(r, "Failed to toggle enabled state of swap context source: %m"); + return 0; } @@ -348,6 +354,7 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void int r; assert(s); + assert(!hashmap_isempty(m->monitored_swap_cgroup_contexts)); /* Reset timer */ r = sd_event_now(sd_event_source_get_event(s), CLOCK_MONOTONIC, &usec_now); @@ -368,13 +375,9 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void /* We still try to acquire system information for oomctl even if no units want swap monitoring */ r = oomd_system_context_acquire("/proc/meminfo", &m->system_context); /* If there are no units depending on swap actions, the only error we exit on is ENOMEM. */ - if (r == -ENOMEM || (r < 0 && !hashmap_isempty(m->monitored_swap_cgroup_contexts))) + if (r < 0) return log_error_errno(r, "Failed to acquire system context: %m"); - /* Return early if nothing is requesting swap monitoring */ - if (hashmap_isempty(m->monitored_swap_cgroup_contexts)) - return 0; - /* Note that m->monitored_swap_cgroup_contexts does not need to be updated every interval because only the * system context is used for deciding whether the swap threshold is hit. m->monitored_swap_cgroup_contexts * is only used to decide which cgroups to kill (and even then only the resource usages of its descendent @@ -594,7 +597,7 @@ static int monitor_swap_contexts(Manager *m) { if (r < 0) return r; - r = sd_event_source_set_enabled(s, SD_EVENT_ON); + r = sd_event_source_set_enabled(s, SD_EVENT_OFF); if (r < 0) return r; |