skip to content
==> include/mesh/native_limits.h <==
1/* @ajax/mesh-native-limits: a native worker's limits (manifest cpu, mem_mb,
2 * nice, background; mesh-host native.rs Limits).  On Linux cpu and mem_mb run
3 * the process in `systemd-run --user --scope` (CPUQuota, MemoryMax and
4 * MemorySwapMax = 0), and its cgroup is read back after the spawn: a limit
5 * that is not in force refuses the start.  macOS cannot cap CPU or memory:
6 * those are refused there; nice and background work on both. */
7#ifndef MESH_NATIVE_LIMITS_H
8#define MESH_NATIVE_LIMITS_H
9
10#include "mesh/manifest.h"
11
12#include <stdbool.h>
13#include <stdint.h>
14#include <sys/types.h>
15
16typedef struct {
17    uint32_t cpu_pct; /* CPUQuota, percent of one core (200 = 2 cores); 0 none */
18    uint64_t mem;     /* MemoryMax bytes (and no swap); 0 none */
19    uint32_t nice;
20    bool background;
21} mesh_native_limits;
22
23mesh_native_limits mesh_native_limits_of(const mesh_manifest *m);
24bool mesh_native_limits_scoped(const mesh_native_limits *l);
25bool mesh_native_limits_eq(const mesh_native_limits *a, const mesh_native_limits *b);
26/* LIMIT_* bits. */
27uint32_t mesh_native_limits_bits(const mesh_native_limits *l);
28/* Whether this machine can enforce l (a refusal says why).  Linux: a
29 * transient user scope with those properties must start; probed once and cached. */
30bool mesh_native_limits_available(const mesh_native_limits *l, char **err);
31/* A process's cgroup v2 limits as l wants them (Linux; read after its exec). */
32bool mesh_native_check_cgroup(pid_t pid, const mesh_native_limits *l, char **err);
33/* Rust's {:?} of the limits: "Limits { cpu_pct: 200, mem: 1073741824, nice: 5, background: true }" (malloc'd). */
34char *mesh_native_limits_debug(const mesh_native_limits *l);
35
36#endif