Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save mfleming/e31c86d3ab0a883e9053e19010150a13 to your computer and use it in GitHub Desktop.
/*
* reclaim_progress_by_type.bt — Break down reclaim progress by anon vs file
*
* Uses mm_vmscan_lru_shrink_inactive tracepoint to show what type of
* pages are being reclaimed during direct reclaim.
*
* Tracepoint fields:
* args.nid, args.nr_scanned, args.nr_reclaimed,
* args.nr_dirty, args.nr_writeback, args.nr_congested,
* args.nr_immediate, args.nr_activate0 (anon), args.nr_activate1 (file),
* args.nr_ref_keep, args.nr_unmap_fail, args.priority,
* args.reclaim_flags
*
* reclaim_flags encoding:
* bit 0 (0x1) = RECLAIM_WB_ANON
* bit 1 (0x2) = RECLAIM_WB_FILE
* bit 3 (0x8) = RECLAIM_WB_ASYNC
*
* Run: sudo bpftrace reclaim_progress_by_type.bt
* Stop: Ctrl-C (prints summary)
*/
BEGIN
{
printf("Tracing LRU shrink by anon/file type...\n");
printf("Hit Ctrl-C for summary.\n\n");
printf("%-5s %6s %10s %10s %8s %8s %4s %-10s\n",
"NID", "PRI", "SCANNED", "RECLAIMED", "DIRTY", "WBACK", "TYPE", "COMM");
}
tracepoint:vmscan:mm_vmscan_lru_shrink_inactive
{
$is_file = args.reclaim_flags & 0x2;
$type = $is_file ? "file" : "anon";
printf("%-5d %6d %10lu %10lu %8lu %8lu %4s %-16s\n",
args.nid, args.priority,
args.nr_scanned, args.nr_reclaimed,
args.nr_dirty, args.nr_writeback,
$type, comm);
/* Reclaimed pages by type */
if ($is_file) {
@reclaimed["file"] = sum(args.nr_reclaimed);
@scanned["file"] = sum(args.nr_scanned);
@events["file"] = count();
} else {
@reclaimed["anon"] = sum(args.nr_reclaimed);
@scanned["anon"] = sum(args.nr_scanned);
@events["anon"] = count();
}
/* Reclaimed per-event histograms by type */
if ($is_file) {
@reclaimed_per_event_file = hist(args.nr_reclaimed);
} else {
@reclaimed_per_event_anon = hist(args.nr_reclaimed);
}
/* Priority distribution */
@priority = lhist(args.priority, 0, 15, 1);
}
interval:s:5
{
printf("\n--- 5s snapshot ---\n");
printf("total reclaimed pages by type:\n");
print(@reclaimed);
printf("total scanned pages by type:\n");
print(@scanned);
printf("event count by type:\n");
print(@events);
}
END
{
printf("\n\n=== FINAL SUMMARY ===\n");
printf("\ntotal reclaimed pages by type:\n");
print(@reclaimed);
printf("\ntotal scanned pages by type:\n");
print(@scanned);
printf("\nevent count by type:\n");
print(@events);
printf("\nreclaimed per-event distribution (ANON):\n");
print(@reclaimed_per_event_anon);
printf("\nreclaimed per-event distribution (FILE):\n");
print(@reclaimed_per_event_file);
printf("\npriority distribution:\n");
print(@priority);
clear(@reclaimed);
clear(@scanned);
clear(@events);
clear(@reclaimed_per_event_anon);
clear(@reclaimed_per_event_file);
clear(@priority);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment