Repository navigation
Signal memory pressure relief and expose PSI readings - #5
Merged
Merged
Conversation
Pressure notifications only signal the onset. The monitor block now takes a Bool: true when pressure is detected, false when it's relieved. While under pressure the PSI file is polled every check_interval and relief is signalled once "some avg10" drops below release_below. Adds MemoryPressure.pressure to read the current PSI (watched .pressure file, the cgroup's memory.pressure, or /proc/pressure/memory) and MemoryPressure.parse for PSI data. The FIFO, socket and regular file watch loops are merged into one Watcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ob4Nr8aeNr1kj3PgMosUS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ob4Nr8aeNr1kj3PgMosUS
1 of 4 tasks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ob4Nr8aeNr1kj3PgMosUS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011ob4Nr8aeNr1kj3PgMosUS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
systemd's memory pressure notifications only signal the onset of pressure. An application that backs off under pressure (blocks publishing, refuses connections) has no way to know when to resume. LavinMQ needs this for cloudamqp/lavinmq#2307.
What
Relief signalling: a new
watchmethod calls its block with aBool,truewhen pressure is detected andfalsewhen it's relieved:It's a separate method instead of an argument to
monitor, because Crystal lets a block ignore its arguments, so the compiler couldn't flag existingmonitor { ... }callers that would suddenly also be called on relief.While under pressure,
watchpolls the PSI file everycheck_intervalinstead of blocking forever. It signals relief oncesome avg10drops belowrelease_below(percent), or at the first check if no PSI file can be read.PSI readings
MemoryPressure.pressurereturns the currentPressure(some/fullStalls with avg10/avg60/avg300/total). It reads the watched file when that's a.pressurefile, otherwise the process' cgroup v2memory.pressure, falling back to/proc/pressure/memory.MemoryPressure.parse(data)parses PSI file contents.Refactor: the separate FIFO, Unix-socket and regular-file loops are merged into one
Watcher, with the same per-kind behaviour (POLLPRI for regular files, read-and-discard for FIFOs and sockets, reconnect on socket EOF).Compatibility
monitor { ... }is unchanged: it's called on pressure only and never polls. The existingmonitorspecs pass without modification.Testing
New specs cover PSI parsing, reading from a file, path selection,
watchsignalling relief,watchnot signalling relief while pressure persists, andmonitoronly being called on pressure.crystal spec -Dpreview_mt -Dexecution_context: 21 examples, 0 failures.🤖 Generated with Claude Code
https://claude.ai/code/session_011ob4Nr8aeNr1kj3PgMosUS