advanced23 min studyLesson 150 in Engineering

Memory-pressure diagnosis

Build a falsifiable investigation from memory accounting, faults, reclaim, cgroup events, and user-visible progress rather than one alarming counter.

On this page

What you’ll understand

  • Separate memory occupancy from pressure and its impact on useful work.
  • Calculate counter rates and stall fractions with consistent scopes and intervals.
  • Design a controlled intervention that distinguishes competing memory hypotheses.

A memory incident is an argument about mechanisms, not a screenshot of a full-looking RAM bar. An engineer must connect a user-visible symptom to a resource boundary and a sequence of events. This final lesson combines translation, faults, working sets, reclaim, large allocations, and pins into an investigation that can be challenged by measurements and improved with one controlled change.

Define the symptom and its resource boundary

Start with useful completions, latency, rejected requests, and failures over a specific time interval. Then identify the process group, container, NUMA node, and host involved. A container can hit a local limit while host-wide available memory looks healthy. A process can have a huge virtual mapping without occupying that much RAM. A large cache can be useful rather than waste. Label every metric with its scope and units before comparing it with another; inconsistent scopes can create an apparently impossible incident out of perfectly valid measurements.

Collect an initial accounting picture: resident and proportional process mappings where appropriate, anonymous versus file-backed memory, dirty/writeback state, relevant cgroup usage and events, swap occupancy, and system available-memory estimates. Keep these quantities distinct rather than adding overlapping categories. A snapshot identifies plausible owners, but not their growth rates or the time spent waiting. Capture a time series around a reproducible workload phase. Record recent code, batch-size, worker-count, and kernel-policy changes so that later explanations can be tested against the actual timeline.

rx=x(t2)−x(t1)t2−t1r_x=\frac{x(t_2)-x(t_1)}{t_2-t_1}
For a cumulative counter x, this gives a rate over a positive interval. If x counts pages, the rate is pages per second; multiply by the relevant page size for bytes per second. Counter resets, wraparound, scope changes, and mixed page-size counters require special handling.↔ Scroll wide equations horizontally.

Match a mechanism to multiple independent observations

Rising major-fault rates with page-loading I/O and latency spikes suggest a different mechanism from high minor faults during first-touch initialization. Heavy reclaim scans with a poor reclaim yield can indicate a shortage of eligible cold pages rather than a lack of scanning effort. Repeated refaults plus stalled tasks and reduced useful throughput support working-set churn. Large-allocation stalls with modest total occupancy can point toward fragmentation or constrained zones. None of these patterns is a universal proof; require a proposed explanation to account for the timing and the scope of several observations.

Pressure Stall Information reports time lost to resource contention rather than bytes occupied. For memory pressure, some tracks intervals when at least some tasks are stalled; full tracks simultaneous stalling of all non-idle tasks in the measured scope. Its cumulative totals can be differenced over a chosen interval, while recent averages use their own windows. Do not sum overlapping some and full percentages: full is a subset. Compare a group's pressure with its useful completions and relevant I/O pressure; memory reclaim can create storage work that appears in more than one resource view.

s=ΔU106Δt,spercent=100ss=\frac{\Delta U}{10^6\Delta t},\qquad s_{\rm percent}=100s
ΔU is the increase in a PSI cumulative total measured in microseconds, and Δt is the matching elapsed seconds. s is the fraction of that interval in the specified stall condition. This uses one consistently scoped some or full counter, not a sum of task wait times.↔ Scroll wide equations horizontally.

Change one cause and preserve the evidence

Choose a reversible intervention tied to the hypothesis. Reducing batch size tests peak live demand; reducing concurrent workers tests overlap; shortening pinned-buffer lifetime tests an unreclaimable pool; changing a huge-page policy in an isolated test can investigate compaction costs. Preserve the requested output and compare useful throughput, latency, and memory behavior together. A fix that lowers one counter by dropping work silently is not a performance improvement. Record the new configuration and a rollback point so that the result remains reproducible after the incident.

Use two reset queue-lab runs as a diagnostic exercise. Press Reset, explicitly set both arrival four and service three, predict one-job-per-second growth from four, then Play or Step. Reset again, set both arrival two and service three, predict drainage from four after four seconds, then Play or Step. Parameter edits alone retain elapsed time and recompute the initial-value model; this comparison is not a live rate switch preserving backlog. It isolates a proposed demand change, but equal jobs without byte accounting, an allocator, or telemetry cannot identify a real incident. For your workload, write expected evidence, a disconfirming observation, and a safe intervention that could prove the hypothesis wrong.

Convert pressure and fault counters into an interval story

Over a matching ten-second interval in one service scope, memory PSI some total increases by 2,000,000 microseconds. A cumulative major-fault counter increases by 500, and completed requests fall from a previous 1,000/s baseline to 600/s.

  1. Convert the stall total: 2,000,000 microseconds is two seconds. Over ten seconds, the some stall fraction is 0.2, or 20 percent; this is not 20 percent of RAM.

  2. The observed major-fault rate is 500 / 10 = 50 faults per second. The counter does not establish that every fault transferred exactly one base page or that each caused the same delay.

  3. The useful completion rate is 40 percent below the stated baseline. Correlate storage reads, refaults, cgroup events, and the workload phase, then test a bounded lower-concurrency run before claiming memory pressure caused the entire regression.

The result

The counters support a concrete investigation window. They establish neither a unique cause nor a direct conversion from stall percentage to throughput loss.

Explore the model

Interactive lab

Interactive lab · queue

Test a cause rather than clearing a symptom

Reset, explicitly set both λ=4 and μ=3, predict growth from four, then Play or Step. For a separate comparison, Reset, set both λ=2 and μ=3, predict drainage from four at t=4, then Play or Step. Parameter edits alone retain elapsed time. This fluid analogy cannot detect memory pressure; the M/M/1 mean needs separate stochastic assumptions.

Test a cause rather than clearing a symptomFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA falsifiable intervention changes the proposed source of retained work and checks useful progress as well as resource counters.

Check your understanding

Memory PSI some rises while a cgroup's useful throughput falls. Which next step most strengthens a causal diagnosis?

Try it yourself

A cumulative memory PSI full total rises by 750,000 microseconds over five seconds. What interval fraction is that? What would you check before comparing it with a different service's recent avg10 value?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Convert the numerator to seconds and keep scope and window definitions consistent.

Compare with the solution

The interval fraction is 0.75 / 5 = 0.15, or 15 percent. Before comparing, check resource, some versus full condition, cgroup or host scope, elapsed window, workload phase, and whether the other number is a recent average rather than a total-difference estimate. Those different views need not agree even when both are correct.

Take it with you

  • Occupancy, contention, and lost useful progress require separate measurements.
  • Difference counters over aligned intervals with explicit scope and units.
  • A strong diagnosis predicts disconfirming evidence and tests one controlled cause.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.