Files
magpie/native/privacy-filter
yetone 691a10446e native: pf-serve on the CPU maps the model instead of reading it into its own memory
magpie-community/plugins#853 (kongbai01203, Windows, 0.1.3295): the
first request that needs Privacy Filter started pf-serve, which held
1.82 GB of private memory until it was ended for idling.

On the CPU, privacy-filter.cpp opened the GGUF with no_alloc=false, so
ggml read all 1.6 GB of weights into a malloc'd buffer: private memory,
commit charge, written to the page file under pressure. Measured on
pf-v3's Windows pf-serve on xiaomi-gpu: 1,749 MB private after load,
1,822 MB after a 20 KB text, the reporter's number. The rest is the
graph's buffers (~200-270 MB).

patches/weights-paged.patch (applied after weights-once, by name) opens
the GGUF for metadata only on the CPU too, maps the file read-only
(mmap PROT_READ / MapViewOfFile FILE_MAP_READ) and points each tensor
at its bytes there, with bounds checked against the file's size. The
weights are the file's pages: read in as used, never part of the
commit charge, and dropped under pressure without being written
anywhere. The GPU paths (Metal, Vulkan) are unchanged. The bytes the
graph reads are the same, so the results are too.

Run, with the branch's CI build (pf/mmap, run 42448144708) against
pf-v3's release, the real q8 model and a 261 B to 78 KB text:
- Windows (xiaomi-gpu), pf-serve on the CPU: private 1,749 -> 200 MB
  after load, 1,822 -> 273 MB after the long texts; working set 1,809
  -> 1,363 MB (file pages, only what was read). pf-serve-base the
  same. Every span, offset and score hashed: identical to pf-v3 for
  pf-serve, pf-serve-base and pf-serve-vulkan. Vulkan on the Radeon
  8060S unchanged (~1.9 GB private, the driver's).
- macOS (mote, M5 Pro), PF_DEVICE=cpu: physical footprint 1.7-1.8 GB
  -> 209-303 MB; spans identical. Metal unchanged.
- Linux (WSL magpie-desktop): RssAnon 1,822 -> 276 MB.
The next commit pins pf-v4, built from this one, and adds the test that
is red on pf-v3 and green on it on all three systems.

Not tried: a machine under real memory pressure; a model file replaced
under a running pf-serve (magpie never does: it is renamed into place
once and Remove stops pf-serve first).

Reported-by: kongbai01203
2026-11-08 13:01:26 +08:00
..