gowalk-cicd 1.0.220 → 1.0.221
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,7 +22,7 @@ REQUIRED = (
|
|
|
22
22
|
'identity_diagnostics.py',
|
|
23
23
|
'health_rollout.py', 'health_rollout_engine.py', 'health_rollout_spec.py', 'health_rollout_credit.py',
|
|
24
24
|
'health_rollout_timing.py',
|
|
25
|
-
'memory_agent.py',
|
|
25
|
+
'memory_agent.py', 'memory_accounting.py',
|
|
26
26
|
'runtime_env.py', 'runtime_env_parse.py', 'edge_inputs.py', 'edge_vhost.py', 'edge_health.py',
|
|
27
27
|
'configure_vhost.py', 'vhost_diagnostics.py', 'remote_deploy.sh', 'deploy_evidence.sh',
|
|
28
28
|
'ensure_certificate.sh', 'select_certbot_account.sh',
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Conservative resident accounting from cgroup v2 type counters, independent of LRU position."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def working_set(current, stats):
|
|
5
|
+
"""Retain pinned/dirty/shared memory and half of potentially reclaimable kernel slab."""
|
|
6
|
+
names = ("anon", "file", "shmem", "kernel", "file_dirty", "file_writeback", "unevictable",
|
|
7
|
+
"slab_reclaimable")
|
|
8
|
+
values = {name: int(stats[name]) for name in names}
|
|
9
|
+
if current < 0 or any(value < 0 for value in values.values()):
|
|
10
|
+
raise ValueError("negative_memory_counter")
|
|
11
|
+
if values["slab_reclaimable"] > values["kernel"] or values["shmem"] > values["file"]:
|
|
12
|
+
raise ValueError("inconsistent_memory_counters")
|
|
13
|
+
# Dirty/writeback may overlap and unevictable may be anonymous: subtracting all is conservative.
|
|
14
|
+
clean_file = max(0, values["file"] - values["shmem"] - values["file_dirty"]
|
|
15
|
+
- values["file_writeback"] - values["unevictable"])
|
|
16
|
+
# The reads are not atomic. Never let a stale current/file pair hide resident type counters.
|
|
17
|
+
resident = max(current - clean_file, values["anon"] + values["shmem"] + values["kernel"])
|
|
18
|
+
# Reclaimable means eligible, not immediately free. Keep at least half even before the 20% margin.
|
|
19
|
+
return resident - values["slab_reclaimable"] // 2
|
|
@@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
14
|
from native_profile import running_native
|
|
15
|
+
from memory_accounting import working_set as resident_working_set
|
|
15
16
|
from runtime_host import AGENT_STATE
|
|
16
17
|
from runtime_model import MIB
|
|
17
18
|
|
|
@@ -63,11 +64,10 @@ def cgroup_dir(container):
|
|
|
63
64
|
raise FileNotFoundError(container["id"]) # the container's process has exited
|
|
64
65
|
|
|
65
66
|
|
|
66
|
-
def measure(directory
|
|
67
|
-
"""
|
|
67
|
+
def measure(directory):
|
|
68
|
+
"""Resident working set, anonymous memory and pressure from the container's own cgroup."""
|
|
68
69
|
stat = dict(line.split() for line in (directory / "memory.stat").read_text().splitlines())
|
|
69
|
-
|
|
70
|
-
working_set = int((directory / "memory.current").read_text()) - cache
|
|
70
|
+
working_set = resident_working_set(int((directory / "memory.current").read_text()), stat)
|
|
71
71
|
pressure = 0.0
|
|
72
72
|
for line in (directory / "memory.pressure").read_text().splitlines():
|
|
73
73
|
if line.startswith("some "):
|
|
@@ -142,7 +142,7 @@ def handle(container, now, zswap, dry_run):
|
|
|
142
142
|
if now - started < SETTLE_SECONDS: # startup imports have not settled yet
|
|
143
143
|
return dict(entry, settling=True)
|
|
144
144
|
directory = cgroup_dir(container)
|
|
145
|
-
working_set, anon, pressure = measure(directory
|
|
145
|
+
working_set, anon, pressure = measure(directory)
|
|
146
146
|
except (FileNotFoundError, ProcessLookupError):
|
|
147
147
|
return dict(entry, exited=True)
|
|
148
148
|
except (OSError, ValueError, KeyError):
|
package/docs/BACKEND_MEMORY.md
CHANGED
|
@@ -4,18 +4,35 @@ Admission counts reservations (64 MiB when unset), not use, within 70% of RAM. I
|
|
|
4
4
|
that default and a third of their memory is cold, so a shared host refused stacks with
|
|
5
5
|
`host_reservations_exhausted` while RAM was still free. `backend-action/memory_agent.py` runs as root every five
|
|
6
6
|
minutes on eight threads. For each running container under `/opt/gowalk-backends/` (the scope admission counts)
|
|
7
|
-
that started at least ten minutes ago, it
|
|
7
|
+
that started at least ten minutes ago, it measures a resident working set from cgroup v2 type counters, then:
|
|
8
8
|
|
|
9
9
|
- sets the reservation to the working set plus 20%, rounded up to 4 MiB, at least 16 MiB and at most the
|
|
10
10
|
container's limit (`docker update --memory-reservation`). App containers rise at once and fall by 8 MiB or more.
|
|
11
11
|
Datastores (PostgreSQL, PostGIS, TimescaleDB, Redis, Valkey, KeyDB, MySQL, MariaDB, MongoDB or Memcached by
|
|
12
|
-
image, service or command, or service `db`/`database`) only rise
|
|
12
|
+
image, service or command, or service `db`/`database`) only rise;
|
|
13
13
|
- only when host `MemAvailable` is below 30% of `MemTotal` (the headroom outside admission's 70% reservation cap),
|
|
14
14
|
while swap is present, zswap is enabled (`/sys/module/zswap/parameters/enabled` is `Y`) and `memory.pressure`
|
|
15
15
|
`some avg60` is below 0.5, writes a quarter of an app container's anonymous memory to `memory.reclaim`,
|
|
16
16
|
compressing cold pages into zswap. Datastores are never reclaimed. With ample host memory, reservation
|
|
17
17
|
measurement and updates continue without proactive page eviction; reclaim resumes when headroom falls.
|
|
18
18
|
|
|
19
|
+
`memory_accounting.py` excludes clean file cache from every container, whether currently active or inactive.
|
|
20
|
+
It retains shared memory (including PostgreSQL shared buffers), dirty/writeback pages, unevictable pages and
|
|
21
|
+
all non-reclaimable kernel allocations. It also retains half of `slab_reclaimable`: eligibility for reclaim
|
|
22
|
+
does not promise immediate availability. Dirty/writeback and unevictable counts may overlap; retaining their
|
|
23
|
+
sum deliberately overestimates this cost. The calculation is
|
|
24
|
+
`max(current - clean_file, anon + shmem + kernel) - floor(slab_reclaimable / 2)`, where
|
|
25
|
+
`clean_file = max(0, file - shmem - file_dirty - file_writeback - unevictable)`.
|
|
26
|
+
The resident type-counter floor guards against skew between non-atomic reads. Missing, negative or inconsistent
|
|
27
|
+
required counters refuse measurement and keep the existing reservation; no low fallback is substituted.
|
|
28
|
+
See the kernel's [memory.stat definitions](https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files).
|
|
29
|
+
|
|
30
|
+
This is a reservation estimate, not a guarantee that cache can immediately be evicted. The 20% margin, 4 MiB
|
|
31
|
+
rounding, 16 MiB floor, 70% host admission cap, available-memory and pressure checks remain unchanged. No cache
|
|
32
|
+
is dropped by this calculation. Existing datastore reservations retain their high-water mark; installing the
|
|
33
|
+
new estimator alone never lowers them. A host migration must separately validate any initial measured
|
|
34
|
+
reservation and preserve the original declaration credits against verified container identities.
|
|
35
|
+
|
|
19
36
|
Before its first change to a container, the agent records the reservation admission counted (bytes; 64 MiB when
|
|
20
37
|
unset) in `/var/lib/gowalk-backend-memory/<full container id>` (root-owned, 0644, atomic, fsynced, never
|
|
21
38
|
overwritten) and never resizes without it; each real run removes only the 64-hex-named records of containers that
|