test-mempress: Support unprivileged operation

This commit is contained in:
Daan De Meyer
2026-04-09 22:47:10 +02:00
committed by Daan De Meyer
parent 1121c77526
commit b3bb4fefde
11 changed files with 523 additions and 182 deletions
+21
View File
@@ -10,6 +10,7 @@
#include "fileio.h"
#include "parse-util.h"
#include "psi-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
@@ -104,6 +105,26 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
return 0;
}
const PressureResourceInfo pressure_resource_info[_PRESSURE_RESOURCE_MAX] = {
[PRESSURE_MEMORY] = {
.name = "memory",
.env_watch = "MEMORY_PRESSURE_WATCH",
.env_write = "MEMORY_PRESSURE_WRITE",
},
[PRESSURE_CPU] = {
.name = "cpu",
.env_watch = "CPU_PRESSURE_WATCH",
.env_write = "CPU_PRESSURE_WRITE",
},
};
static const char* const pressure_resource_table[_PRESSURE_RESOURCE_MAX] = {
[PRESSURE_MEMORY] = "memory",
[PRESSURE_CPU] = "cpu",
};
DEFINE_STRING_TABLE_LOOKUP(pressure_resource, PressureResource);
int is_pressure_supported(void) {
static thread_local int cached = -1;
int r;
+22 -4
View File
@@ -9,6 +9,13 @@ typedef enum PressureType {
PRESSURE_TYPE_FULL,
} PressureType;
typedef enum PressureResource {
PRESSURE_MEMORY,
PRESSURE_CPU,
_PRESSURE_RESOURCE_MAX,
_PRESSURE_RESOURCE_INVALID = -EINVAL,
} PressureResource;
/* Averages are stored in fixed-point with 11 bit fractions */
typedef struct ResourcePressure {
loadavg_t avg10;
@@ -27,7 +34,18 @@ 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 (200 * USEC_PER_MSEC)
#define MEMORY_PRESSURE_DEFAULT_WINDOW_USEC (2 * USEC_PER_SEC)
/* Metadata for each pressure resource type, for use in sd-event and PID 1 */
typedef struct PressureResourceInfo {
const char *name; /* "memory", "cpu", "io" */
const char *env_watch; /* "MEMORY_PRESSURE_WATCH", etc. */
const char *env_write; /* "MEMORY_PRESSURE_WRITE", etc. */
} PressureResourceInfo;
extern const PressureResourceInfo pressure_resource_info[_PRESSURE_RESOURCE_MAX];
DECLARE_STRING_TABLE_LOOKUP(pressure_resource, PressureResource);
/* Default parameters for pressure watch logic in sd-event and PID 1 */
#define PRESSURE_DEFAULT_TYPE "some"
#define PRESSURE_DEFAULT_THRESHOLD_USEC (200 * USEC_PER_MSEC)
#define PRESSURE_DEFAULT_WINDOW_USEC (2 * USEC_PER_SEC)