summaryrefslogtreecommitdiff
path: root/src/basic/psi-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-02-10 16:44:24 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-22 13:09:42 +0100
commit158fe190afe37b222c9dc2c53bd7be426b92ef89 (patch)
treee9f2a08d7fd364ede9213da53af8a5684c7e13a8 /src/basic/psi-util.h
parent81cfea95e51c72da6765b517e7038b3e7e3dec9f (diff)
downloadsystemd-158fe190afe37b222c9dc2c53bd7be426b92ef89.tar.gz
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.
Diffstat (limited to 'src/basic/psi-util.h')
-rw-r--r--src/basic/psi-util.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/basic/psi-util.h b/src/basic/psi-util.h
index 415fbbdd47..558a130996 100644
--- a/src/basic/psi-util.h
+++ b/src/basic/psi-util.h
@@ -28,3 +28,8 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
/* Was the kernel compiled with CONFIG_PSI=y? 1 if yes, 0 if not, negative on error. */
int is_pressure_supported(void);
+
+/* Default parameters for memory pressure watch logic in sd-event and PID 1 */
+#define MEMORY_PRESSURE_DEFAULT_TYPE "some"
+#define MEMORY_PRESSURE_DEFAULT_THRESHOLD_USEC (100 * USEC_PER_MSEC)
+#define MEMORY_PRESSURE_DEFAULT_WINDOW_USEC USEC_PER_SEC