Skip to content

feat(init): report workingset_refault_file so the host can right-size this VM#13

Merged
jaredLunde merged 2 commits into
mainfrom
feat/report-workingset-refaults
Jul 13, 2026
Merged

feat(init): report workingset_refault_file so the host can right-size this VM#13
jaredLunde merged 2 commits into
mainfrom
feat/report-workingset-refaults

Conversation

@jaredLunde

Copy link
Copy Markdown
Contributor

Why

The VM's memory is elastic — it boots with only part of its RAM online and the rest is hot-plugged in as the workload needs it. The host makes that sizing decision from the pressure signals this guest reports.

Postgres reports none of them. It is page-cache-bound and reads with read(), not mmap, so when its working set outgrows RAM it does not swap, takes no major faults, and never stalls on reclaim.

Measured on a real VM (1.8 GB working set, 735 MiB RAM, scanning continuously):

signal measured
PSI some.avg10 0.00
swap_out 0
major faults/tick 0

Every memory-pressure signal reads zero while the database re-reads its data from disk continuously. So the VM never grows, and the DB thrashes indefinitely.

What

Report workingset_refault_file from /proc/vmstat alongside PSI in the existing GuestResourceStats (0xA2) frame.

A refault is a file page we evicted from the page cache and then had to read back — precisely "the working set does not fit."

Measured on the same VM under identical load:

condition refaults/sec
working set fits (150 MB table) 0 — with 1,002 confirmed full scans
working set exceeds (1.8 GB table) 29,002

A healthy database doing a thousand full scans a minute refaults zero times, so the counter cleanly separates "busy" from "starved". It also can't false-report on streaming reads: a single pass over a large table evicts pages but never re-reads them, so it produces no refaults at all.

The field is optional on the wire, so a host that doesn't consume it is unaffected.

🤖 Generated with Claude Code

jaredLunde and others added 2 commits July 13, 2026 13:54
… this VM

The VM's memory is elastic — it boots with only part of its RAM online and the
rest is hot-plugged in as the workload needs it. That sizing decision is made on
the host, from the pressure signals this guest reports.

Postgres reports none of them. It is page-cache-bound and reads with read(), not
mmap, so when its working set outgrows RAM it does not swap, takes no major
faults, and never stalls on reclaim. Measured on a real VM (1.8 GB working set,
735 MiB RAM, scanning continuously):

  PSI some.avg10      0.00
  swap_out            0
  major faults/tick   0

Every memory-pressure signal reads zero while the database re-reads its data
from disk continuously, so the VM is never grown.

Report `workingset_refault_file` from /proc/vmstat alongside PSI in the existing
GuestResourceStats (0xA2) frame. A refault is a file page we evicted from the
page cache and then had to read back — precisely "the working set does not fit".
Measured on the same VM, under identical load:

  working set FITS (150 MB table)        0 refaults/sec   (1002 full scans)
  working set EXCEEDS (1.8 GB table)    29,002 refaults/sec

A healthy database doing a thousand full scans a minute refaults zero times, so
the counter cleanly separates "busy" from "starved". It also cannot false-report
on streaming reads: a single pass over a large table evicts pages but never
re-reads them, producing no refaults at all.

The field is optional on the wire, so a host that doesn't consume it is
unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e test

The frame-stability test exists precisely to stop this payload drifting from
instd's decoder, and adding a field broke it — it never compiled in the earlier
run because `cargo test --bins` doesn't build beyond-pg-init's tests.

Extend it rather than just repair it: assert the refault key REACHES the host
(it is the only signal that sees this VM outgrow its RAM), assert it is omitted
entirely when the kernel doesn't export the counter (rather than sent as a bogus
0, which the host would read as 'no refaults'), and cover the /proc/vmstat parse.
@jaredLunde jaredLunde merged commit a254de4 into main Jul 13, 2026
1 check passed
@jaredLunde jaredLunde deleted the feat/report-workingset-refaults branch July 13, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant