Skip to content

Instantly share code, notes, and snippets.

@mfleming
Created March 4, 2026 15:17
Show Gist options
  • Select an option

  • Save mfleming/167b00bef7e1f4e686a6d32833c42079 to your computer and use it in GitHub Desktop.

Select an option

Save mfleming/167b00bef7e1f4e686a6d32833c42079 to your computer and use it in GitHub Desktop.
reclaim_retry_trace.bt
/*
* reclaim_retry_trace.bt — Capture should_reclaim_retry() behaviour
*
* Uses the built-in reclaim_retry_zone tracepoint to log every
* retry decision in direct reclaim.
*
* Tracepoint fields:
* args.node, args.zone_idx, args.order,
* args.reclaimable, args.available, args.min_wmark,
* args.no_progress_loops, args.wmark_check
*
* no_progress_loops == 0 means did_some_progress was true (reclaim
* freed at least one page, resetting the counter). With zram this
* includes anon pages swapped out synchronously — even though no
* net free memory was produced.
*
* Run: sudo bpftrace reclaim_retry_trace.bt
* Stop: Ctrl-C (prints summary histograms)
*/
BEGIN
{
printf("Tracing should_reclaim_retry via reclaim_retry_zone...\n");
printf("Hit Ctrl-C for summary.\n\n");
printf("%-16s %6s %5s %5s %14s %14s %14s %5s %5s\n",
"COMM", "PID", "NODE", "ORDER",
"RECLAIMABLE", "AVAILABLE", "MIN_WMARK", "LOOPS", "WMARK");
}
tracepoint:oom:reclaim_retry_zone
{
printf("%-16s %6d %5d %5d %14lu %14lu %14lu %5d %5d\n",
comm, pid,
args.node, args.order,
args.reclaimable, args.available, args.min_wmark,
args.no_progress_loops, args.wmark_check);
@loops_hist = lhist(args.no_progress_loops, 0, 20, 1);
if (args.wmark_check) {
@wmark["pass"] = count();
} else {
@wmark["fail"] = count();
}
@reclaimable = hist(args.reclaimable);
@total = count();
}
interval:s:5
{
printf("\n--- 5s snapshot ---\n");
printf("no_progress_loops distribution:\n");
print(@loops_hist);
printf("wmark outcomes:\n");
print(@wmark);
}
END
{
printf("\n\n=== FINAL SUMMARY ===\n");
printf("\nno_progress_loops distribution:\n");
print(@loops_hist);
printf("\nreclaimable pages distribution:\n");
print(@reclaimable);
printf("\nwmark_check outcomes:\n");
print(@wmark);
printf("\ntotal events: ");
print(@total);
clear(@loops_hist);
clear(@reclaimable);
clear(@wmark);
clear(@total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment