| 1 |
#! /usr/bin/env stap |
| 2 |
# |
| 3 |
# Reclaim kernel tracepoints: |
| 4 |
# |
| 5 |
# mm_vmscan_direct_reclaim_end |
| 6 |
# mm_vmscan_lru_shrink_inactive, mm_vmscan_memcg_reclaim_end, |
| 7 |
# mm_vmscan_memcg_softlimit_reclaim_end |
| 8 |
|
| 9 |
global traced_pid, command |
| 10 |
|
| 11 |
global old_set_hits |
| 12 |
global reclaims, t_reclaims |
| 13 |
global direct_reclaims, t_direct_reclaims |
| 14 |
global freed, t_freed |
| 15 |
global reactivate, t_reactivate |
| 16 |
global deactivate, t_deactivate |
| 17 |
global pgout, t_pgout |
| 18 |
|
| 19 |
global inactive_reclaims, t_inactive_reclaims |
| 20 |
global cgroup_reclaims, t_cgroup_reclaims |
| 21 |
global softlimit_reclaims, t_softlimit_reclaims |
| 22 |
|
| 23 |
function log_event:long () |
| 24 |
{ |
| 25 |
return (!traced_pid || traced_pid == pid()) |
| 26 |
} |
| 27 |
|
| 28 |
probe kernel.trace("mm_vmscan_direct_reclaim_end")? { |
| 29 |
if (!log_event()) next |
| 30 |
command[pid()] = execname() |
| 31 |
direct_reclaims[pid()] <<< $nr_reclaimed |
| 32 |
t_direct_reclaims <<< $nr_reclaimed |
| 33 |
} |
| 34 |
|
| 35 |
probe kernel.trace("mm_vmscan_lru_shrink_inactive")? { |
| 36 |
if (!log_event()) next |
| 37 |
command[pid()] = execname() |
| 38 |
inactive_reclaims[pid()] <<< $nr_reclaimed |
| 39 |
t_inactive_reclaims <<< $nr_reclaimed |
| 40 |
} |
| 41 |
|
| 42 |
probe kernel.trace("mm_vmscan_memcg_reclaim_end")? { |
| 43 |
if (!log_event()) next |
| 44 |
command[pid()] = execname() |
| 45 |
cgroup_reclaims[pid()] <<< $nr_reclaimed |
| 46 |
t_cgroup_reclaims <<< $nr_reclaimed |
| 47 |
} |
| 48 |
|
| 49 |
probe kernel.trace("mm_vmscan_memcg_softlimit_reclaim_end")? { |
| 50 |
if (!log_event()) next |
| 51 |
command[pid()] = execname() |
| 52 |
softlimit_reclaims[pid()] <<< $nr_reclaimed |
| 53 |
t_softlimit_reclaims <<< $nr_reclaimed |
| 54 |
} |
| 55 |
|
| 56 |
probe never { |
| 57 |
# Do a few initializations to let stap know what the global |
| 58 |
# variable types are. Note that since we're in a "never" |
| 59 |
# probe, these initializations will never actually happen. |
| 60 |
traced_pid = 0 |
| 61 |
command[0] = "" |
| 62 |
old_set_hits <<< 1 |
| 63 |
reclaims[0] <<< 1 |
| 64 |
t_reclaims <<< 1 |
| 65 |
direct_reclaims[0] <<< 1 |
| 66 |
t_direct_reclaims <<< 1 |
| 67 |
freed[0] <<< 1 |
| 68 |
t_freed <<< 1 |
| 69 |
reactivate[0] <<< 1 |
| 70 |
t_reactivate <<< 1 |
| 71 |
deactivate[0] <<< 1 |
| 72 |
t_deactivate <<< 1 |
| 73 |
pgout[0] <<< 1 |
| 74 |
t_pgout <<< 1 |
| 75 |
inactive_reclaims[0] <<< 1 |
| 76 |
t_inactive_reclaims <<< 1 |
| 77 |
cgroup_reclaims[0] <<< 1 |
| 78 |
t_cgroup_reclaims <<< 1 |
| 79 |
softlimit_reclaims[0] <<< 1 |
| 80 |
t_softlimit_reclaims <<< 1 |
| 81 |
} |
| 82 |
|
| 83 |
probe begin { |
| 84 |
printf("Starting data collection\n") |
| 85 |
if (target()) |
| 86 |
printf("mode Specific Pid, traced pid: %d\n\n", target()) |
| 87 |
else |
| 88 |
printf("mode - All Pids\n\n") |
| 89 |
} |
| 90 |
|
| 91 |
probe end { |
| 92 |
printf("Terminating data collection\n") |
| 93 |
if (@count(old_set_hits)) { |
| 94 |
printf("%-16s %6s %8s %8s %8s %10s %8s %8s\n", |
| 95 |
"Command", "Pid", "Direct", "Activate", "Deactive", |
| 96 |
"Reclaims", "Pgout", "Freed") |
| 97 |
printf("%-16s %6s %8s %8s %8s %10s %8s %8s\n", |
| 98 |
"-------", "-----", "------", "--------", "--------", |
| 99 |
"-----", "-----", "-----") |
| 100 |
} |
| 101 |
else { |
| 102 |
printf("%-16s %6s %8s %8s %8s %9s\n", |
| 103 |
"Command", "Pid", "Direct", "Cgroup", "Inactive", "SoftLimit") |
| 104 |
printf("%-16s %6s %8s %8s %8s %9s\n", |
| 105 |
"-------", "-----", "------", "------", "--------", "---------") |
| 106 |
} |
| 107 |
foreach (pid in reclaims-) { |
| 108 |
if (@count(old_set_hits)) |
| 109 |
printf("%-16s %6d %8d %8d %8d %10d %8d %8d\n", |
| 110 |
command[pid], pid, |
| 111 |
@count(direct_reclaims[pid]), @count(reactivate[pid]), |
| 112 |
@count(deactivate[pid]), @sum(reclaims[pid]), |
| 113 |
@count(pgout[pid]), @count(freed[pid])) |
| 114 |
else |
| 115 |
printf("%-16s %6d %8d %8d %8d %9d\n", |
| 116 |
command[pid], pid, |
| 117 |
@sum(direct_reclaims[pid]), @sum(cgroup_reclaims[pid]), |
| 118 |
@sum(inactive_reclaims[pid]), @sum(softlimit_reclaims[pid])) |
| 119 |
} |
| 120 |
printf("\n") |
| 121 |
if (@count(old_set_hits)) |
| 122 |
printf("%-23s %8d %8d %8d %10d %8d %8d\n", "Totals", |
| 123 |
@count(t_direct_reclaims), @count(t_reactivate), |
| 124 |
@count(t_deactivate), @sum(t_reclaims), |
| 125 |
@count(t_pgout), @count(t_freed)) |
| 126 |
else |
| 127 |
printf("%-23s %8d %8d %8d %9d\n", "Totals", |
| 128 |
@sum(t_direct_reclaims), @sum(t_cgroup_reclaims), |
| 129 |
@sum(t_inactive_reclaims), @sum(t_softlimit_reclaims)) |
| 130 |
} |