Commit Graph
10 Commits
Author SHA1 Message Date
Niko1221 bde58068a0 Revert "expert arena RAM check: optionally leave the engine's own mappings out"
This reverts commit 667533760d.

Measured in a 57.7 GiB container (RTX 4090, IQ3_S, two starts each way):
with STRATA_ARENA_OWN_MAPPED=1 the arena check read about 27 GiB where
the memory guard read 56.8, waited 80 s, warned of a shortfall, and then
loaded the same arena as without it. Refaults and the PLE table's
resident pages were in the same range both ways and prompt time was
level. The switch was off by default, so the default path is unchanged;
the settings register is regenerated without it.
2026-11-14 05:05:02 +01:00
Niko1221 667533760d expert arena RAM check: optionally leave the engine's own mappings out
STRATA_ARENA_OWN_MAPPED=1 makes the expert arena's RAM figure leave out
this process's own resident file mappings, as the memory guard does: in
a container the PLE table the engine mapped before the arena is then no
longer counted as room for the arena. Without it (the default for now)
the table and the arena can together hold more than the container's
limit, and the table's pages are read again from the drive while the
engine answers. With it the arena verdict can switch to the RAM copy of
the hottest experts; which one is faster has not been measured yet, so
the default stays as it was.
2026-11-14 02:21:17 +01:00
Niko1221 434663b1ba expert arena RAM check: do not credit shmem or locked pages in a container
The RAM figure behind the expert arena's verdict, the file tier and the
CPU share credits a cgroup's whole memory.stat "file" counter as
reclaimable. That counter includes shmem (memfd, tmpfs, the shared K/V
pool) and mlocked file pages, neither of which the kernel can give back
in a container without swap. In a 24 GiB scope with a 3 GiB memfd held
the figure said 23.61 GiB where 20.98 GiB was true, and an allocation up
to it was OOM-killed; up to the corrected figure it ran without a kill.

Under a cgroup limit below MemTotal the credit now comes from the same
memory.stat arithmetic as the memory guard (active_file + inactive_file
less dirty and writeback: shmem sits on the anon lists and locked pages
on the unevictable list), keeping this figure's own margin of
min(half the credit, limit / 64). With no limit, a limit at or above
MemTotal, or STRATA_MEM_CREDIT_INACTIVE=1, the figure is the earlier one.
2026-11-14 02:18:05 +01:00
Niko1221 f36f8168f9 memory guard: do not credit the engine's own mapped file pages
Under a container's limit the guard now credits every clean page on the
file lists, which includes the pages the engine itself maps and reads:
the PLE table in ram or mmap mode (when the lock is refused, as in most
containers), mapped model files and the libraries. Planning that RAM for
something else pushes those pages out: in a 24 GiB scope an allocation up
to the lists figure left 22% of a mapped 11 GiB table resident; up to the
figure without the process's own mappings it stayed fully resident.

The credit under a container's limit is now the file lists less this
process's RssFile (/proc/self/status), with the file bytes the engine has
locked added back (a locked PLE table is in RssFile but on the
unevictable list, not on the file lists; generate registers it after the
table is opened and clears it when the lock is given back). When RssFile
cannot be read the inactive-only credit is used. Cold and warm starts of
the same configuration get the same figure: before the table is mapped
its cached pages are credited, after it is mapped its resident pages are
left out in both.

Limit: the Intel engine's generate does not register a locked table, so
there a container with a locked table gets a lower figure than the true
one (on the safe side). Outside a container nothing changes.
2026-11-14 02:14:47 +01:00
Niko1221 e02647b741 memory guard: credit active file cache under a container's limit
The guard credited only inactive_file as reclaimable. On a kernel with
the multi-generational LRU a page faulted in through a mapping lands on
the active list at once, so the same engine in the same container saw
26.7 GiB available after a restart with its n-gram table still cached and
57.1 GiB after a cold start. The kernel reclaims clean active file pages
at the limit as it does inactive ones (checked in a 24 GiB scope without
swap: 21.45 GiB of anonymous memory allocated over 11 GiB of active cache,
no OOM kill). The old comment said active_file holds mlocked pages; the
kernel puts mlocked pages on the unevictable list and shmem on the anon
lists, so neither is on the file lists.

Under a cgroup limit below MemTotal (a container: /proc/meminfo is the
host's) the credit is now active_file + inactive_file less dirty and
writeback. With no limit, a limit at or above MemTotal, or the operator's
--memory-limit-mib cap, the credit stays inactive_file only, unchanged.
STRATA_MEM_CREDIT_INACTIVE=1 keeps the inactive-only credit everywhere.
The memory.stat parsing is a pure function now, with unit tests.
2026-11-14 02:10:12 +01:00
Niko1221 65d97b0ab6 memory_guard_test: build on Windows (process.h getpid instead of unistd.h) 2026-10-09 15:00:53 +02:00
Niko1221 68d66b117f memory_guard_test: a .. component in the cgroup path falls back without a cap 2026-10-09 12:38:17 +02:00
Niko1221 b0531c8dad memory_guard_test: memory.current "max" without a cap falls back too 2026-10-09 12:37:43 +02:00
Niko1221 c9680eeff6 memory guard: unusable cgroup files without --memory-limit-mib fall back to MemAvailable with one warning; with the flag the sample stays unknown 2026-10-09 12:37:05 +02:00
noon-at-cgn daa765524d memory guard: parking and session save/restore read the RAM the engine really has (--memory-limit-mib)
available_host_bytes() = min(MemAvailable, the room under every cgroup limit above the engine, the operator's cap).
Parking and session save/restore read MemAvailable alone: in a container whose real limit sits on a parent cgroup it
cannot see, MemAvailable is stale (about 25 GiB shown when about 1 GiB was left) and the engine was OOM-killed.

conversation_available_memory() is replaced by available_host_bytes() / sample_host_memory() (the SYCL port's
generate.cpp too). The cgroup term covers memory.max and memory.high (v2) and memory.limit_in_bytes (v1) of the
process's group and every visible ancestor, with clean inactive file cache credited; an unparsable cgroup file makes the
sample unknown (fail closed). --memory-limit-mib / STRATA_MEMORY_LIMIT_MIB names the total RAM the container or cgroup
may use. Refusals say how much was available and from which source; one start-up line reports the limit.
tests/core/memory_guard_test.cpp runs on fixture directories (CPU only). Docs: DETAILS.md.
2026-10-09 03:28:31 +02:00