]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-event: add high-level sd_event_add_memory_pressure() event source
authorLennart Poettering <lennart@poettering.net>
Fri, 10 Feb 2023 15:44:24 +0000 (16:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Feb 2023 12:09:42 +0000 (13:09 +0100)
commit158fe190afe37b222c9dc2c53bd7be426b92ef89
treee9f2a08d7fd364ede9213da53af8a5684c7e13a8
parent81cfea95e51c72da6765b517e7038b3e7e3dec9f
sd-event: add high-level sd_event_add_memory_pressure() event source

Typically, in reasonably complex programs we want to realease various
caches (such as glibc allocation caches) in case of memory pressure.
Let's add explicit infrastructure for that to sd-event, that can hook
Linux' Pressure Stall Information (PSI) logic with our event loop.

This adds sd_event_add_memory_pressure() as easy, one-step API to
install an even source that is called under memory pressure.

The parameters which file to watch (the per-cgroup PSI file, or the
system-wide file /proc/pressure/memory) can be configured via env vars.
The idea is that the service manager sooner or later gains controls for
setting this up correctly.

Alternatively to the PSI a similar logic is supported but instead of
waiting for POLLPRI on a procfs/cgroupfs fd we'll wait for POLLIN on
FIFO or AF_UNIX sockets. This is useful for testing, and possibly in
other environments, for example to hook up this protocol directly with
GNOME's low memory monitor.

By default this watches on the cgroup-local PSI so that we aren't
affected by pressure on cgroups we are not related to.
catalog/systemd.catalog.in
src/basic/psi-util.h
src/libsystemd/sd-event/event-source.h
src/libsystemd/sd-event/sd-event.c
src/systemd/sd-event.h
src/systemd/sd-messages.h